Skip to content

Commit 317acb7

Browse files
committed
Rollup merge of rust-lang#32482 - nikomatsakis:erase-via-visitor, r=nagisa
use new visitor to erase regions r? @nagisa
2 parents d36cb22 + e539b74 commit 317acb7

File tree

2 files changed

+17
-87
lines changed

2 files changed

+17
-87
lines changed

src/librustc/mir/visit.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,15 @@ macro_rules! make_mir_visitor {
614614

615615
fn super_constant(&mut self,
616616
constant: & $($mutability)* Constant<'tcx>) {
617-
self.visit_span(& $($mutability)* constant.span);
618-
self.visit_ty(& $($mutability)* constant.ty);
619-
self.visit_literal(& $($mutability)* constant.literal);
617+
let Constant {
618+
ref $($mutability)* span,
619+
ref $($mutability)* ty,
620+
ref $($mutability)* literal,
621+
} = *constant;
622+
623+
self.visit_span(span);
624+
self.visit_ty(ty);
625+
self.visit_literal(literal);
620626
}
621627

622628
fn super_typed_const_val(&mut self,
@@ -626,6 +632,7 @@ macro_rules! make_mir_visitor {
626632
ref $($mutability)* ty,
627633
ref $($mutability)* value,
628634
} = *constant;
635+
629636
self.visit_span(span);
630637
self.visit_ty(ty);
631638
self.visit_const_usize(value);

src/librustc_mir/transform/erase_regions.rs

+7-84
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
//! We want to do this once just before trans, so trans does not have to take
1313
//! care erasing regions all over the place.
1414
15-
use rustc::middle::ty::{self, TyCtxt};
15+
use rustc::middle::subst::Substs;
16+
use rustc::middle::ty::{Ty, TyCtxt};
1617
use rustc::mir::repr::*;
1718
use rustc::mir::visit::MutVisitor;
1819
use rustc::mir::transform::{MirPass, Pass};
@@ -28,94 +29,16 @@ impl<'a, 'tcx> EraseRegionsVisitor<'a, 'tcx> {
2829
tcx: tcx
2930
}
3031
}
31-
32-
fn erase_regions_return_ty(&mut self, fn_output: &mut ty::FnOutput<'tcx>) {
33-
match *fn_output {
34-
ty::FnConverging(ref mut ty) => {
35-
*ty = self.tcx.erase_regions(ty);
36-
},
37-
ty::FnDiverging => {}
38-
}
39-
}
40-
41-
fn erase_regions_tys<'b, T>(&mut self, tys: T)
42-
where T: Iterator<Item = &'b mut ty::Ty<'tcx>>,
43-
'tcx: 'b
44-
{
45-
for ty in tys {
46-
*ty = self.tcx.erase_regions(ty);
47-
}
48-
}
4932
}
5033

5134
impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
52-
fn visit_mir(&mut self, mir: &mut Mir<'tcx>) {
53-
self.erase_regions_return_ty(&mut mir.return_ty);
54-
self.erase_regions_tys(mir.var_decls.iter_mut().map(|d| &mut d.ty));
55-
self.erase_regions_tys(mir.arg_decls.iter_mut().map(|d| &mut d.ty));
56-
self.erase_regions_tys(mir.temp_decls.iter_mut().map(|d| &mut d.ty));
57-
self.super_mir(mir);
58-
}
59-
60-
fn visit_terminator(&mut self, bb: BasicBlock, terminator: &mut Terminator<'tcx>) {
61-
match terminator.kind {
62-
TerminatorKind::Goto { .. } |
63-
TerminatorKind::Resume |
64-
TerminatorKind::Return |
65-
TerminatorKind::If { .. } |
66-
TerminatorKind::Switch { .. } |
67-
TerminatorKind::Drop { .. } |
68-
TerminatorKind::Call { .. } => {
69-
/* nothing to do */
70-
},
71-
TerminatorKind::SwitchInt { ref mut switch_ty, .. } => {
72-
*switch_ty = self.tcx.erase_regions(switch_ty);
73-
},
74-
}
75-
self.super_terminator(bb, terminator);
76-
}
77-
78-
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>) {
79-
match *rvalue {
80-
Rvalue::Use(_) |
81-
Rvalue::Len(_) |
82-
Rvalue::BinaryOp(_, _, _) |
83-
Rvalue::UnaryOp(_, _) |
84-
Rvalue::Slice { input: _, from_start: _, from_end: _ } |
85-
Rvalue::InlineAsm {..} => {},
86-
87-
Rvalue::Repeat(_, ref mut value) => value.ty = self.tcx.erase_regions(&value.ty),
88-
Rvalue::Ref(ref mut region, _, _) => *region = ty::ReStatic,
89-
Rvalue::Cast(_, _, ref mut ty) => *ty = self.tcx.erase_regions(ty),
90-
Rvalue::Box(ref mut ty) => *ty = self.tcx.erase_regions(ty),
91-
92-
93-
Rvalue::Aggregate(AggregateKind::Vec, _) |
94-
Rvalue::Aggregate(AggregateKind::Tuple, _) => {},
95-
Rvalue::Aggregate(AggregateKind::Adt(_, _, ref mut substs), _) =>
96-
*substs = self.tcx.mk_substs(self.tcx.erase_regions(*substs)),
97-
Rvalue::Aggregate(AggregateKind::Closure(def_id, ref mut closure_substs), _) => {
98-
let cloned = Box::new(closure_substs.clone());
99-
let ty = self.tcx.mk_closure_from_closure_substs(def_id, cloned);
100-
let erased = self.tcx.erase_regions(&ty);
101-
*closure_substs = match erased.sty {
102-
ty::TyClosure(_, ref closure_substs) => &*closure_substs,
103-
_ => unreachable!()
104-
};
105-
}
106-
}
107-
self.super_rvalue(rvalue);
35+
fn visit_ty(&mut self, ty: &mut Ty<'tcx>) {
36+
let old_ty = *ty;
37+
*ty = self.tcx.erase_regions(&old_ty);
10838
}
10939

110-
fn visit_constant(&mut self, constant: &mut Constant<'tcx>) {
111-
constant.ty = self.tcx.erase_regions(&constant.ty);
112-
match constant.literal {
113-
Literal::Item { ref mut substs, .. } => {
114-
*substs = self.tcx.mk_substs(self.tcx.erase_regions(substs));
115-
}
116-
Literal::Value { .. } => { /* nothing to do */ }
117-
}
118-
self.super_constant(constant);
40+
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>) {
41+
*substs = self.tcx.mk_substs(self.tcx.erase_regions(*substs));
11942
}
12043
}
12144

0 commit comments

Comments
 (0)