Skip to content

Commit

Permalink
re-name stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed May 1, 2022
1 parent 4d4b0f1 commit d9ddb64
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_middle/src/mir/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<LocalInfo<'tcx>>>,
) -> 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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/add_retag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
_ => (),
};
}
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_mir_transform/src/deref_separator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit d9ddb64

Please sign in to comment.