Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions compiler/rustc_mir_build/src/builder/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.into_block();
} else {
let scope = (*init_scope, source_info);
let _: BlockAnd<()> = this.in_scope(scope, lint_level, |this| {
this.declare_bindings(
visibility_scope,
remainder_span,
pattern,
None,
None,
);
block.unit()
});
block = this
.in_scope(scope, lint_level, |this| {
this.declare_bindings(
visibility_scope,
remainder_span,
pattern,
None,
None,
);
block.unit()
})
.into_block();

debug!("ast_block_stmts: pattern={:?}", pattern);
this.visit_primary_bindings(pattern, &mut |this, node, span| {
Expand Down
15 changes: 13 additions & 2 deletions compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::cast::{CastTy, mir_cast_kind};
use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, Ty, UpvarArgs};
use rustc_span::{DUMMY_SP, Span, Spanned};
use rustc_span::Span;
use tracing::debug;

use crate::builder::expr::as_place::PlaceBase;
Expand Down Expand Up @@ -74,6 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
NeedsTemporary::No
)
);
this.record_operand_moved(&value_operand);
block.and(Rvalue::Repeat(value_operand, count))
}
}
Expand Down Expand Up @@ -219,6 +220,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
})
.collect();

for operand in fields.iter() {
this.record_operand_moved(operand);
}
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(el_ty)), fields))
}
ExprKind::Tuple { ref fields } => {
Expand All @@ -240,6 +244,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
})
.collect();

for operand in fields.iter() {
this.record_operand_moved(operand);
}
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields))
}
ExprKind::Closure(ClosureExpr {
Expand Down Expand Up @@ -342,6 +349,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Box::new(AggregateKind::CoroutineClosure(closure_id.to_def_id(), args))
}
};
for operand in operands.iter() {
this.record_operand_moved(operand);
}
block.and(Rvalue::Aggregate(result, operands))
}
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
Expand Down Expand Up @@ -424,6 +434,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
NeedsTemporary::No,
)
);
this.record_operand_moved(&operand);
block.and(Rvalue::Use(operand, WithRetag::Yes))
}

Expand Down Expand Up @@ -647,7 +658,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.diverge_from(block);
block = success;
}
this.record_operands_moved(&[Spanned { node: value_operand, span: DUMMY_SP }]);
this.record_operand_moved(&value_operand);
}
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), IndexVec::new()))
}
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_mir_build/src/builder/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_index::IndexVec;
use rustc_middle::mir::*;
use rustc_middle::span_bug;
use rustc_middle::thir::*;
Expand Down Expand Up @@ -491,7 +492,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

let success = this.cfg.start_new_block();

this.record_operands_moved(&args);
for operand in args.iter() {
this.record_operand_moved(&operand.node);
}

debug!("expr_into_dest: fn_span={:?}", fn_span);

Expand Down Expand Up @@ -636,7 +639,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let variant = adt_def.variant(variant_index);
let field_names = variant.fields.indices();

let fields = match base {
let fields: IndexVec<_, _> = match base {
AdtExprBase::None => {
field_names.filter_map(|n| fields_map.get(&n).cloned()).collect()
}
Expand Down Expand Up @@ -701,6 +704,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
user_ty,
active_field_index,
));
for operand in fields.iter() {
this.record_operand_moved(operand);
}
this.cfg.push_assign(
block,
source_info,
Expand Down Expand Up @@ -849,7 +855,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));

let place = unpack!(block = this.as_place(block, expr_id));
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place), WithRetag::Yes);
let operand = this.consume_by_copy_or_move(place);
this.record_operand_moved(&operand);
let rvalue = Rvalue::Use(operand, WithRetag::Yes);
this.cfg.push_assign(block, source_info, destination, rvalue);
block.unit()
}
Expand All @@ -875,6 +883,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block =
this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
);
this.record_operand_moved(&value);
let resume = this.cfg.start_new_block();
this.cfg.terminate(
block,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir_build/src/builder/expr/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
})
.collect();

this.record_operands_moved(&args);
for operand in args.iter() {
this.record_operand_moved(&operand.node);
}

debug!("expr_into_dest: fn_span={:?}", fn_span);

Expand Down
23 changes: 11 additions & 12 deletions compiler/rustc_mir_build/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,22 +532,21 @@ fn construct_fn<'tcx>(
region::Scope { local_id: body.id().hir_id.local_id, data: region::ScopeData::Arguments };
let source_info = builder.source_info(span);
let call_site_s = (call_site_scope, source_info);
let _: BlockAnd<()> = builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {
let arg_scope_s = (arg_scope, source_info);
// Attribute epilogue to function's closing brace
let fn_end = span_with_body.shrink_to_hi();
let return_block = builder
.in_breakable_scope(None, Place::return_place(), fn_end, |builder| {
// Attribute epilogue to function's closing brace
let fn_end = span_with_body.shrink_to_hi();
let return_block = builder
.in_scope(call_site_s, LintLevel::Inherited, |builder| {
let arg_scope_s = (arg_scope, source_info);
builder.in_breakable_scope(None, Place::return_place(), fn_end, |builder| {
Some(builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
builder.args_and_body(START_BLOCK, arguments, arg_scope, expr)
}))
})
.into_block();
let source_info = builder.source_info(fn_end);
builder.cfg.terminate(return_block, source_info, TerminatorKind::Return);
builder.build_drop_trees();
return_block.unit()
});
})
.into_block();
let source_info = builder.source_info(fn_end);
builder.cfg.terminate(return_block, source_info, TerminatorKind::Return);
builder.build_drop_trees();

let mut body = builder.finish();

Expand Down
Loading
Loading