Skip to content

Commit 511364e

Browse files
committedMar 16, 2023
Auto merge of #108944 - cjgillot:clear-local-info, r=oli-obk
Wrap the whole LocalInfo in ClearCrossCrate. MIR contains a lot of information about locals. The primary purpose of this information is the quality of borrowck diagnostics. This PR aims to drop this information after MIR analyses are finished, ie. starting from post-cleanup runtime MIR.
2 parents e386217 + 2adf2cd commit 511364e

File tree

30 files changed

+188
-214
lines changed

30 files changed

+188
-214
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -1985,16 +1985,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19851985
let (place_desc, note) = if let Some(place_desc) = opt_place_desc {
19861986
let local_kind = if let Some(local) = borrow.borrowed_place.as_local() {
19871987
match self.body.local_kind(local) {
1988-
LocalKind::ReturnPointer | LocalKind::Temp => {
1989-
bug!("temporary or return pointer with a name")
1988+
LocalKind::Temp if self.body.local_decls[local].is_user_variable() => {
1989+
"local variable "
19901990
}
1991-
LocalKind::Var => "local variable ",
19921991
LocalKind::Arg
19931992
if !self.upvars.is_empty() && local == ty::CAPTURE_STRUCT_LOCAL =>
19941993
{
19951994
"variable captured by `move` "
19961995
}
19971996
LocalKind::Arg => "function parameter ",
1997+
LocalKind::ReturnPointer | LocalKind::Temp => {
1998+
bug!("temporary or return pointer with a name")
1999+
}
19982000
}
19992001
} else {
20002002
"local data "
@@ -2008,16 +2010,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20082010
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
20092011
let local = root_place.local;
20102012
match self.body.local_kind(local) {
2011-
LocalKind::ReturnPointer | LocalKind::Temp => {
2012-
("temporary value".to_string(), "temporary value created here".to_string())
2013-
}
20142013
LocalKind::Arg => (
20152014
"function parameter".to_string(),
20162015
"function parameter borrowed here".to_string(),
20172016
),
2018-
LocalKind::Var => {
2017+
LocalKind::Temp if self.body.local_decls[local].is_user_variable() => {
20192018
("local binding".to_string(), "local binding introduced here".to_string())
20202019
}
2020+
LocalKind::ReturnPointer | LocalKind::Temp => {
2021+
("temporary value".to_string(), "temporary value created here".to_string())
2022+
}
20212023
}
20222024
};
20232025

@@ -2482,15 +2484,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24822484
let (place_description, assigned_span) = match local_decl {
24832485
Some(LocalDecl {
24842486
local_info:
2485-
Some(box LocalInfo::User(
2486-
ClearCrossCrate::Clear
2487-
| ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
2487+
ClearCrossCrate::Set(
2488+
box LocalInfo::User(BindingForm::Var(VarBindingForm {
24882489
opt_match_place: None,
24892490
..
2490-
})),
2491-
))
2492-
| Some(box LocalInfo::StaticRef { .. })
2493-
| None,
2491+
}))
2492+
| box LocalInfo::StaticRef { .. }
2493+
| box LocalInfo::Boring,
2494+
),
24942495
..
24952496
})
24962497
| None => (self.describe_any_place(place.as_ref()), assigned_span),

‎compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+3-3
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_borrowck/src/diagnostics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
196196
if self.body.local_decls[local].is_ref_for_guard() {
197197
continue;
198198
}
199-
if let Some(box LocalInfo::StaticRef { def_id, .. }) =
200-
&self.body.local_decls[local].local_info
199+
if let LocalInfo::StaticRef { def_id, .. } =
200+
*self.body.local_decls[local].local_info()
201201
{
202-
buf.push_str(self.infcx.tcx.item_name(*def_id).as_str());
202+
buf.push_str(self.infcx.tcx.item_name(def_id).as_str());
203203
ok = Ok(());
204204
continue;
205205
}

‎compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
102102
//
103103
// opt_match_place is None for let [mut] x = ... statements,
104104
// whether or not the right-hand side is a place expression
105-
if let Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
106-
VarBindingForm {
107-
opt_match_place: Some((opt_match_place, match_span)),
108-
binding_mode: _,
109-
opt_ty_info: _,
110-
pat_span: _,
111-
},
112-
)))) = local_decl.local_info
105+
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
106+
opt_match_place: Some((opt_match_place, match_span)),
107+
binding_mode: _,
108+
opt_ty_info: _,
109+
pat_span: _,
110+
})) = *local_decl.local_info()
113111
{
114112
let stmt_source_info = self.body.source_info(location);
115113
self.append_binding_error(
@@ -478,9 +476,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
478476
let mut suggestions: Vec<(Span, String, String)> = Vec::new();
479477
for local in binds_to {
480478
let bind_to = &self.body.local_decls[*local];
481-
if let Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
482-
VarBindingForm { pat_span, .. },
483-
)))) = bind_to.local_info
479+
if let LocalInfo::User(BindingForm::Var(VarBindingForm { pat_span, .. })) =
480+
*bind_to.local_info()
484481
{
485482
let Ok(pat_snippet) =
486483
self.infcx.tcx.sess.source_map().span_to_snippet(pat_span) else { continue; };

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+38-54
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
77
use rustc_middle::ty::{self, Ty, TyCtxt};
88
use rustc_middle::{
99
hir::place::PlaceBase,
10-
mir::{self, BindingForm, ClearCrossCrate, Local, LocalDecl, LocalInfo, LocalKind, Location},
10+
mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location},
1111
};
1212
use rustc_span::source_map::DesugaringKind;
1313
use rustc_span::symbol::{kw, Symbol};
@@ -105,8 +105,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
105105
reason = String::new();
106106
} else {
107107
item_msg = access_place_desc;
108-
let local_info = &self.body.local_decls[local].local_info;
109-
if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info {
108+
let local_info = self.body.local_decls[local].local_info();
109+
if let LocalInfo::StaticRef { def_id, .. } = *local_info {
110110
let static_name = &self.infcx.tcx.item_name(def_id);
111111
reason = format!(", as `{static_name}` is an immutable static item");
112112
} else {
@@ -305,15 +305,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
305305
..
306306
}) = &self.body[location.block].statements.get(location.statement_index)
307307
{
308-
match decl.local_info {
309-
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
310-
mir::VarBindingForm {
311-
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
312-
opt_ty_info: Some(sp),
313-
opt_match_place: _,
314-
pat_span: _,
315-
},
316-
)))) => {
308+
match *decl.local_info() {
309+
LocalInfo::User(BindingForm::Var(mir::VarBindingForm {
310+
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
311+
opt_ty_info: Some(sp),
312+
opt_match_place: _,
313+
pat_span: _,
314+
})) => {
317315
if suggest {
318316
err.span_note(sp, "the binding is already a mutable borrow");
319317
}
@@ -346,10 +344,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
346344
}
347345
} else if decl.mutability.is_not() {
348346
if matches!(
349-
decl.local_info,
350-
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
351-
hir::ImplicitSelfKind::MutRef
352-
),)))
347+
decl.local_info(),
348+
LocalInfo::User(BindingForm::ImplicitSelf(hir::ImplicitSelfKind::MutRef))
353349
) {
354350
err.note(
355351
"as `Self` may be unsized, this call attempts to take `&mut &mut self`",
@@ -482,22 +478,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
482478

483479
match self.local_names[local] {
484480
Some(name) if !local_decl.from_compiler_desugaring() => {
485-
let label = match local_decl.local_info.as_deref().unwrap() {
486-
LocalInfo::User(ClearCrossCrate::Set(
487-
mir::BindingForm::ImplicitSelf(_),
488-
)) => {
481+
let label = match *local_decl.local_info() {
482+
LocalInfo::User(mir::BindingForm::ImplicitSelf(_)) => {
489483
let (span, suggestion) =
490484
suggest_ampmut_self(self.infcx.tcx, local_decl);
491485
Some((true, span, suggestion))
492486
}
493487

494-
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
495-
mir::VarBindingForm {
496-
binding_mode: ty::BindingMode::BindByValue(_),
497-
opt_ty_info,
498-
..
499-
},
500-
))) => {
488+
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
489+
binding_mode: ty::BindingMode::BindByValue(_),
490+
opt_ty_info,
491+
..
492+
})) => {
501493
// check if the RHS is from desugaring
502494
let opt_assignment_rhs_span =
503495
self.body.find_assignments(local).first().map(|&location| {
@@ -534,16 +526,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
534526
self.infcx.tcx,
535527
local_decl,
536528
opt_assignment_rhs_span,
537-
*opt_ty_info,
529+
opt_ty_info,
538530
)
539531
} else {
540-
match local_decl.local_info.as_deref() {
541-
Some(LocalInfo::User(ClearCrossCrate::Set(
542-
mir::BindingForm::Var(mir::VarBindingForm {
543-
opt_ty_info: None,
544-
..
545-
}),
546-
))) => {
532+
match local_decl.local_info() {
533+
LocalInfo::User(mir::BindingForm::Var(
534+
mir::VarBindingForm {
535+
opt_ty_info: None, ..
536+
},
537+
)) => {
547538
let (span, sugg) = suggest_ampmut_self(
548539
self.infcx.tcx,
549540
local_decl,
@@ -555,7 +546,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
555546
self.infcx.tcx,
556547
local_decl,
557548
opt_assignment_rhs_span,
558-
*opt_ty_info,
549+
opt_ty_info,
559550
),
560551
}
561552
};
@@ -564,21 +555,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
564555
}
565556
}
566557

567-
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
568-
mir::VarBindingForm {
569-
binding_mode: ty::BindingMode::BindByReference(_),
570-
..
571-
},
572-
))) => {
558+
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
559+
binding_mode: ty::BindingMode::BindByReference(_),
560+
..
561+
})) => {
573562
let pattern_span = local_decl.source_info.span;
574563
suggest_ref_mut(self.infcx.tcx, pattern_span)
575564
.map(|replacement| (true, pattern_span, replacement))
576565
}
577566

578-
LocalInfo::User(ClearCrossCrate::Clear) => {
579-
bug!("saw cleared local state")
580-
}
581-
582567
_ => unreachable!(),
583568
};
584569

@@ -1151,20 +1136,19 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11511136
pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {
11521137
debug!("local_info: {:?}, ty.kind(): {:?}", local_decl.local_info, local_decl.ty.kind());
11531138

1154-
match local_decl.local_info.as_deref() {
1139+
match *local_decl.local_info() {
11551140
// Check if mutably borrowing a mutable reference.
1156-
Some(LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
1157-
mir::VarBindingForm {
1158-
binding_mode: ty::BindingMode::BindByValue(Mutability::Not), ..
1159-
},
1160-
)))) => matches!(local_decl.ty.kind(), ty::Ref(_, _, hir::Mutability::Mut)),
1161-
Some(LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::ImplicitSelf(kind)))) => {
1141+
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
1142+
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
1143+
..
1144+
})) => matches!(local_decl.ty.kind(), ty::Ref(_, _, hir::Mutability::Mut)),
1145+
LocalInfo::User(mir::BindingForm::ImplicitSelf(kind)) => {
11621146
// Check if the user variable is a `&mut self` and we can therefore
11631147
// suggest removing the `&mut`.
11641148
//
11651149
// Deliberately fall into this case for all implicit self types,
11661150
// so that we don't fall in to the next case with them.
1167-
*kind == hir::ImplicitSelfKind::MutRef
1151+
kind == hir::ImplicitSelfKind::MutRef
11681152
}
11691153
_ if Some(kw::SelfLower) == local_name => {
11701154
// Otherwise, check if the name is the `self` keyword - in which case

‎compiler/rustc_borrowck/src/type_check/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1180,10 +1180,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11801180
}
11811181
}
11821182
Some(l)
1183-
if matches!(
1184-
body.local_decls[l].local_info,
1185-
Some(box LocalInfo::AggregateTemp)
1186-
) =>
1183+
if matches!(body.local_decls[l].local_info(), LocalInfo::AggregateTemp) =>
11871184
{
11881185
ConstraintCategory::Usage
11891186
}
@@ -1684,7 +1681,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16841681
// - maybe we should make that a warning.
16851682
return;
16861683
}
1687-
LocalKind::Var | LocalKind::Temp => {}
1684+
LocalKind::Temp => {}
16881685
}
16891686

16901687
// When `unsized_fn_params` or `unsized_locals` is enabled, only function calls

‎compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
241241
pub fn debug_introduce_local(&self, bx: &mut Bx, local: mir::Local) {
242242
let full_debug_info = bx.sess().opts.debuginfo == DebugInfo::Full;
243243

244-
// FIXME(eddyb) maybe name the return place as `_0` or `return`?
245-
if local == mir::RETURN_PLACE && !self.mir.local_decls[mir::RETURN_PLACE].is_user_variable()
246-
{
247-
return;
248-
}
249-
250244
let vars = match &self.per_local_var_debug_info {
251245
Some(per_local) => &per_local[local],
252246
None => return,
@@ -303,7 +297,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
303297

304298
let local_ref = &self.locals[local];
305299

306-
let name = if bx.sess().fewer_names() {
300+
// FIXME Should the return place be named?
301+
let name = if bx.sess().fewer_names() || local == mir::RETURN_PLACE {
307302
None
308303
} else {
309304
Some(match whole_local_var.or(fallback_var.clone()) {

‎compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
643643
if base_ty.is_unsafe_ptr() {
644644
if proj_base.is_empty() {
645645
let decl = &self.body.local_decls[place_local];
646-
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
646+
if let LocalInfo::StaticRef { def_id, .. } = *decl.local_info() {
647647
let span = decl.source_info.span;
648648
self.check_static(def_id, span);
649649
return;

‎compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ pub mod ty {
704704

705705
fn importance(&self) -> DiagnosticImportance {
706706
match self.0 {
707-
mir::LocalKind::Var | mir::LocalKind::Temp => DiagnosticImportance::Secondary,
707+
mir::LocalKind::Temp => DiagnosticImportance::Secondary,
708708
mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => {
709709
DiagnosticImportance::Primary
710710
}

‎compiler/rustc_const_eval/src/transform/promote_consts.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
106106
debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location);
107107
// We're only interested in temporaries and the return place
108108
match self.ccx.body.local_kind(index) {
109-
LocalKind::Temp | LocalKind::ReturnPointer => {}
110-
LocalKind::Arg | LocalKind::Var => return,
109+
LocalKind::Arg => return,
110+
LocalKind::Temp if self.ccx.body.local_decls[index].is_user_variable() => return,
111+
LocalKind::ReturnPointer | LocalKind::Temp => {}
111112
}
112113

113114
// Ignore drops, if the temp gets promoted,

‎compiler/rustc_middle/src/mir/mod.rs

+35-41
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,6 @@ impl<'tcx> Body<'tcx> {
401401
LocalKind::ReturnPointer
402402
} else if index < self.arg_count + 1 {
403403
LocalKind::Arg
404-
} else if self.local_decls[local].is_user_variable() {
405-
LocalKind::Var
406404
} else {
407405
LocalKind::Temp
408406
}
@@ -572,6 +570,13 @@ impl<T> ClearCrossCrate<T> {
572570
}
573571
}
574572

573+
pub fn as_mut(&mut self) -> ClearCrossCrate<&mut T> {
574+
match self {
575+
ClearCrossCrate::Clear => ClearCrossCrate::Clear,
576+
ClearCrossCrate::Set(v) => ClearCrossCrate::Set(v),
577+
}
578+
}
579+
575580
pub fn assert_crate_local(self) -> T {
576581
match self {
577582
ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"),
@@ -661,9 +666,7 @@ impl Atom for Local {
661666
/// Classifies locals into categories. See `Body::local_kind`.
662667
#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable)]
663668
pub enum LocalKind {
664-
/// User-declared variable binding.
665-
Var,
666-
/// Compiler-introduced temporary.
669+
/// User-declared variable binding or compiler-introduced temporary.
667670
Temp,
668671
/// Function argument.
669672
Arg,
@@ -760,7 +763,7 @@ pub struct LocalDecl<'tcx> {
760763
pub mutability: Mutability,
761764

762765
// FIXME(matthewjasper) Don't store in this in `Body`
763-
pub local_info: Option<Box<LocalInfo<'tcx>>>,
766+
pub local_info: ClearCrossCrate<Box<LocalInfo<'tcx>>>,
764767

765768
/// `true` if this is an internal local.
766769
///
@@ -778,13 +781,6 @@ pub struct LocalDecl<'tcx> {
778781
/// generator.
779782
pub internal: bool,
780783

781-
/// If this local is a temporary and `is_block_tail` is `Some`,
782-
/// then it is a temporary created for evaluation of some
783-
/// subexpression of some block's tail expression (with no
784-
/// intervening statement context).
785-
// FIXME(matthewjasper) Don't store in this in `Body`
786-
pub is_block_tail: Option<BlockTailInfo>,
787-
788784
/// The type of this local.
789785
pub ty: Ty<'tcx>,
790786

@@ -890,21 +886,31 @@ pub enum LocalInfo<'tcx> {
890886
/// The `BindingForm` is solely used for local diagnostics when generating
891887
/// warnings/errors when compiling the current crate, and therefore it need
892888
/// not be visible across crates.
893-
User(ClearCrossCrate<BindingForm<'tcx>>),
889+
User(BindingForm<'tcx>),
894890
/// A temporary created that references the static with the given `DefId`.
895891
StaticRef { def_id: DefId, is_thread_local: bool },
896892
/// A temporary created that references the const with the given `DefId`
897893
ConstRef { def_id: DefId },
898894
/// A temporary created during the creation of an aggregate
899895
/// (e.g. a temporary for `foo` in `MyStruct { my_field: foo }`)
900896
AggregateTemp,
897+
/// A temporary created for evaluation of some subexpression of some block's tail expression
898+
/// (with no intervening statement context).
899+
// FIXME(matthewjasper) Don't store in this in `Body`
900+
BlockTailTemp(BlockTailInfo),
901901
/// A temporary created during the pass `Derefer` to avoid it's retagging
902902
DerefTemp,
903903
/// A temporary created for borrow checking.
904904
FakeBorrow,
905+
/// A local without anything interesting about it.
906+
Boring,
905907
}
906908

907909
impl<'tcx> LocalDecl<'tcx> {
910+
pub fn local_info(&self) -> &LocalInfo<'tcx> {
911+
&**self.local_info.as_ref().assert_crate_local()
912+
}
913+
908914
/// Returns `true` only if local is a binding that can itself be
909915
/// made mutable via the addition of the `mut` keyword, namely
910916
/// something like the occurrences of `x` in:
@@ -913,15 +919,15 @@ impl<'tcx> LocalDecl<'tcx> {
913919
/// - or `match ... { C(x) => ... }`
914920
pub fn can_be_made_mutable(&self) -> bool {
915921
matches!(
916-
self.local_info,
917-
Some(box LocalInfo::User(ClearCrossCrate::Set(
922+
self.local_info(),
923+
LocalInfo::User(
918924
BindingForm::Var(VarBindingForm {
919925
binding_mode: ty::BindingMode::BindByValue(_),
920926
opt_ty_info: _,
921927
opt_match_place: _,
922928
pat_span: _,
923929
}) | BindingForm::ImplicitSelf(ImplicitSelfKind::Imm),
924-
)))
930+
)
925931
)
926932
}
927933

@@ -930,54 +936,51 @@ impl<'tcx> LocalDecl<'tcx> {
930936
/// mutable bindings, but the inverse does not necessarily hold).
931937
pub fn is_nonref_binding(&self) -> bool {
932938
matches!(
933-
self.local_info,
934-
Some(box LocalInfo::User(ClearCrossCrate::Set(
939+
self.local_info(),
940+
LocalInfo::User(
935941
BindingForm::Var(VarBindingForm {
936942
binding_mode: ty::BindingMode::BindByValue(_),
937943
opt_ty_info: _,
938944
opt_match_place: _,
939945
pat_span: _,
940946
}) | BindingForm::ImplicitSelf(_),
941-
)))
947+
)
942948
)
943949
}
944950

945951
/// Returns `true` if this variable is a named variable or function
946952
/// parameter declared by the user.
947953
#[inline]
948954
pub fn is_user_variable(&self) -> bool {
949-
matches!(self.local_info, Some(box LocalInfo::User(_)))
955+
matches!(self.local_info(), LocalInfo::User(_))
950956
}
951957

952958
/// Returns `true` if this is a reference to a variable bound in a `match`
953959
/// expression that is used to access said variable for the guard of the
954960
/// match arm.
955961
pub fn is_ref_for_guard(&self) -> bool {
956-
matches!(
957-
self.local_info,
958-
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::RefForGuard)))
959-
)
962+
matches!(self.local_info(), LocalInfo::User(BindingForm::RefForGuard))
960963
}
961964

962965
/// Returns `Some` if this is a reference to a static item that is used to
963966
/// access that static.
964967
pub fn is_ref_to_static(&self) -> bool {
965-
matches!(self.local_info, Some(box LocalInfo::StaticRef { .. }))
968+
matches!(self.local_info(), LocalInfo::StaticRef { .. })
966969
}
967970

968971
/// Returns `Some` if this is a reference to a thread-local static item that is used to
969972
/// access that static.
970973
pub fn is_ref_to_thread_local(&self) -> bool {
971-
match self.local_info {
972-
Some(box LocalInfo::StaticRef { is_thread_local, .. }) => is_thread_local,
974+
match self.local_info() {
975+
LocalInfo::StaticRef { is_thread_local, .. } => *is_thread_local,
973976
_ => false,
974977
}
975978
}
976979

977980
/// Returns `true` if this is a DerefTemp
978981
pub fn is_deref_temp(&self) -> bool {
979-
match self.local_info {
980-
Some(box LocalInfo::DerefTemp) => return true,
982+
match self.local_info() {
983+
LocalInfo::DerefTemp => return true,
981984
_ => (),
982985
}
983986
return false;
@@ -1001,9 +1004,8 @@ impl<'tcx> LocalDecl<'tcx> {
10011004
pub fn with_source_info(ty: Ty<'tcx>, source_info: SourceInfo) -> Self {
10021005
LocalDecl {
10031006
mutability: Mutability::Mut,
1004-
local_info: None,
1007+
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::Boring)),
10051008
internal: false,
1006-
is_block_tail: None,
10071009
ty,
10081010
user_ty: None,
10091011
source_info,
@@ -1023,14 +1025,6 @@ impl<'tcx> LocalDecl<'tcx> {
10231025
self.mutability = Mutability::Not;
10241026
self
10251027
}
1026-
1027-
/// Converts `self` into same `LocalDecl` except tagged as internal temporary.
1028-
#[inline]
1029-
pub fn block_tail(mut self, info: BlockTailInfo) -> Self {
1030-
assert!(self.is_block_tail.is_none());
1031-
self.is_block_tail = Some(info);
1032-
self
1033-
}
10341028
}
10351029

10361030
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
@@ -3091,7 +3085,7 @@ mod size_asserts {
30913085
use rustc_data_structures::static_assert_size;
30923086
// tidy-alphabetical-start
30933087
static_assert_size!(BasicBlockData<'_>, 144);
3094-
static_assert_size!(LocalDecl<'_>, 56);
3088+
static_assert_size!(LocalDecl<'_>, 40);
30953089
static_assert_size!(Statement<'_>, 32);
30963090
static_assert_size!(StatementKind<'_>, 16);
30973091
static_assert_size!(Terminator<'_>, 112);

‎compiler/rustc_middle/src/mir/patch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ impl<'tcx> MirPatch<'tcx> {
7272
&mut self,
7373
ty: Ty<'tcx>,
7474
span: Span,
75-
local_info: Option<Box<LocalInfo<'tcx>>>,
75+
local_info: LocalInfo<'tcx>,
7676
) -> Local {
7777
let index = self.next_local;
7878
self.next_local += 1;
7979
let mut new_decl = LocalDecl::new(ty, span).internal();
80-
new_decl.local_info = local_info;
80+
**new_decl.local_info.as_mut().assert_crate_local() = local_info;
8181
self.new_locals.push(new_decl);
8282
Local::new(index as usize)
8383
}

‎compiler/rustc_middle/src/mir/visit.rs

-1
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

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2020
expr: &Expr<'tcx>,
2121
) -> BlockAnd<Operand<'tcx>> {
2222
let local_scope = self.local_scope();
23-
self.as_operand(block, Some(local_scope), expr, None, NeedsTemporary::Maybe)
23+
self.as_operand(block, Some(local_scope), expr, LocalInfo::Boring, NeedsTemporary::Maybe)
2424
}
2525

2626
/// Returns an operand suitable for use until the end of the current scope expression and
@@ -102,7 +102,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
102102
mut block: BasicBlock,
103103
scope: Option<region::Scope>,
104104
expr: &Expr<'tcx>,
105-
local_info: Option<Box<LocalInfo<'tcx>>>,
105+
local_info: LocalInfo<'tcx>,
106106
needs_temporary: NeedsTemporary,
107107
) -> BlockAnd<Operand<'tcx>> {
108108
let this = self;
@@ -124,8 +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-
if this.local_decls[operand].local_info.is_none() {
128-
this.local_decls[operand].local_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+
}
129133
}
130134
block.and(Operand::Move(Place::from(operand)))
131135
}
@@ -178,6 +182,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178182
}
179183
}
180184

181-
this.as_operand(block, scope, expr, None, NeedsTemporary::Maybe)
185+
this.as_operand(block, scope, expr, LocalInfo::Boring, NeedsTemporary::Maybe)
182186
}
183187
}

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6464
block,
6565
scope,
6666
&this.thir[value],
67-
None,
67+
LocalInfo::Boring,
6868
NeedsTemporary::No
6969
)
7070
);
@@ -74,18 +74,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7474
ExprKind::Binary { op, lhs, rhs } => {
7575
let lhs = unpack!(
7676
block =
77-
this.as_operand(block, scope, &this.thir[lhs], None, NeedsTemporary::Maybe)
77+
this.as_operand(block, scope, &this.thir[lhs], LocalInfo::Boring, NeedsTemporary::Maybe)
7878
);
7979
let rhs = unpack!(
8080
block =
81-
this.as_operand(block, scope, &this.thir[rhs], None, NeedsTemporary::No)
81+
this.as_operand(block, scope, &this.thir[rhs], LocalInfo::Boring, NeedsTemporary::No)
8282
);
8383
this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs)
8484
}
8585
ExprKind::Unary { op, arg } => {
8686
let arg = unpack!(
8787
block =
88-
this.as_operand(block, scope, &this.thir[arg], None, NeedsTemporary::No)
88+
this.as_operand(block, scope, &this.thir[arg], LocalInfo::Boring, NeedsTemporary::No)
8989
);
9090
// Check for -MIN on signed integers
9191
if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() {
@@ -260,7 +260,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
260260
} else {
261261
let ty = source.ty;
262262
let source = unpack!(
263-
block = this.as_operand(block, scope, source, None, NeedsTemporary::No)
263+
block = this.as_operand(block, scope, source, LocalInfo::Boring, NeedsTemporary::No)
264264
);
265265
(source, ty)
266266
};
@@ -273,7 +273,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
273273
ExprKind::Pointer { cast, source } => {
274274
let source = unpack!(
275275
block =
276-
this.as_operand(block, scope, &this.thir[source], None, NeedsTemporary::No)
276+
this.as_operand(block, scope, &this.thir[source], LocalInfo::Boring, NeedsTemporary::No)
277277
);
278278
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
279279
}
@@ -315,7 +315,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
315315
block,
316316
scope,
317317
&this.thir[f],
318-
None,
318+
LocalInfo::Boring,
319319
NeedsTemporary::Maybe
320320
)
321321
)
@@ -336,7 +336,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
336336
block,
337337
scope,
338338
&this.thir[f],
339-
None,
339+
LocalInfo::Boring,
340340
NeedsTemporary::Maybe
341341
)
342342
)
@@ -424,7 +424,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
424424
block,
425425
scope,
426426
upvar,
427-
None,
427+
LocalInfo::Boring,
428428
NeedsTemporary::Maybe
429429
)
430430
)
@@ -503,7 +503,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
503503
Some(Category::Rvalue(RvalueFunc::AsRvalue) | Category::Constant)
504504
));
505505
let operand =
506-
unpack!(block = this.as_operand(block, scope, expr, None, NeedsTemporary::No));
506+
unpack!(block = this.as_operand(block, scope, expr, LocalInfo::Boring, NeedsTemporary::No));
507507
block.and(Rvalue::Use(operand))
508508
}
509509
}
@@ -663,7 +663,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
663663
} else {
664664
// For a non-const, we may need to generate an appropriate `Drop`
665665
let value_operand =
666-
unpack!(block = this.as_operand(block, scope, value, None, NeedsTemporary::No));
666+
unpack!(block = this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No));
667667
if let Operand::Move(to_drop) = value_operand {
668668
let success = this.cfg.start_new_block();
669669
this.cfg.terminate(

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

+12-13
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 =
62-
Some(Box::new(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 =
68-
Some(Box::new(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 = Some(Box::new(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/expr/into.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
328328
let fields_map: FxHashMap<_, _> = fields
329329
.into_iter()
330330
.map(|f| {
331-
let local_info = Box::new(LocalInfo::AggregateTemp);
332331
(
333332
f.name,
334333
unpack!(
335334
block = this.as_operand(
336335
block,
337336
Some(scope),
338337
&this.thir[f.expr],
339-
Some(local_info),
338+
LocalInfo::AggregateTemp,
340339
NeedsTemporary::Maybe,
341340
)
342341
),
@@ -526,7 +525,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
526525
block,
527526
Some(scope),
528527
&this.thir[value],
529-
None,
528+
LocalInfo::Boring,
530529
NeedsTemporary::No
531530
)
532531
);

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

+6-10
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
607607
// };
608608
// ```
609609
if let Some(place) = initializer.try_to_place(self) {
610-
let Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
610+
let LocalInfo::User(BindingForm::Var(
611611
VarBindingForm { opt_match_place: Some((ref mut match_place, _)), .. },
612-
)))) = self.local_decls[local].local_info else {
612+
)) = **self.local_decls[local].local_info.as_mut().assert_crate_local() else {
613613
bug!("Let binding to non-user variable.")
614614
};
615615
*match_place = Some(place);
@@ -1754,7 +1754,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17541754
let fake_borrow_ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty);
17551755
let mut fake_borrow_temp = LocalDecl::new(fake_borrow_ty, temp_span);
17561756
fake_borrow_temp.internal = self.local_decls[matched_place.local].internal;
1757-
fake_borrow_temp.local_info = Some(Box::new(LocalInfo::FakeBorrow));
1757+
fake_borrow_temp.local_info = ClearCrossCrate::Set(Box::new(LocalInfo::FakeBorrow));
17581758
let fake_borrow_temp = self.local_decls.push(fake_borrow_temp);
17591759

17601760
(matched_place, fake_borrow_temp)
@@ -2224,8 +2224,7 @@ 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,
2228-
local_info: Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
2227+
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var(
22292228
VarBindingForm {
22302229
binding_mode,
22312230
// hypothetically, `visit_primary_bindings` could try to unzip
@@ -2236,7 +2235,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22362235
opt_match_place,
22372236
pat_span,
22382237
},
2239-
))))),
2238+
)))),
22402239
};
22412240
let for_arm_body = self.local_decls.push(local);
22422241
self.var_debug_info.push(VarDebugInfo {
@@ -2253,10 +2252,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22532252
user_ty: None,
22542253
source_info,
22552254
internal: false,
2256-
is_block_tail: None,
2257-
local_info: Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(
2258-
BindingForm::RefForGuard,
2259-
)))),
2255+
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::RefForGuard))),
22602256
});
22612257
self.var_debug_info.push(VarDebugInfo {
22622258
name,

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -876,20 +876,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
876876
} => {
877877
self.local_decls[local].mutability = mutability;
878878
self.local_decls[local].source_info.scope = self.source_scope;
879-
self.local_decls[local].local_info = if let Some(kind) = param.self_kind {
880-
Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(
879+
**self.local_decls[local].local_info.as_mut().assert_crate_local() = if let Some(kind) = param.self_kind {
880+
LocalInfo::User(
881881
BindingForm::ImplicitSelf(kind),
882-
))))
882+
)
883883
} else {
884884
let binding_mode = ty::BindingMode::BindByValue(mutability);
885-
Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
885+
LocalInfo::User(BindingForm::Var(
886886
VarBindingForm {
887887
binding_mode,
888888
opt_ty_info: param.ty_span,
889889
opt_match_place: Some((None, span)),
890890
pat_span: span,
891891
},
892-
)))))
892+
))
893893
};
894894
self.var_indices.insert(var, LocalsForNode::One(local));
895895
}

‎compiler/rustc_mir_transform/src/check_const_item_mutation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct ConstMutationChecker<'a, 'tcx> {
2424

2525
impl<'tcx> ConstMutationChecker<'_, 'tcx> {
2626
fn is_const_item(&self, local: Local) -> Option<DefId> {
27-
if let Some(box LocalInfo::ConstRef { def_id }) = self.body.local_decls[local].local_info {
27+
if let LocalInfo::ConstRef { def_id } = *self.body.local_decls[local].local_info() {
2828
Some(def_id)
2929
} else {
3030
None

‎compiler/rustc_mir_transform/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
182182
// If the projection root is an artificial local that we introduced when
183183
// desugaring `static`, give a more specific error message
184184
// (avoid the general "raw pointer" clause below, that would only be confusing).
185-
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
185+
if let LocalInfo::StaticRef { def_id, .. } = *decl.local_info() {
186186
if self.tcx.is_mutable_static(def_id) {
187187
self.require_unsafe(
188188
UnsafetyViolationKind::General,

‎compiler/rustc_mir_transform/src/deref_separator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
4040
let temp = self.patcher.new_internal_with_info(
4141
ty,
4242
self.local_decls[p_ref.local].source_info.span,
43-
Some(Box::new(LocalInfo::DerefTemp)),
43+
LocalInfo::DerefTemp,
4444
);
4545

4646
// We are adding current p_ref's projections to our

‎compiler/rustc_mir_transform/src/dest_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ impl<'tcx> Visitor<'tcx> for FindAssignments<'_, '_, 'tcx> {
788788
fn is_local_required(local: Local, body: &Body<'_>) -> bool {
789789
match body.local_kind(local) {
790790
LocalKind::Arg | LocalKind::ReturnPointer => true,
791-
LocalKind::Var | LocalKind::Temp => false,
791+
LocalKind::Temp => false,
792792
}
793793
}
794794

‎compiler/rustc_mir_transform/src/generator.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,19 @@ fn compute_layout<'tcx>(
924924
debug!(?decl);
925925

926926
let ignore_for_traits = if tcx.sess.opts.unstable_opts.drop_tracking_mir {
927+
// Do not `assert_crate_local` here, as post-borrowck cleanup may have already cleared
928+
// the information. This is alright, since `ignore_for_traits` is only relevant when
929+
// this code runs on pre-cleanup MIR, and `ignore_for_traits = false` is the safer
930+
// default.
927931
match decl.local_info {
928932
// Do not include raw pointers created from accessing `static` items, as those could
929933
// well be re-created by another access to the same static.
930-
Some(box LocalInfo::StaticRef { is_thread_local, .. }) => !is_thread_local,
934+
ClearCrossCrate::Set(box LocalInfo::StaticRef { is_thread_local, .. }) => {
935+
!is_thread_local
936+
}
931937
// Fake borrows are only read by fake reads, so do not have any reality in
932938
// post-analysis MIR.
933-
Some(box LocalInfo::FakeBorrow) => true,
939+
ClearCrossCrate::Set(box LocalInfo::FakeBorrow) => true,
934940
_ => false,
935941
}
936942
} else {

‎compiler/rustc_mir_transform/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use rustc_hir::intravisit::{self, Visitor};
2929
use rustc_index::vec::IndexVec;
3030
use rustc_middle::mir::visit::Visitor as _;
3131
use rustc_middle::mir::{
32-
traversal, AnalysisPhase, Body, ConstQualifs, Constant, LocalDecl, MirPass, MirPhase, Operand,
33-
Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, SourceInfo, Statement, StatementKind,
34-
TerminatorKind,
32+
traversal, AnalysisPhase, Body, ClearCrossCrate, ConstQualifs, Constant, LocalDecl, MirPass,
33+
MirPhase, Operand, Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, SourceInfo,
34+
Statement, StatementKind, TerminatorKind,
3535
};
3636
use rustc_middle::ty::query::Providers;
3737
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
@@ -532,6 +532,12 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
532532
&[&lower_intrinsics::LowerIntrinsics, &simplify::SimplifyCfg::new("elaborate-drops")];
533533

534534
pm::run_passes(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::PostCleanup)));
535+
536+
// Clear this by anticipation. Optimizations and runtime MIR have no reason to look
537+
// into this information, which is meant for borrowck diagnostics.
538+
for decl in &mut body.local_decls {
539+
decl.local_info = ClearCrossCrate::Clear;
540+
}
535541
}
536542

537543
fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

‎compiler/rustc_mir_transform/src/nrvo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn local_eligible_for_nrvo(body: &mut mir::Body<'_>) -> Option<Local> {
102102
mir::LocalKind::Arg => return None,
103103

104104
mir::LocalKind::ReturnPointer => bug!("Return place was assigned to itself?"),
105-
mir::LocalKind::Var | mir::LocalKind::Temp => {}
105+
mir::LocalKind::Temp => {}
106106
}
107107

108108
// If multiple different locals are copied to the return place. We can't pick a

‎tests/codegen/fewer-names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub fn sum(x: u32, y: u32) -> u32 {
1313

1414
// NO-LABEL: define{{.*}}i32 @sum(i32 noundef %x, i32 noundef %y)
1515
// NO-NEXT: start:
16-
// NO-NEXT: %z = add i32 %y, %x
17-
// NO-NEXT: ret i32 %z
16+
// NO-NEXT: %0 = add i32 %y, %x
17+
// NO-NEXT: ret i32 %0
1818
let z = x + y;
1919
z
2020
}

‎tests/codegen/var-names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn test(a: u32, b: u32) -> u32 {
99
// CHECK: %c = add i32 %a, %b
1010
let d = c;
1111
let e = d * a;
12-
// CHECK-NEXT: %e = mul i32 %c, %a
12+
// CHECK-NEXT: %0 = mul i32 %c, %a
1313
e
14-
// CHECK-NEXT: ret i32 %e
14+
// CHECK-NEXT: ret i32 %0
1515
}

‎tests/incremental/hashes/let_expressions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ pub fn add_initializer() {
193193
}
194194

195195
#[cfg(not(any(cfail1,cfail4)))]
196-
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck,optimized_mir")]
196+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck")]
197197
#[rustc_clean(cfg="cfail3")]
198-
#[rustc_clean(cfg="cfail5", except="hir_owner_nodes,typeck,optimized_mir")]
198+
#[rustc_clean(cfg="cfail5", except="hir_owner_nodes,typeck")]
199199
#[rustc_clean(cfg="cfail6")]
200200
pub fn add_initializer() {
201201
let _x: i16 = 3i16;

‎tests/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
let mut _7: !; // in scope 0 at $DIR/separate_const_switch.rs:+1:9: +1:10
1313
let mut _8: std::result::Result<std::convert::Infallible, i32>; // in scope 0 at $DIR/separate_const_switch.rs:+1:9: +1:10
1414
let _9: i32; // in scope 0 at $DIR/separate_const_switch.rs:+1:8: +1:10
15-
let mut _16: i32; // in scope 0 at $SRC_DIR/core/src/result.rs:LL:COL
1615
scope 1 {
1716
debug residual => _6; // in scope 1 at $DIR/separate_const_switch.rs:+1:9: +1:10
1817
scope 2 {
@@ -23,7 +22,7 @@
2322
scope 9 {
2423
debug e => _14; // in scope 9 at $SRC_DIR/core/src/result.rs:LL:COL
2524
scope 10 (inlined <i32 as From<i32>>::from) { // at $SRC_DIR/core/src/result.rs:LL:COL
26-
debug t => _16; // in scope 10 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
25+
debug t => _14; // in scope 10 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
2726
}
2827
}
2928
}
@@ -90,10 +89,7 @@
9089
StorageLive(_14); // scope 2 at $DIR/separate_const_switch.rs:+1:8: +1:10
9190
_14 = move ((_8 as Err).0: i32); // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
9291
StorageLive(_15); // scope 9 at $SRC_DIR/core/src/result.rs:LL:COL
93-
StorageLive(_16); // scope 9 at $SRC_DIR/core/src/result.rs:LL:COL
94-
_16 = move _14; // scope 9 at $SRC_DIR/core/src/result.rs:LL:COL
95-
_15 = move _16; // scope 10 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
96-
StorageDead(_16); // scope 9 at $SRC_DIR/core/src/result.rs:LL:COL
92+
_15 = move _14; // scope 10 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
9793
_0 = Result::<i32, i32>::Err(move _15); // scope 9 at $SRC_DIR/core/src/result.rs:LL:COL
9894
StorageDead(_15); // scope 9 at $SRC_DIR/core/src/result.rs:LL:COL
9995
StorageDead(_14); // scope 2 at $DIR/separate_const_switch.rs:+1:8: +1:10

0 commit comments

Comments
 (0)
Please sign in to comment.