use rustc_middle::ty::{self, Ty, UpvarSubsts};
use rustc_span::Span;
+use std::slice;
+
impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Returns an rvalue suitable for use until the end of the current
/// scope expression.
M: Mirror<'tcx, Output = Expr<'tcx>>,
{
let local_scope = self.local_scope();
- self.as_rvalue(block, local_scope, expr)
+ self.as_rvalue(block, Some(local_scope), expr)
}
/// Compile `expr`, yielding an rvalue.
ExprKind::Box { value } => {
let value = this.hir.mirror(value);
// The `Box<T>` temporary created here is not a part of the HIR,
- // and therefore is not considered during generator OIBIT
+ // and therefore is not considered during generator auto-trait
// determination. See the comment about `box` at `yield_in_scope`.
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span).internal());
this.cfg.push(
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
this.cfg.push_assign(block, source_info, Place::from(result), box_);
- // initialize the box contents:
+ // Initialize the box contents. No scope is needed since the
+ // `Box` is already scheduled to be dropped.
unpack!(
- block =
- this.into(this.hir.tcx().mk_place_deref(Place::from(result)), block, value)
+ block = this.into(
+ this.hir.tcx().mk_place_deref(Place::from(result)),
+ None,
+ block,
+ value,
+ )
);
- block.and(Rvalue::Use(Operand::Move(Place::from(result))))
+ let result_operand = Operand::Move(Place::from(result));
+ this.record_operands_moved(slice::from_ref(&result_operand));
+ block.and(Rvalue::Use(result_operand))
}
ExprKind::Cast { source } => {
let source = unpack!(block = this.as_operand(block, scope, source));
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
.collect();
+ this.record_operands_moved(&fields);
block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields))
}
ExprKind::Tuple { fields } => {
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
.collect();
+ this.record_operands_moved(&fields);
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
}
ExprKind::Closure { closure_id, substs, upvars, movability } => {
}
UpvarSubsts::Closure(substs) => box AggregateKind::Closure(closure_id, substs),
};
+ this.record_operands_moved(&operands);
block.and(Rvalue::Aggregate(result, operands))
}
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
| ExprKind::Deref { .. }
| ExprKind::Index { .. }
| ExprKind::VarRef { .. }
- | ExprKind::SelfRef
+ | ExprKind::UpvarRef { .. }
| ExprKind::Break { .. }
| ExprKind::Continue { .. }
| ExprKind::Return { .. }
| ExprKind::ValueTypeAscription { .. } => {
// these do not have corresponding `Rvalue` variants,
// so make an operand and then return that
- debug_assert!(match Category::of(&expr.kind) {
- Some(Category::Rvalue(RvalueFunc::AsRvalue)) => false,
- _ => true,
- });
+ debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Rvalue(RvalueFunc::AsRvalue))));
let operand = unpack!(block = this.as_operand(block, scope, expr));
block.and(Rvalue::Use(operand))
}
Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place),
);
- // In constants, temp_lifetime is None. We should not need to drop
- // anything because no values with a destructor can be created in
- // a constant at this time, even if the type may need dropping.
+ // See the comment in `expr_as_temp` and on the `rvalue_scopes` field for why
+ // this can be `None`.
if let Some(temp_lifetime) = temp_lifetime {
this.schedule_drop_storage_and_value(upvar_span, temp_lifetime, temp);
}