Skip to content

Commit 9f3f117

Browse files
Rollup merge of #158706 - cjgillot:drop-api, r=Nadrieril
Tweaks to MIR building scope API Some simplifications that come from staring too long at that code
2 parents ff239d9 + 28ed28a commit 9f3f117

6 files changed

Lines changed: 74 additions & 90 deletions

File tree

compiler/rustc_mir_build/src/builder/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
184184

185185
// Declare the bindings, which may create a source scope.
186186
let remainder_span = remainder_scope.span(this.tcx, this.region_scope_tree);
187-
this.push_scope((*remainder_scope, source_info));
187+
this.push_scope(*remainder_scope);
188188
let_scope_stack.push(remainder_scope);
189189

190190
let visibility_scope =
@@ -242,7 +242,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
242242
this.block_context.push(BlockFrame::Statement { ignores_expr_result });
243243

244244
// Enter the remainder scope, i.e., the bindings' destruction scope.
245-
this.push_scope((*remainder_scope, source_info));
245+
this.push_scope(*remainder_scope);
246246
let_scope_stack.push(remainder_scope);
247247

248248
// Declare the bindings, which may create a source scope.
@@ -346,7 +346,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
346346
// Finally, we pop all the let scopes before exiting out from the scope of block
347347
// itself.
348348
for scope in let_scope_stack.into_iter().rev() {
349-
block = this.pop_scope((*scope, source_info), block).into_block();
349+
block = this.pop_scope(*scope, block).into_block();
350350
}
351351
// Restore the original source scope.
352352
this.source_scope = outer_source_scope;

compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
726726
// This can be `None` if the expression's temporary scope was extended so that it can be
727727
// borrowed by a `const` or `static`. In that case, it's never dropped.
728728
if let Some(temp_lifetime) = temp_lifetime {
729-
this.schedule_drop_storage_and_value(upvar_span, temp_lifetime, temp);
729+
this.schedule_drop_storage(upvar_span, temp_lifetime, temp);
730+
this.schedule_drop_value(upvar_span, temp_lifetime, temp);
730731
}
731732

732733
block.and(Operand::Move(Place::from(temp)))

compiler/rustc_mir_build/src/builder/expr/as_temp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::mir::*;
77
use rustc_middle::thir::*;
88
use tracing::{debug, instrument};
99

10-
use crate::builder::scope::{DropKind, LintLevel};
10+
use crate::builder::scope::LintLevel;
1111
use crate::builder::{BlockAnd, BlockAndExtension, Builder};
1212

1313
impl<'a, 'tcx> Builder<'a, 'tcx> {
@@ -120,15 +120,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
120120
// `bar(&foo())` or anything within a block will keep the
121121
// regular drops just like runtime code.
122122
if let Some(temp_lifetime) = temp_lifetime.temp_lifetime {
123-
this.schedule_drop(expr_span, temp_lifetime, temp, DropKind::Storage);
123+
this.schedule_drop_storage(expr_span, temp_lifetime, temp);
124124
}
125125
}
126126
}
127127

128128
block = this.expr_into_dest(temp_place, block, expr_id).into_block();
129129

130130
if let Some(temp_lifetime) = temp_lifetime.temp_lifetime {
131-
this.schedule_drop(expr_span, temp_lifetime, temp, DropKind::Value);
131+
this.schedule_drop_value(expr_span, temp_lifetime, temp);
132132
}
133133

134134
if let Some(backwards_incompatible) = temp_lifetime.backwards_incompatible {

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::builder::ForGuard::{self, OutsideGuard, RefWithinGuard};
2828
use crate::builder::expr::as_place::PlaceBuilder;
2929
use crate::builder::matches::buckets::PartitionedCandidates;
3030
use crate::builder::matches::user_ty::ProjectedUserTypesNode;
31-
use crate::builder::scope::{DropKind, LintLevel};
31+
use crate::builder::scope::LintLevel;
3232
use crate::builder::{
3333
BlockAnd, BlockAndExtension, Builder, GuardFrame, GuardFrameLocal, LocalsForNode,
3434
};
@@ -791,7 +791,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
791791
if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id)
792792
&& matches!(schedule_drop, ScheduleDrops::Yes)
793793
{
794-
self.schedule_drop(span, region_scope, local_id, DropKind::Storage);
794+
self.schedule_drop_storage(span, region_scope, local_id);
795795
}
796796
let local_info = self.local_decls[local_id].local_info.as_mut().unwrap_crate_local();
797797
if let LocalInfo::User(BindingForm::Var(var_info)) = &mut **local_info {
@@ -808,7 +808,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
808808
) {
809809
let local_id = self.var_local_id(var, for_guard);
810810
if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id) {
811-
self.schedule_drop(span, region_scope, local_id, DropKind::Value);
811+
self.schedule_drop_value(span, region_scope, local_id);
812812
}
813813
}
814814

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_middle::{bug, span_bug};
4242
use rustc_span::{Span, Symbol};
4343

4444
use crate::builder::expr::as_place::PlaceBuilder;
45-
use crate::builder::scope::{DropKind, LintLevel};
45+
use crate::builder::scope::LintLevel;
4646

4747
pub(crate) fn closure_saved_names_of_captured_variables<'tcx>(
4848
tcx: TyCtxt<'tcx>,
@@ -955,11 +955,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
955955
let place = Place::from(local);
956956

957957
// Make sure we drop (parts of) the argument even when not matched on.
958-
self.schedule_drop(
958+
self.schedule_drop_value(
959959
param.pat.as_ref().map_or(expr_span, |pat| pat.span),
960960
argument_scope,
961961
local,
962-
DropKind::Value,
963962
);
964963

965964
let Some(ref pat) = param.pat else {

0 commit comments

Comments
 (0)