diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 42a205fad75..990efa7d09d 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1080,7 +1080,7 @@ pub enum LocalInfo<'tcx> { /// (e.g. a temporary for `foo` in `MyStruct { my_field: foo }`) AggregateTemp, /// A temporary created during the pass `Derefer` to avoid it's retagging - Temp, + DerefTemp, } impl<'tcx> LocalDecl<'tcx> { diff --git a/compiler/rustc_middle/src/mir/patch.rs b/compiler/rustc_middle/src/mir/patch.rs index 708ea53eb1a..d03f9235efd 100644 --- a/compiler/rustc_middle/src/mir/patch.rs +++ b/compiler/rustc_middle/src/mir/patch.rs @@ -78,20 +78,22 @@ impl<'tcx> MirPatch<'tcx> { Location { block: bb, statement_index: offset } } - pub fn new_local_temp(&mut self, ty: Ty<'tcx>, span: Span) -> Local { + pub fn new_local_with_info( + &mut self, + ty: Ty<'tcx>, + span: Span, + local_info: Option>>, + ) -> Local { let index = self.next_local; self.next_local += 1; let mut new_decl = LocalDecl::new(ty, span); - new_decl.local_info = Some(Box::new(LocalInfo::Temp)); + new_decl.local_info = local_info; self.new_locals.push(new_decl); Local::new(index as usize) } pub fn new_temp(&mut self, ty: Ty<'tcx>, span: Span) -> Local { - let index = self.next_local; - self.next_local += 1; - self.new_locals.push(LocalDecl::new(ty, span)); - Local::new(index as usize) + self.new_local_with_info(ty, span, None) } pub fn new_internal(&mut self, ty: Ty<'tcx>, span: Span) -> Local { diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index 825340892d9..a245da658b9 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -61,7 +61,7 @@ fn may_be_reference(ty: Ty<'_>) -> bool { fn is_not_temp<'tcx>(local_decl: &LocalDecl<'tcx>) -> bool { if let Some(local_info) = &local_decl.local_info { match local_info.as_ref() { - LocalInfo::Temp => return false, + LocalInfo::DerefTemp => return false, _ => (), }; } diff --git a/compiler/rustc_mir_transform/src/deref_separator.rs b/compiler/rustc_mir_transform/src/deref_separator.rs index afaab6e9a35..57a95a67df7 100644 --- a/compiler/rustc_mir_transform/src/deref_separator.rs +++ b/compiler/rustc_mir_transform/src/deref_separator.rs @@ -33,8 +33,11 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> { for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() { if p_elem == ProjectionElem::Deref && !p_ref.projection.is_empty() { let ty = p_ref.ty(&self.local_decls, self.tcx).ty; - let temp = - self.patcher.new_local_temp(ty, self.local_decls[p_ref.local].source_info.span); + let temp = self.patcher.new_local_with_info( + ty, + self.local_decls[p_ref.local].source_info.span, + Some(Box::new(LocalInfo::DerefTemp)), + ); self.patcher.add_statement(loc, StatementKind::StorageLive(temp));