Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4ba5010

Browse files
committedAug 14, 2024
update comment, rename fn record_operand_moved
the previous name made it seem as if the operand was moved while it's actually just looking at all `Move` operands.
1 parent 3e0db6a commit 4ba5010

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed
 

‎compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
197197
)
198198
);
199199
let result_operand = Operand::Move(Place::from(result));
200-
this.record_operands_moved(slice::from_ref(&result_operand));
200+
this.record_move_operands(slice::from_ref(&result_operand));
201201
block.and(Rvalue::Use(result_operand))
202202
}
203203
ExprKind::Cast { source } => {
@@ -366,7 +366,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
366366
})
367367
.collect();
368368

369-
this.record_operands_moved(&fields.raw);
369+
this.record_move_operands(&fields.raw);
370370
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(el_ty)), fields))
371371
}
372372
ExprKind::Tuple { ref fields } => {
@@ -388,7 +388,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
388388
})
389389
.collect();
390390

391-
this.record_operands_moved(&fields.raw);
391+
this.record_move_operands(&fields.raw);
392392
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields))
393393
}
394394
ExprKind::Closure(box ClosureExpr {
@@ -491,7 +491,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
491491
Box::new(AggregateKind::CoroutineClosure(closure_id.to_def_id(), args))
492492
}
493493
};
494-
this.record_operands_moved(&operands.raw);
494+
this.record_move_operands(&operands.raw);
495495
block.and(Rvalue::Aggregate(result, operands))
496496
}
497497
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
@@ -747,7 +747,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
747747
this.diverge_from(block);
748748
block = success;
749749
}
750-
this.record_operands_moved(&[value_operand]);
750+
this.record_move_operands(&[value_operand]);
751751
}
752752
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), IndexVec::new()))
753753
}

‎compiler/rustc_mir_build/src/build/expr/into.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
314314
);
315315
this.diverge_from(block);
316316

317-
// This is here and not before `diverge_from` to avoid breaking
318-
// the example in #80949.
317+
// By only recording the moved operands after `diverge_from`, we emit redundant
318+
// drop calls for the arguments of the call. While these should be unnecessary,
319+
// they cause borrowck to shrink the required lifetime of some borrows which is
320+
// necessary to avoid breaking the example in #80949.
319321
// FIXME(matthewjasper): Look at this again if Polonius is
320322
// stabilized.
321-
this.record_operands_moved(&args);
323+
this.record_move_operands(&args);
322324
schedule_drop(this);
323325
success.unit()
324326
}
@@ -419,7 +421,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
419421
user_ty,
420422
active_field_index,
421423
));
422-
this.record_operands_moved(&fields.raw);
424+
this.record_move_operands(&fields.raw);
423425
this.cfg.push_assign(
424426
block,
425427
source_info,
@@ -602,7 +604,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
602604
)
603605
);
604606
let resume = this.cfg.start_new_block();
605-
this.record_operands_moved(slice::from_ref(&value));
607+
this.record_move_operands(slice::from_ref(&value));
606608
this.cfg.terminate(
607609
block,
608610
source_info,

‎compiler/rustc_mir_build/src/build/expr/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
116116
.collect();
117117
let args: Vec<_> = spanned_args.iter().map(|arg| arg.node.clone()).collect();
118118

119-
this.record_operands_moved(&args);
119+
this.record_move_operands(&args);
120120

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

‎compiler/rustc_mir_build/src/build/scope.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1009,13 +1009,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10091009
region_scope: region::Scope,
10101010
local: Local,
10111011
) {
1012+
// We first drop the value and then the underlying storage.
10121013
self.schedule_drop(span, region_scope, local, DropKind::Storage);
10131014
self.schedule_drop(span, region_scope, local, DropKind::Value);
10141015
}
10151016

1016-
/// Indicates that `place` should be dropped on exit from `region_scope`.
1017+
/// Indicates that `local` should be dropped on exit from `region_scope`.
10171018
///
1018-
/// When called with `DropKind::Storage`, `place` shouldn't be the return
1019+
/// When called with `DropKind::Storage`, `local` shouldn't be the return
10191020
/// place, or a function parameter.
10201021
pub(crate) fn schedule_drop(
10211022
&mut self,
@@ -1121,7 +1122,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11211122
}
11221123

11231124
/// Unschedule a drop. Used for `break`, `return` and `match` expressions,
1124-
/// where `record_operands_moved` is not powerful enough.
1125+
/// where `record_move_operands` is not powerful enough.
11251126
///
11261127
/// The given local is expected to have a value drop scheduled in the given
11271128
/// scope and for that drop to be the most recent thing scheduled in that
@@ -1146,8 +1147,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11461147
// type does not need drop.
11471148
None if self.local_decls[local].ty.has_opaque_types() => return,
11481149
_ => bug!(
1149-
"found wrong drop, expected value drop of {:?}, found {:?}",
1150+
"found wrong drop, expected value drop of {:?} in scope {:?}, found {:?}",
11501151
local,
1152+
region_scope,
11511153
drop,
11521154
),
11531155
}
@@ -1192,7 +1194,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11921194
/// spurious borrow-check errors -- the problem, ironically, is
11931195
/// not the `DROP(_X)` itself, but the (spurious) unwind pathways
11941196
/// that it creates. See #64391 for an example.
1195-
pub(crate) fn record_operands_moved(&mut self, operands: &[Operand<'tcx>]) {
1197+
pub(crate) fn record_move_operands(&mut self, operands: &[Operand<'tcx>]) {
11961198
let local_scope = self.local_scope();
11971199
let scope = self.scopes.scopes.last_mut().unwrap();
11981200

0 commit comments

Comments
 (0)
Please sign in to comment.