1
Fork 0

Remove useless references/dereferences

This commit is contained in:
LeSeulArtichaut 2021-03-06 22:24:04 +01:00
parent c2c4322891
commit cd049ef9ea
12 changed files with 148 additions and 168 deletions

View file

@ -23,29 +23,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
expr, expr,
targeted_by_break, targeted_by_break,
safety_mode, safety_mode,
} = ast_block; } = *ast_block;
self.in_opt_scope(opt_destruction_scope.map(|de| (de, source_info)), move |this| { self.in_opt_scope(opt_destruction_scope.map(|de| (de, source_info)), move |this| {
this.in_scope((*region_scope, source_info), LintLevel::Inherited, move |this| { this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
if *targeted_by_break { if targeted_by_break {
this.in_breakable_scope(None, destination, *span, |this| { this.in_breakable_scope(None, destination, span, |this| {
Some(this.ast_block_stmts( Some(this.ast_block_stmts(
destination, destination,
block, block,
*span, span,
&stmts, stmts,
expr.as_deref(), expr,
*safety_mode, safety_mode,
)) ))
}) })
} else { } else {
this.ast_block_stmts( this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
destination,
block,
*span,
&stmts,
expr.as_deref(),
*safety_mode,
)
} }
}) })
}) })
@ -87,15 +80,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let source_info = this.source_info(span); let source_info = this.source_info(span);
for Stmt { kind, opt_destruction_scope } in stmts { for Stmt { kind, opt_destruction_scope } in stmts {
match kind { match kind {
StmtKind::Expr { scope, expr } => { &StmtKind::Expr { scope, expr } => {
this.block_context.push(BlockFrame::Statement { ignores_expr_result: true }); this.block_context.push(BlockFrame::Statement { ignores_expr_result: true });
unpack!( unpack!(
block = this.in_opt_scope( block = this.in_opt_scope(
opt_destruction_scope.map(|de| (de, source_info)), opt_destruction_scope.map(|de| (de, source_info)),
|this| { |this| {
let si = (*scope, source_info); let si = (scope, source_info);
this.in_scope(si, LintLevel::Inherited, |this| { this.in_scope(si, LintLevel::Inherited, |this| {
this.stmt_expr(block, &expr, Some(*scope)) this.stmt_expr(block, expr, Some(scope))
}) })
} }
) )
@ -110,7 +103,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let_scope_stack.push(remainder_scope); let_scope_stack.push(remainder_scope);
// Declare the bindings, which may create a source scope. // Declare the bindings, which may create a source scope.
let remainder_span = remainder_scope.span(this.tcx, &this.region_scope_tree); let remainder_span = remainder_scope.span(this.tcx, this.region_scope_tree);
let visibility_scope = let visibility_scope =
Some(this.new_source_scope(remainder_span, LintLevel::Inherited, None)); Some(this.new_source_scope(remainder_span, LintLevel::Inherited, None));
@ -128,11 +121,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.declare_bindings( this.declare_bindings(
visibility_scope, visibility_scope,
remainder_span, remainder_span,
&pattern, pattern,
ArmHasGuard(false), ArmHasGuard(false),
Some((None, initializer_span)), Some((None, initializer_span)),
); );
this.expr_into_pattern(block, pattern.clone(), &init) this.expr_into_pattern(block, pattern.clone(), init)
}) })
} }
) )
@ -143,7 +136,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.declare_bindings( this.declare_bindings(
visibility_scope, visibility_scope,
remainder_span, remainder_span,
&pattern, pattern,
ArmHasGuard(false), ArmHasGuard(false),
None, None,
); );

View file

@ -10,25 +10,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// `expr` is a valid compile-time constant! /// `expr` is a valid compile-time constant!
crate fn as_constant(&mut self, expr: &Expr<'_, 'tcx>) -> Constant<'tcx> { crate fn as_constant(&mut self, expr: &Expr<'_, 'tcx>) -> Constant<'tcx> {
let this = self; let this = self;
let Expr { ty, temp_lifetime: _, span, kind } = expr; let Expr { ty, temp_lifetime: _, span, ref kind } = *expr;
match kind { match kind {
ExprKind::Scope { region_scope: _, lint_level: _, value } => this.as_constant(&value), ExprKind::Scope { region_scope: _, lint_level: _, value } => this.as_constant(value),
ExprKind::Literal { literal, user_ty, const_id: _ } => { ExprKind::Literal { literal, user_ty, const_id: _ } => {
let user_ty = user_ty.map(|user_ty| { let user_ty = user_ty.map(|user_ty| {
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span: *span, span,
user_ty, user_ty,
inferred_ty: ty, inferred_ty: ty,
}) })
}); });
assert_eq!(literal.ty, *ty); assert_eq!(literal.ty, ty);
Constant { span: *span, user_ty, literal } Constant { span, user_ty, literal }
} }
ExprKind::StaticRef { literal, .. } => Constant { span: *span, user_ty: None, literal }, ExprKind::StaticRef { literal, .. } => Constant { span, user_ty: None, literal },
ExprKind::ConstBlock { value } => { ExprKind::ConstBlock { value } => {
Constant { span: *span, user_ty: None, literal: value } Constant { span: span, user_ty: None, literal: value }
} }
_ => span_bug!(*span, "expression is not a valid constant {:?}", kind), _ => span_bug!(span, "expression is not a valid constant {:?}", kind),
} }
} }
} }

View file

@ -98,11 +98,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
debug!("as_operand(block={:?}, expr={:?})", block, expr); debug!("as_operand(block={:?}, expr={:?})", block, expr);
let this = self; let this = self;
if let ExprKind::Scope { region_scope, lint_level, value } = &expr.kind { if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind {
let source_info = this.source_info(expr.span); let source_info = this.source_info(expr.span);
let region_scope = (*region_scope, source_info); let region_scope = (region_scope, source_info);
return this return this
.in_scope(region_scope, *lint_level, |this| this.as_operand(block, scope, &value)); .in_scope(region_scope, lint_level, |this| this.as_operand(block, scope, value));
} }
let category = Category::of(&expr.kind).unwrap(); let category = Category::of(&expr.kind).unwrap();
@ -128,11 +128,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
debug!("as_call_operand(block={:?}, expr={:?})", block, expr); debug!("as_call_operand(block={:?}, expr={:?})", block, expr);
let this = self; let this = self;
if let ExprKind::Scope { region_scope, lint_level, value } = &expr.kind { if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind {
let source_info = this.source_info(expr.span); let source_info = this.source_info(expr.span);
let region_scope = (*region_scope, source_info); let region_scope = (region_scope, source_info);
return this.in_scope(region_scope, *lint_level, |this| { return this.in_scope(region_scope, lint_level, |this| {
this.as_call_operand(block, scope, &value) this.as_call_operand(block, scope, value)
}); });
} }
@ -149,7 +149,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// As described above, detect the case where we are passing a value of unsized // As described above, detect the case where we are passing a value of unsized
// type, and that value is coming from the deref of a box. // type, and that value is coming from the deref of a box.
if let ExprKind::Deref { ref arg } = expr.kind { if let ExprKind::Deref { arg } = expr.kind {
// Generate let tmp0 = arg0 // Generate let tmp0 = arg0
let operand = unpack!(block = this.as_temp(block, scope, arg, Mutability::Mut)); let operand = unpack!(block = this.as_temp(block, scope, arg, Mutability::Mut));

View file

@ -406,28 +406,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let this = self; let this = self;
let expr_span = expr.span; let expr_span = expr.span;
let source_info = this.source_info(expr_span); let source_info = this.source_info(expr_span);
match &expr.kind { match expr.kind {
ExprKind::Scope { region_scope, lint_level, value } => { ExprKind::Scope { region_scope, lint_level, value } => {
this.in_scope((*region_scope, source_info), *lint_level, |this| { this.in_scope((region_scope, source_info), lint_level, |this| {
this.expr_as_place(block, &value, mutability, fake_borrow_temps) this.expr_as_place(block, value, mutability, fake_borrow_temps)
}) })
} }
ExprKind::Field { lhs, name } => { ExprKind::Field { lhs, name } => {
let place_builder = unpack!( let place_builder =
block = this.expr_as_place(block, &lhs, mutability, fake_borrow_temps,) unpack!(block = this.expr_as_place(block, lhs, mutability, fake_borrow_temps,));
); block.and(place_builder.field(name, expr.ty))
block.and(place_builder.field(*name, expr.ty))
} }
ExprKind::Deref { arg } => { ExprKind::Deref { arg } => {
let place_builder = unpack!( let place_builder =
block = this.expr_as_place(block, &arg, mutability, fake_borrow_temps,) unpack!(block = this.expr_as_place(block, arg, mutability, fake_borrow_temps,));
);
block.and(place_builder.deref()) block.and(place_builder.deref())
} }
ExprKind::Index { lhs, index } => this.lower_index_expression( ExprKind::Index { lhs, index } => this.lower_index_expression(
block, block,
&lhs, lhs,
&index, index,
mutability, mutability,
fake_borrow_temps, fake_borrow_temps,
expr.temp_lifetime, expr.temp_lifetime,
@ -435,16 +433,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
source_info, source_info,
), ),
ExprKind::UpvarRef { closure_def_id, var_hir_id } => { ExprKind::UpvarRef { closure_def_id, var_hir_id } => {
let upvar_id = ty::UpvarId::new(*var_hir_id, closure_def_id.expect_local()); let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id.expect_local());
this.lower_captured_upvar(block, upvar_id) this.lower_captured_upvar(block, upvar_id)
} }
ExprKind::VarRef { id } => { ExprKind::VarRef { id } => {
let place_builder = if this.is_bound_var_in_guard(*id) { let place_builder = if this.is_bound_var_in_guard(id) {
let index = this.var_local_id(*id, RefWithinGuard); let index = this.var_local_id(id, RefWithinGuard);
PlaceBuilder::from(index).deref() PlaceBuilder::from(index).deref()
} else { } else {
let index = this.var_local_id(*id, OutsideGuard); let index = this.var_local_id(id, OutsideGuard);
PlaceBuilder::from(index) PlaceBuilder::from(index)
}; };
block.and(place_builder) block.and(place_builder)
@ -452,13 +450,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
ExprKind::PlaceTypeAscription { source, user_ty } => { ExprKind::PlaceTypeAscription { source, user_ty } => {
let place_builder = unpack!( let place_builder = unpack!(
block = this.expr_as_place(block, &source, mutability, fake_borrow_temps,) block = this.expr_as_place(block, source, mutability, fake_borrow_temps,)
); );
if let Some(user_ty) = user_ty { if let Some(user_ty) = user_ty {
let annotation_index = let annotation_index =
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span: source_info.span, span: source_info.span,
user_ty: *user_ty, user_ty,
inferred_ty: expr.ty, inferred_ty: expr.ty,
}); });
@ -481,12 +479,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
ExprKind::ValueTypeAscription { source, user_ty } => { ExprKind::ValueTypeAscription { source, user_ty } => {
let temp = let temp =
unpack!(block = this.as_temp(block, source.temp_lifetime, &source, mutability)); unpack!(block = this.as_temp(block, source.temp_lifetime, source, mutability));
if let Some(user_ty) = user_ty { if let Some(user_ty) = user_ty {
let annotation_index = let annotation_index =
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span: source_info.span, span: source_info.span,
user_ty: *user_ty, user_ty,
inferred_ty: expr.ty, inferred_ty: expr.ty,
}); });
this.cfg.push( this.cfg.push(

View file

@ -41,27 +41,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let expr_span = expr.span; let expr_span = expr.span;
let source_info = this.source_info(expr_span); let source_info = this.source_info(expr_span);
match &expr.kind { match expr.kind {
ExprKind::ThreadLocalRef(did) => block.and(Rvalue::ThreadLocalRef(*did)), ExprKind::ThreadLocalRef(did) => block.and(Rvalue::ThreadLocalRef(did)),
ExprKind::Scope { region_scope, lint_level, value } => { ExprKind::Scope { region_scope, lint_level, value } => {
let region_scope = (*region_scope, source_info); let region_scope = (region_scope, source_info);
this.in_scope(region_scope, *lint_level, |this| { this.in_scope(region_scope, lint_level, |this| this.as_rvalue(block, scope, value))
this.as_rvalue(block, scope, &value)
})
} }
ExprKind::Repeat { value, count } => { ExprKind::Repeat { value, count } => {
let value_operand = unpack!(block = this.as_operand(block, scope, &value)); let value_operand = unpack!(block = this.as_operand(block, scope, value));
block.and(Rvalue::Repeat(value_operand, count)) block.and(Rvalue::Repeat(value_operand, count))
} }
ExprKind::Binary { op, lhs, rhs } => { ExprKind::Binary { op, lhs, rhs } => {
let lhs = unpack!(block = this.as_operand(block, scope, &lhs)); let lhs = unpack!(block = this.as_operand(block, scope, lhs));
let rhs = unpack!(block = this.as_operand(block, scope, &rhs)); let rhs = unpack!(block = this.as_operand(block, scope, rhs));
this.build_binary_op(block, *op, expr_span, expr.ty, lhs, rhs) this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs)
} }
ExprKind::Unary { op, arg } => { ExprKind::Unary { op, arg } => {
let arg = unpack!(block = this.as_operand(block, scope, &arg)); let arg = unpack!(block = this.as_operand(block, scope, arg));
// Check for -MIN on signed integers // Check for -MIN on signed integers
if this.check_overflow && *op == UnOp::Neg && expr.ty.is_signed() { if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() {
let bool_ty = this.tcx.types.bool; let bool_ty = this.tcx.types.bool;
let minval = this.minval_literal(expr_span, expr.ty); let minval = this.minval_literal(expr_span, expr.ty);
@ -82,7 +80,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
expr_span, expr_span,
); );
} }
block.and(Rvalue::UnaryOp(*op, arg)) block.and(Rvalue::UnaryOp(op, arg))
} }
ExprKind::Box { value } => { ExprKind::Box { value } => {
// The `Box<T>` temporary created here is not a part of the HIR, // The `Box<T>` temporary created here is not a part of the HIR,
@ -107,18 +105,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block = this.expr_into_dest( block = this.expr_into_dest(
this.tcx.mk_place_deref(Place::from(result)), this.tcx.mk_place_deref(Place::from(result)),
block, block,
&value value
) )
); );
block.and(Rvalue::Use(Operand::Move(Place::from(result)))) block.and(Rvalue::Use(Operand::Move(Place::from(result))))
} }
ExprKind::Cast { source } => { ExprKind::Cast { source } => {
let source = unpack!(block = this.as_operand(block, scope, &source)); let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty)) block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
} }
ExprKind::Pointer { cast, source } => { ExprKind::Pointer { cast, source } => {
let source = unpack!(block = this.as_operand(block, scope, &source)); let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Cast(CastKind::Pointer(*cast), source, expr.ty)) block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
} }
ExprKind::Array { fields } => { ExprKind::Array { fields } => {
// (*) We would (maybe) be closer to codegen if we // (*) We would (maybe) be closer to codegen if we
@ -151,7 +149,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let el_ty = expr.ty.sequence_element_type(this.tcx); let el_ty = expr.ty.sequence_element_type(this.tcx);
let fields: Vec<_> = fields let fields: Vec<_> = fields
.into_iter() .into_iter()
.map(|f| unpack!(block = this.as_operand(block, scope, &f))) .map(|f| unpack!(block = this.as_operand(block, scope, f)))
.collect(); .collect();
block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields)) block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields))
@ -161,7 +159,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// first process the set of fields // first process the set of fields
let fields: Vec<_> = fields let fields: Vec<_> = fields
.into_iter() .into_iter()
.map(|f| unpack!(block = this.as_operand(block, scope, &f))) .map(|f| unpack!(block = this.as_operand(block, scope, f)))
.collect(); .collect();
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields)) block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
@ -181,7 +179,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// This occurs when capturing by copy/move, while // This occurs when capturing by copy/move, while
// by reference captures use as_operand // by reference captures use as_operand
Some(Category::Place) => { Some(Category::Place) => {
let place = unpack!(block = this.as_place(block, &upvar)); let place = unpack!(block = this.as_place(block, upvar));
this.consume_by_copy_or_move(place) this.consume_by_copy_or_move(place)
} }
_ => { _ => {
@ -189,17 +187,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// borrow captures when capturing an immutable // borrow captures when capturing an immutable
// variable. This is sound because the mutation // variable. This is sound because the mutation
// that caused the capture will cause an error. // that caused the capture will cause an error.
match &upvar.kind { match upvar.kind {
ExprKind::Borrow { ExprKind::Borrow {
borrow_kind: borrow_kind:
BorrowKind::Mut { allow_two_phase_borrow: false }, BorrowKind::Mut { allow_two_phase_borrow: false },
arg, arg,
} => unpack!( } => unpack!(
block = this.limit_capture_mutability( block = this.limit_capture_mutability(
upvar.span, upvar.ty, scope, block, &arg, upvar.span, upvar.ty, scope, block, arg,
) )
), ),
_ => unpack!(block = this.as_operand(block, scope, &upvar)), _ => unpack!(block = this.as_operand(block, scope, upvar)),
} }
} }
} }
@ -210,9 +208,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// We implicitly set the discriminant to 0. See // We implicitly set the discriminant to 0. See
// librustc_mir/transform/deaggregator.rs for details. // librustc_mir/transform/deaggregator.rs for details.
let movability = movability.unwrap(); let movability = movability.unwrap();
box AggregateKind::Generator(*closure_id, substs, movability) box AggregateKind::Generator(closure_id, substs, movability)
} }
UpvarSubsts::Closure(substs) => box AggregateKind::Closure(*closure_id, substs), UpvarSubsts::Closure(substs) => box AggregateKind::Closure(closure_id, substs),
}; };
block.and(Rvalue::Aggregate(result, operands)) block.and(Rvalue::Aggregate(result, operands))
} }

View file

@ -38,8 +38,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let expr_span = expr.span; let expr_span = expr.span;
let source_info = this.source_info(expr_span); let source_info = this.source_info(expr_span);
if let ExprKind::Scope { region_scope, lint_level, value } = &expr.kind { if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind {
return this.in_scope((*region_scope, source_info), *lint_level, |this| { return this.in_scope((region_scope, source_info), lint_level, |this| {
this.as_temp(block, temp_lifetime, value, mutability) this.as_temp(block, temp_lifetime, value, mutability)
}); });
} }

View file

@ -36,24 +36,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.block_context.push(BlockFrame::SubExpr); this.block_context.push(BlockFrame::SubExpr);
} }
let block_and = match &expr.kind { let block_and = match expr.kind {
ExprKind::Scope { region_scope, lint_level, value } => { ExprKind::Scope { region_scope, lint_level, value } => {
let region_scope = (*region_scope, source_info); let region_scope = (region_scope, source_info);
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
this.in_scope(region_scope, *lint_level, |this| { this.in_scope(region_scope, lint_level, |this| {
this.expr_into_dest(destination, block, &value) this.expr_into_dest(destination, block, value)
}) })
}) })
} }
ExprKind::Block { body: ast_block } => { ExprKind::Block { body: ref ast_block } => {
this.ast_block(destination, block, &ast_block, source_info) this.ast_block(destination, block, ast_block, source_info)
} }
ExprKind::Match { scrutinee, arms } => { ExprKind::Match { scrutinee, arms } => {
this.match_expr(destination, expr_span, block, &scrutinee, &arms) this.match_expr(destination, expr_span, block, scrutinee, arms)
} }
ExprKind::If { cond, then, else_opt } => { ExprKind::If { cond, then, else_opt } => {
let place = unpack!( let place = unpack!(
block = this.as_temp(block, Some(this.local_scope()), &cond, Mutability::Mut) block = this.as_temp(block, Some(this.local_scope()), cond, Mutability::Mut)
); );
let operand = Operand::Move(Place::from(place)); let operand = Operand::Move(Place::from(place));
@ -62,9 +62,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let term = TerminatorKind::if_(this.tcx, operand, then_block, else_block); let term = TerminatorKind::if_(this.tcx, operand, then_block, else_block);
this.cfg.terminate(block, source_info, term); this.cfg.terminate(block, source_info, term);
unpack!(then_block = this.expr_into_dest(destination, then_block, &then)); unpack!(then_block = this.expr_into_dest(destination, then_block, then));
else_block = if let Some(else_opt) = else_opt { else_block = if let Some(else_opt) = else_opt {
unpack!(this.expr_into_dest(destination, else_block, &else_opt)) unpack!(this.expr_into_dest(destination, else_block, else_opt))
} else { } else {
// Body of the `if` expression without an `else` clause must return `()`, thus // Body of the `if` expression without an `else` clause must return `()`, thus
// we implicitly generate a `else {}` if it is not specified. // we implicitly generate a `else {}` if it is not specified.
@ -94,8 +94,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// (#66975) Source could be a const of type `!`, so has to // (#66975) Source could be a const of type `!`, so has to
// exist in the generated MIR. // exist in the generated MIR.
unpack!( unpack!(
block = block = this.as_temp(block, Some(this.local_scope()), source, Mutability::Mut,)
this.as_temp(block, Some(this.local_scope()), &source, Mutability::Mut,)
); );
// This is an optimization. If the expression was a call then we already have an // This is an optimization. If the expression was a call then we already have an
@ -128,7 +127,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.cfg.start_new_block(), this.cfg.start_new_block(),
); );
let lhs = unpack!(block = this.as_local_operand(block, &lhs)); let lhs = unpack!(block = this.as_local_operand(block, lhs));
let blocks = match op { let blocks = match op {
LogicalOp::And => (else_block, false_block), LogicalOp::And => (else_block, false_block),
LogicalOp::Or => (true_block, else_block), LogicalOp::Or => (true_block, else_block),
@ -136,7 +135,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let term = TerminatorKind::if_(this.tcx, lhs, blocks.0, blocks.1); let term = TerminatorKind::if_(this.tcx, lhs, blocks.0, blocks.1);
this.cfg.terminate(block, source_info, term); this.cfg.terminate(block, source_info, term);
let rhs = unpack!(else_block = this.as_local_operand(else_block, &rhs)); let rhs = unpack!(else_block = this.as_local_operand(else_block, rhs));
let term = TerminatorKind::if_(this.tcx, rhs, true_block, false_block); let term = TerminatorKind::if_(this.tcx, rhs, true_block, false_block);
this.cfg.terminate(else_block, source_info, term); this.cfg.terminate(else_block, source_info, term);
@ -197,7 +196,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// introduce a unit temporary as the destination for the loop body. // introduce a unit temporary as the destination for the loop body.
let tmp = this.get_unit_temp(); let tmp = this.get_unit_temp();
// Execute the body, branching back to the test. // Execute the body, branching back to the test.
let body_block_end = unpack!(this.expr_into_dest(tmp, body_block, &body)); let body_block_end = unpack!(this.expr_into_dest(tmp, body_block, body));
this.cfg.goto(body_block_end, source_info, loop_block); this.cfg.goto(body_block_end, source_info, loop_block);
// Loops are only exited by `break` expressions. // Loops are only exited by `break` expressions.
@ -205,10 +204,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}) })
} }
ExprKind::Call { ty: _, fun, args, from_hir_call, fn_span } => { ExprKind::Call { ty: _, fun, args, from_hir_call, fn_span } => {
let fun = unpack!(block = this.as_local_operand(block, &fun)); let fun = unpack!(block = this.as_local_operand(block, fun));
let args: Vec<_> = args let args: Vec<_> = args
.into_iter() .into_iter()
.map(|arg| unpack!(block = this.as_local_call_operand(block, &arg))) .map(|arg| unpack!(block = this.as_local_call_operand(block, arg)))
.collect(); .collect();
let success = this.cfg.start_new_block(); let success = this.cfg.start_new_block();
@ -232,14 +231,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} else { } else {
Some((destination, success)) Some((destination, success))
}, },
from_hir_call: *from_hir_call, from_hir_call,
fn_span: *fn_span, fn_span,
}, },
); );
this.diverge_from(block); this.diverge_from(block);
success.unit() success.unit()
} }
ExprKind::Use { source } => this.expr_into_dest(destination, block, &source), ExprKind::Use { source } => this.expr_into_dest(destination, block, source),
ExprKind::Borrow { arg, borrow_kind } => { ExprKind::Borrow { arg, borrow_kind } => {
// We don't do this in `as_rvalue` because we use `as_place` // We don't do this in `as_rvalue` because we use `as_place`
// for borrow expressions, so we cannot create an `RValue` that // for borrow expressions, so we cannot create an `RValue` that
@ -247,23 +246,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// by this method anyway, so this shouldn't cause too many // by this method anyway, so this shouldn't cause too many
// unnecessary temporaries. // unnecessary temporaries.
let arg_place = match borrow_kind { let arg_place = match borrow_kind {
BorrowKind::Shared => unpack!(block = this.as_read_only_place(block, &arg)), BorrowKind::Shared => unpack!(block = this.as_read_only_place(block, arg)),
_ => unpack!(block = this.as_place(block, &arg)), _ => unpack!(block = this.as_place(block, arg)),
}; };
let borrow = Rvalue::Ref(this.tcx.lifetimes.re_erased, *borrow_kind, arg_place); let borrow = Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind, arg_place);
this.cfg.push_assign(block, source_info, destination, borrow); this.cfg.push_assign(block, source_info, destination, borrow);
block.unit() block.unit()
} }
ExprKind::AddressOf { mutability, arg } => { ExprKind::AddressOf { mutability, arg } => {
let place = match mutability { let place = match mutability {
hir::Mutability::Not => this.as_read_only_place(block, &arg), hir::Mutability::Not => this.as_read_only_place(block, arg),
hir::Mutability::Mut => this.as_place(block, &arg), hir::Mutability::Mut => this.as_place(block, arg),
}; };
let address_of = Rvalue::AddressOf(*mutability, unpack!(block = place)); let address_of = Rvalue::AddressOf(mutability, unpack!(block = place));
this.cfg.push_assign(block, source_info, destination, address_of); this.cfg.push_assign(block, source_info, destination, address_of);
block.unit() block.unit()
} }
ExprKind::Adt { adt_def, variant_index, substs, user_ty, fields, base } => { ExprKind::Adt { adt_def, variant_index, substs, user_ty, fields, ref base } => {
// See the notes for `ExprKind::Array` in `as_rvalue` and for // See the notes for `ExprKind::Array` in `as_rvalue` and for
// `ExprKind::Borrow` above. // `ExprKind::Borrow` above.
let is_union = adt_def.is_union(); let is_union = adt_def.is_union();
@ -275,16 +274,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// (evaluating them in order given by user) // (evaluating them in order given by user)
let fields_map: FxHashMap<_, _> = fields let fields_map: FxHashMap<_, _> = fields
.into_iter() .into_iter()
.map(|f| { .map(|f| (f.name, unpack!(block = this.as_operand(block, Some(scope), f.expr))))
(f.name, unpack!(block = this.as_operand(block, Some(scope), &f.expr)))
})
.collect(); .collect();
let field_names: Vec<_> = let field_names: Vec<_> =
(0..adt_def.variants[*variant_index].fields.len()).map(Field::new).collect(); (0..adt_def.variants[variant_index].fields.len()).map(Field::new).collect();
let fields: Vec<_> = if let Some(FruInfo { base, field_types }) = base { let fields: Vec<_> = if let Some(FruInfo { base, field_types }) = base {
let place_builder = unpack!(block = this.as_place_builder(block, &base)); let place_builder = unpack!(block = this.as_place_builder(block, base));
// MIR does not natively support FRU, so for each // MIR does not natively support FRU, so for each
// base-supplied field, generate an operand that // base-supplied field, generate an operand that
@ -318,7 +315,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}); });
let adt = box AggregateKind::Adt( let adt = box AggregateKind::Adt(
adt_def, adt_def,
*variant_index, variant_index,
substs, substs,
user_ty, user_ty,
active_field_index, active_field_index,
@ -336,25 +333,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
use rustc_middle::mir; use rustc_middle::mir;
let operands = operands let operands = operands
.into_iter() .into_iter()
.map(|op| match op { .map(|op| match *op {
thir::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In { thir::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In {
reg: *reg, reg,
value: unpack!(block = this.as_local_operand(block, &expr)), value: unpack!(block = this.as_local_operand(block, expr)),
}, },
thir::InlineAsmOperand::Out { reg, late, expr } => { thir::InlineAsmOperand::Out { reg, late, expr } => {
mir::InlineAsmOperand::Out { mir::InlineAsmOperand::Out {
reg: *reg, reg,
late: *late, late,
place: expr place: expr
.as_ref() .as_ref()
.map(|expr| unpack!(block = this.as_place(block, expr))), .map(|expr| unpack!(block = this.as_place(block, expr))),
} }
} }
thir::InlineAsmOperand::InOut { reg, late, expr } => { thir::InlineAsmOperand::InOut { reg, late, expr } => {
let place = unpack!(block = this.as_place(block, &expr)); let place = unpack!(block = this.as_place(block, expr));
mir::InlineAsmOperand::InOut { mir::InlineAsmOperand::InOut {
reg: *reg, reg,
late: *late, late,
// This works because asm operands must be Copy // This works because asm operands must be Copy
in_value: Operand::Copy(place), in_value: Operand::Copy(place),
out_place: Some(place), out_place: Some(place),
@ -362,22 +359,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
thir::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => { thir::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => {
mir::InlineAsmOperand::InOut { mir::InlineAsmOperand::InOut {
reg: *reg, reg,
late: *late, late,
in_value: unpack!(block = this.as_local_operand(block, &in_expr)), in_value: unpack!(block = this.as_local_operand(block, in_expr)),
out_place: out_expr.as_ref().map(|out_expr| { out_place: out_expr.as_ref().map(|out_expr| {
unpack!(block = this.as_place(block, out_expr)) unpack!(block = this.as_place(block, out_expr))
}), }),
} }
} }
thir::InlineAsmOperand::Const { expr } => mir::InlineAsmOperand::Const { thir::InlineAsmOperand::Const { expr } => mir::InlineAsmOperand::Const {
value: unpack!(block = this.as_local_operand(block, &expr)), value: unpack!(block = this.as_local_operand(block, expr)),
}, },
thir::InlineAsmOperand::SymFn { expr } => { thir::InlineAsmOperand::SymFn { expr } => {
mir::InlineAsmOperand::SymFn { value: box this.as_constant(&expr) } mir::InlineAsmOperand::SymFn { value: box this.as_constant(expr) }
} }
thir::InlineAsmOperand::SymStatic { def_id } => { thir::InlineAsmOperand::SymStatic { def_id } => {
mir::InlineAsmOperand::SymStatic { def_id: *def_id } mir::InlineAsmOperand::SymStatic { def_id }
} }
}) })
.collect(); .collect();
@ -390,7 +387,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
TerminatorKind::InlineAsm { TerminatorKind::InlineAsm {
template, template,
operands, operands,
options: *options, options,
line_spans, line_spans,
destination: if options.contains(InlineAsmOptions::NORETURN) { destination: if options.contains(InlineAsmOptions::NORETURN) {
None None
@ -449,7 +446,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
ExprKind::Yield { value } => { ExprKind::Yield { value } => {
let scope = this.local_scope(); let scope = this.local_scope();
let value = unpack!(block = this.as_operand(block, Some(scope), &value)); let value = unpack!(block = this.as_operand(block, Some(scope), value));
let resume = this.cfg.start_new_block(); let resume = this.cfg.start_new_block();
this.cfg.terminate( this.cfg.terminate(
block, block,

View file

@ -21,10 +21,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let source_info = this.source_info(expr.span); let source_info = this.source_info(expr.span);
// Handle a number of expressions that don't need a destination at all. This // Handle a number of expressions that don't need a destination at all. This
// avoids needing a mountain of temporary `()` variables. // avoids needing a mountain of temporary `()` variables.
match &expr.kind { match expr.kind {
ExprKind::Scope { region_scope, lint_level, value } => { ExprKind::Scope { region_scope, lint_level, value } => {
this.in_scope((*region_scope, source_info), *lint_level, |this| { this.in_scope((region_scope, source_info), lint_level, |this| {
this.stmt_expr(block, &value, statement_scope) this.stmt_expr(block, value, statement_scope)
}) })
} }
ExprKind::Assign { lhs, rhs } => { ExprKind::Assign { lhs, rhs } => {
@ -40,12 +40,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Generate better code for things that don't need to be // Generate better code for things that don't need to be
// dropped. // dropped.
if lhs.ty.needs_drop(this.tcx, this.param_env) { if lhs.ty.needs_drop(this.tcx, this.param_env) {
let rhs = unpack!(block = this.as_local_operand(block, &rhs)); let rhs = unpack!(block = this.as_local_operand(block, rhs));
let lhs = unpack!(block = this.as_place(block, &lhs)); let lhs = unpack!(block = this.as_place(block, lhs));
unpack!(block = this.build_drop_and_replace(block, lhs_span, lhs, rhs)); unpack!(block = this.build_drop_and_replace(block, lhs_span, lhs, rhs));
} else { } else {
let rhs = unpack!(block = this.as_local_rvalue(block, &rhs)); let rhs = unpack!(block = this.as_local_rvalue(block, rhs));
let lhs = unpack!(block = this.as_place(block, &lhs)); let lhs = unpack!(block = this.as_place(block, lhs));
this.cfg.push_assign(block, source_info, lhs, rhs); this.cfg.push_assign(block, source_info, lhs, rhs);
} }
@ -67,21 +67,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.block_context.push(BlockFrame::SubExpr); this.block_context.push(BlockFrame::SubExpr);
// As above, RTL. // As above, RTL.
let rhs = unpack!(block = this.as_local_operand(block, &rhs)); let rhs = unpack!(block = this.as_local_operand(block, rhs));
let lhs = unpack!(block = this.as_place(block, &lhs)); let lhs = unpack!(block = this.as_place(block, lhs));
// we don't have to drop prior contents or anything // we don't have to drop prior contents or anything
// because AssignOp is only legal for Copy types // because AssignOp is only legal for Copy types
// (overloaded ops should be desugared into a call). // (overloaded ops should be desugared into a call).
let result = unpack!( let result = unpack!(
block = this.build_binary_op( block =
block, this.build_binary_op(block, op, expr_span, lhs_ty, Operand::Copy(lhs), rhs)
*op,
expr_span,
lhs_ty,
Operand::Copy(lhs),
rhs
)
); );
this.cfg.push_assign(block, source_info, lhs, result); this.cfg.push_assign(block, source_info, lhs, result);
@ -89,12 +83,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.unit() block.unit()
} }
ExprKind::Continue { label } => { ExprKind::Continue { label } => {
this.break_scope(block, None, BreakableTarget::Continue(*label), source_info) this.break_scope(block, None, BreakableTarget::Continue(label), source_info)
} }
ExprKind::Break { label, value } => this.break_scope( ExprKind::Break { label, value } => this.break_scope(
block, block,
value.as_deref(), value.as_deref(),
BreakableTarget::Break(*label), BreakableTarget::Break(label),
source_info, source_info,
), ),
ExprKind::Return { value } => { ExprKind::Return { value } => {
@ -120,7 +114,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement { Statement {
source_info, source_info,
kind: StatementKind::LlvmInlineAsm(box LlvmInlineAsm { kind: StatementKind::LlvmInlineAsm(box LlvmInlineAsm {
asm: (*asm).clone(), asm: asm.clone(),
outputs, outputs,
inputs, inputs,
}), }),

View file

@ -1754,7 +1754,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Guard::IfLet(pat, scrutinee) => { Guard::IfLet(pat, scrutinee) => {
let scrutinee_span = scrutinee.span; let scrutinee_span = scrutinee.span;
let scrutinee_place = let scrutinee_place =
unpack!(block = self.lower_scrutinee(block, &scrutinee, scrutinee_span)); unpack!(block = self.lower_scrutinee(block, scrutinee, scrutinee_span));
let mut guard_candidate = Candidate::new(scrutinee_place, &pat, false); let mut guard_candidate = Candidate::new(scrutinee_place, &pat, false);
let wildcard = Pat::wildcard_from_ty(pat.ty); let wildcard = Pat::wildcard_from_ty(pat.ty);
let mut otherwise_candidate = Candidate::new(scrutinee_place, &wildcard, false); let mut otherwise_candidate = Candidate::new(scrutinee_place, &wildcard, false);

View file

@ -643,7 +643,7 @@ where
fn_def.did.to_def_id(), fn_def.did.to_def_id(),
&arguments, &arguments,
arg_scope, arg_scope,
&expr, expr,
) )
})) }))
})); }));

View file

@ -11,7 +11,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
crate fn mirror_block(&mut self, block: &'tcx hir::Block<'tcx>) -> Block<'thir, 'tcx> { crate fn mirror_block(&mut self, block: &'tcx hir::Block<'tcx>) -> Block<'thir, 'tcx> {
// We have to eagerly lower the "spine" of the statements // We have to eagerly lower the "spine" of the statements
// in order to get the lexical scoping correctly. // in order to get the lexical scoping correctly.
let stmts = self.mirror_stmts(block.hir_id.local_id, &*block.stmts); let stmts = self.mirror_stmts(block.hir_id.local_id, block.stmts);
let opt_destruction_scope = let opt_destruction_scope =
self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id); self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id);
Block { Block {
@ -23,7 +23,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
opt_destruction_scope, opt_destruction_scope,
span: block.span, span: block.span,
stmts, stmts,
expr: block.expr.as_ref().map(|expr| self.mirror_expr(expr)), expr: block.expr.map(|expr| self.mirror_expr(expr)),
safety_mode: match block.rules { safety_mode: match block.rules {
hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe, hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe,
hir::BlockCheckMode::UnsafeBlock(..) => BlockSafety::ExplicitUnsafe(block.hir_id), hir::BlockCheckMode::UnsafeBlock(..) => BlockSafety::ExplicitUnsafe(block.hir_id),
@ -59,7 +59,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
data: region::ScopeData::Remainder(region::FirstStatementIndex::new(index)), data: region::ScopeData::Remainder(region::FirstStatementIndex::new(index)),
}; };
let mut pattern = self.pattern_from_hir(&local.pat); let mut pattern = self.pattern_from_hir(local.pat);
if let Some(ty) = &local.ty { if let Some(ty) = &local.ty {
if let Some(&user_ty) = if let Some(&user_ty) =

View file

@ -203,7 +203,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
ExprKind::Call { ExprKind::Call {
ty: method.ty, ty: method.ty,
fun: self.arena.alloc(method), fun: self.arena.alloc(method),
args: &*self args: self
.arena .arena
.alloc_from_iter(vec![self.mirror_expr_inner(fun), tupled_args]), .alloc_from_iter(vec![self.mirror_expr_inner(fun), tupled_args]),
from_hir_call: true, from_hir_call: true,
@ -243,7 +243,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
adt_def, adt_def,
substs, substs,
variant_index: index, variant_index: index,
fields: &*field_refs, fields: field_refs,
user_ty, user_ty,
base: None, base: None,
} }
@ -277,7 +277,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
if self.typeck_results().is_method_call(expr) { if self.typeck_results().is_method_call(expr) {
let lhs = self.mirror_expr_inner(lhs); let lhs = self.mirror_expr_inner(lhs);
let rhs = self.mirror_expr_inner(rhs); let rhs = self.mirror_expr_inner(rhs);
self.overloaded_operator(expr, &*self.arena.alloc_from_iter(vec![lhs, rhs])) self.overloaded_operator(expr, self.arena.alloc_from_iter(vec![lhs, rhs]))
} else { } else {
ExprKind::AssignOp { ExprKind::AssignOp {
op: bin_op(op.node), op: bin_op(op.node),
@ -297,7 +297,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
if self.typeck_results().is_method_call(expr) { if self.typeck_results().is_method_call(expr) {
let lhs = self.mirror_expr_inner(lhs); let lhs = self.mirror_expr_inner(lhs);
let rhs = self.mirror_expr_inner(rhs); let rhs = self.mirror_expr_inner(rhs);
self.overloaded_operator(expr, &*self.arena.alloc_from_iter(vec![lhs, rhs])) self.overloaded_operator(expr, self.arena.alloc_from_iter(vec![lhs, rhs]))
} else { } else {
// FIXME overflow // FIXME overflow
match op.node { match op.node {
@ -332,7 +332,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
expr, expr,
expr_ty, expr_ty,
None, None,
&*self.arena.alloc_from_iter(vec![lhs, index]), self.arena.alloc_from_iter(vec![lhs, index]),
expr.span, expr.span,
) )
} else { } else {
@ -347,7 +347,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
expr, expr,
expr_ty, expr_ty,
None, None,
&*self.arena.alloc_from_iter(iter::once(arg)), self.arena.alloc_from_iter(iter::once(arg)),
expr.span, expr.span,
) )
} else { } else {
@ -358,7 +358,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
hir::ExprKind::Unary(hir::UnOp::Not, ref arg) => { hir::ExprKind::Unary(hir::UnOp::Not, ref arg) => {
if self.typeck_results().is_method_call(expr) { if self.typeck_results().is_method_call(expr) {
let arg = self.mirror_expr_inner(arg); let arg = self.mirror_expr_inner(arg);
self.overloaded_operator(expr, &*self.arena.alloc_from_iter(iter::once(arg))) self.overloaded_operator(expr, self.arena.alloc_from_iter(iter::once(arg)))
} else { } else {
ExprKind::Unary { op: UnOp::Not, arg: self.mirror_expr(arg) } ExprKind::Unary { op: UnOp::Not, arg: self.mirror_expr(arg) }
} }
@ -367,7 +367,7 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
hir::ExprKind::Unary(hir::UnOp::Neg, ref arg) => { hir::ExprKind::Unary(hir::UnOp::Neg, ref arg) => {
if self.typeck_results().is_method_call(expr) { if self.typeck_results().is_method_call(expr) {
let arg = self.mirror_expr_inner(arg); let arg = self.mirror_expr_inner(arg);
self.overloaded_operator(expr, &*self.arena.alloc_from_iter(iter::once(arg))) self.overloaded_operator(expr, self.arena.alloc_from_iter(iter::once(arg)))
} else if let hir::ExprKind::Lit(ref lit) = arg.kind { } else if let hir::ExprKind::Lit(ref lit) = arg.kind {
ExprKind::Literal { ExprKind::Literal {
literal: self.const_eval_literal(&lit.node, expr_ty, lit.span, true), literal: self.const_eval_literal(&lit.node, expr_ty, lit.span, true),