Skip to content

Commit d31386a

Browse files
committed
Make is_block_tail a variant of LocalInfo.
1 parent bcb161d commit d31386a

File tree

6 files changed

+26
-39
lines changed

6 files changed

+26
-39
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_hir::intravisit::Visitor;
66
use rustc_index::vec::IndexVec;
77
use rustc_infer::infer::NllRegionVariableOrigin;
88
use rustc_middle::mir::{
9-
Body, CastKind, ConstraintCategory, FakeReadCause, Local, Location, Operand, Place, Rvalue,
10-
Statement, StatementKind, TerminatorKind,
9+
Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place,
10+
Rvalue, Statement, StatementKind, TerminatorKind,
1111
};
1212
use rustc_middle::ty::adjustment::PointerCast;
1313
use rustc_middle::ty::{self, RegionVid, TyCtxt};
@@ -220,7 +220,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
220220
);
221221
err.span_label(body.source_info(drop_loc).span, message);
222222

223-
if let Some(info) = &local_decl.is_block_tail {
223+
if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
224224
if info.tail_result_is_ignored {
225225
// #85581: If the first mutable borrow's scope contains
226226
// the second borrow, this suggestion isn't helpful.

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -785,13 +785,6 @@ pub struct LocalDecl<'tcx> {
785785
/// generator.
786786
pub internal: bool,
787787

788-
/// If this local is a temporary and `is_block_tail` is `Some`,
789-
/// then it is a temporary created for evaluation of some
790-
/// subexpression of some block's tail expression (with no
791-
/// intervening statement context).
792-
// FIXME(matthewjasper) Don't store in this in `Body`
793-
pub is_block_tail: Option<BlockTailInfo>,
794-
795788
/// The type of this local.
796789
pub ty: Ty<'tcx>,
797790

@@ -905,6 +898,10 @@ pub enum LocalInfo<'tcx> {
905898
/// A temporary created during the creation of an aggregate
906899
/// (e.g. a temporary for `foo` in `MyStruct { my_field: foo }`)
907900
AggregateTemp,
901+
/// A temporary created for evaluation of some subexpression of some block's tail expression
902+
/// (with no intervening statement context).
903+
// FIXME(matthewjasper) Don't store in this in `Body`
904+
BlockTailTemp(BlockTailInfo),
908905
/// A temporary created during the pass `Derefer` to avoid it's retagging
909906
DerefTemp,
910907
/// A temporary created for borrow checking.
@@ -1018,7 +1015,6 @@ impl<'tcx> LocalDecl<'tcx> {
10181015
mutability: Mutability::Mut,
10191016
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::Boring)),
10201017
internal: false,
1021-
is_block_tail: None,
10221018
ty,
10231019
user_ty: None,
10241020
source_info,
@@ -1038,14 +1034,6 @@ impl<'tcx> LocalDecl<'tcx> {
10381034
self.mutability = Mutability::Not;
10391035
self
10401036
}
1041-
1042-
/// Converts `self` into same `LocalDecl` except tagged as internal temporary.
1043-
#[inline]
1044-
pub fn block_tail(mut self, info: BlockTailInfo) -> Self {
1045-
assert!(self.is_block_tail.is_none());
1046-
self.is_block_tail = Some(info);
1047-
self
1048-
}
10491037
}
10501038

10511039
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
@@ -3106,7 +3094,7 @@ mod size_asserts {
31063094
use rustc_data_structures::static_assert_size;
31073095
// tidy-alphabetical-start
31083096
static_assert_size!(BasicBlockData<'_>, 144);
3109-
static_assert_size!(LocalDecl<'_>, 56);
3097+
static_assert_size!(LocalDecl<'_>, 40);
31103098
static_assert_size!(Statement<'_>, 32);
31113099
static_assert_size!(StatementKind<'_>, 16);
31123100
static_assert_size!(Terminator<'_>, 112);

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,6 @@ macro_rules! make_mir_visitor {
804804
source_info,
805805
internal: _,
806806
local_info: _,
807-
is_block_tail: _,
808807
} = local_decl;
809808

810809
self.visit_ty($(& $mutability)? *ty, TyContext::LocalDecl {

compiler/rustc_mir_build/src/build/expr/as_operand.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
124124
}
125125
Category::Constant | Category::Place | Category::Rvalue(..) => {
126126
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
127-
let decl_info = this.local_decls[operand].local_info.as_mut().assert_crate_local();
128-
if let LocalInfo::Boring = **decl_info {
129-
**decl_info = local_info;
127+
// Overwrite temp local info if we have something more interesting to record.
128+
if !matches!(local_info, LocalInfo::Boring) {
129+
let decl_info = this.local_decls[operand].local_info.as_mut().assert_crate_local();
130+
if let LocalInfo::Boring | LocalInfo::BlockTailTemp(_) = **decl_info {
131+
**decl_info = local_info;
132+
}
130133
}
131134
block.and(Operand::Move(Place::from(operand)))
132135
}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4949
}
5050

5151
debug!("creating temp {:?} with block_context: {:?}", local_decl, this.block_context);
52-
// Find out whether this temp is being created within the
53-
// tail expression of a block whose result is ignored.
54-
if let Some(tail_info) = this.block_context.currently_in_block_tail() {
55-
local_decl = local_decl.block_tail(tail_info);
56-
}
57-
match expr.kind {
52+
let local_info = match expr.kind {
5853
ExprKind::StaticRef { def_id, .. } => {
5954
assert!(!this.tcx.is_thread_local_static(def_id));
6055
local_decl.internal = true;
61-
**local_decl.local_info.as_mut().assert_crate_local() =
62-
LocalInfo::StaticRef { def_id, is_thread_local: false };
56+
LocalInfo::StaticRef { def_id, is_thread_local: false }
6357
}
6458
ExprKind::ThreadLocalRef(def_id) => {
6559
assert!(this.tcx.is_thread_local_static(def_id));
6660
local_decl.internal = true;
67-
**local_decl.local_info.as_mut().assert_crate_local() =
68-
LocalInfo::StaticRef { def_id, is_thread_local: true };
61+
LocalInfo::StaticRef { def_id, is_thread_local: true }
6962
}
7063
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {
71-
**local_decl.local_info.as_mut().assert_crate_local() = LocalInfo::ConstRef { def_id };
64+
LocalInfo::ConstRef { def_id }
7265
}
73-
_ => {}
74-
}
66+
// Find out whether this temp is being created within the
67+
// tail expression of a block whose result is ignored.
68+
_ if let Some(tail_info) = this.block_context.currently_in_block_tail() => {
69+
LocalInfo::BlockTailTemp(tail_info)
70+
}
71+
_ => LocalInfo::Boring,
72+
};
73+
**local_decl.local_info.as_mut().assert_crate_local() = local_info;
7574
this.local_decls.push(local_decl)
7675
};
7776
let temp_place = Place::from(temp);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22242224
user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) },
22252225
source_info,
22262226
internal: false,
2227-
is_block_tail: None,
22282227
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var(
22292228
VarBindingForm {
22302229
binding_mode,
@@ -2253,7 +2252,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22532252
user_ty: None,
22542253
source_info,
22552254
internal: false,
2256-
is_block_tail: None,
22572255
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::RefForGuard))),
22582256
});
22592257
self.var_debug_info.push(VarDebugInfo {

0 commit comments

Comments
 (0)