Skip to content

Commit 162bd16

Browse files
committed
Elide storage markers when elaborating deref projections
1 parent 943a380 commit 162bd16

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

compiler/rustc_middle/src/mir/patch.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,25 @@ impl<'tcx> MirPatch<'tcx> {
6868
Location { block: bb, statement_index: offset }
6969
}
7070

71-
pub fn new_local_with_info(
71+
pub fn new_internal_with_info(
7272
&mut self,
7373
ty: Ty<'tcx>,
7474
span: Span,
7575
local_info: Option<Box<LocalInfo<'tcx>>>,
7676
) -> Local {
7777
let index = self.next_local;
7878
self.next_local += 1;
79-
let mut new_decl = LocalDecl::new(ty, span);
79+
let mut new_decl = LocalDecl::new(ty, span).internal();
8080
new_decl.local_info = local_info;
8181
self.new_locals.push(new_decl);
8282
Local::new(index as usize)
8383
}
8484

8585
pub fn new_temp(&mut self, ty: Ty<'tcx>, span: Span) -> Local {
86-
self.new_local_with_info(ty, span, None)
86+
let index = self.next_local;
87+
self.next_local += 1;
88+
self.new_locals.push(LocalDecl::new(ty, span));
89+
Local::new(index as usize)
8790
}
8891

8992
pub fn new_internal(&mut self, ty: Ty<'tcx>, span: Span) -> Local {

compiler/rustc_mir_transform/src/deref_separator.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
2828
let mut last_len = 0;
2929
let mut last_deref_idx = 0;
3030

31-
let mut prev_temp: Option<Local> = None;
32-
3331
for (idx, elem) in place.projection[0..].iter().enumerate() {
3432
if *elem == ProjectionElem::Deref {
3533
last_deref_idx = idx;
@@ -39,14 +37,12 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
3937
for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() {
4038
if !p_ref.projection.is_empty() && p_elem == ProjectionElem::Deref {
4139
let ty = p_ref.ty(&self.local_decls, self.tcx).ty;
42-
let temp = self.patcher.new_local_with_info(
40+
let temp = self.patcher.new_internal_with_info(
4341
ty,
4442
self.local_decls[p_ref.local].source_info.span,
4543
Some(Box::new(LocalInfo::DerefTemp)),
4644
);
4745

48-
self.patcher.add_statement(loc, StatementKind::StorageLive(temp));
49-
5046
// We are adding current p_ref's projections to our
5147
// temp value, excluding projections we already covered.
5248
let deref_place = Place::from(place_local)
@@ -66,22 +62,8 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
6662
Place::from(temp).project_deeper(&place.projection[idx..], self.tcx);
6763
*place = temp_place;
6864
}
69-
70-
// We are destroying the previous temp since it's no longer used.
71-
if let Some(prev_temp) = prev_temp {
72-
self.patcher.add_statement(loc, StatementKind::StorageDead(prev_temp));
73-
}
74-
75-
prev_temp = Some(temp);
7665
}
7766
}
78-
79-
// Since we won't be able to reach final temp, we destroy it outside the loop.
80-
if let Some(prev_temp) = prev_temp {
81-
let last_loc =
82-
Location { block: loc.block, statement_index: loc.statement_index + 1 };
83-
self.patcher.add_statement(last_loc, StatementKind::StorageDead(prev_temp));
84-
}
8567
}
8668
}
8769
}

0 commit comments

Comments
 (0)