//! We want to do this once just before trans, so trans does not have to take
//! care erasing regions all over the place.
-use rustc::middle::ty;
+use rustc::middle::ty::{self, TyCtxt};
use rustc::mir::repr::*;
use rustc::mir::visit::MutVisitor;
-use rustc::mir::mir_map::MirMap;
-use rustc::mir::transform::MirPass;
-
-pub fn erase_regions<'tcx>(tcx: &ty::ctxt<'tcx>, mir_map: &mut MirMap<'tcx>) {
- let mut eraser = EraseRegions;
-
- for (_, mir) in &mut mir_map.map {
- eraser.run_on_mir(mir, tcx);
- }
-}
-
-pub struct EraseRegions;
+use rustc::mir::transform::{MirPass, Pass};
+use syntax::ast::NodeId;
struct EraseRegionsVisitor<'a, 'tcx: 'a> {
- tcx: &'a ty::ctxt<'tcx>,
+ tcx: &'a TyCtxt<'tcx>,
}
impl<'a, 'tcx> EraseRegionsVisitor<'a, 'tcx> {
- pub fn new(tcx: &'a ty::ctxt<'tcx>) -> Self {
+ pub fn new(tcx: &'a TyCtxt<'tcx>) -> Self {
EraseRegionsVisitor {
tcx: tcx
}
}
}
-impl MirPass for EraseRegions {
- fn run_on_mir<'tcx>(&mut self, mir: &mut Mir<'tcx>, tcx: &ty::ctxt<'tcx>) {
- EraseRegionsVisitor::new(tcx).visit_mir(mir);
- }
-}
-
impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
fn visit_mir(&mut self, mir: &mut Mir<'tcx>) {
self.erase_regions_return_ty(&mut mir.return_ty);
Rvalue::BinaryOp(_, _, _) |
Rvalue::UnaryOp(_, _) |
Rvalue::Slice { input: _, from_start: _, from_end: _ } |
- Rvalue::InlineAsm(_) => {},
+ Rvalue::InlineAsm {..} => {},
Rvalue::Repeat(_, ref mut value) => value.ty = self.tcx.erase_regions(&value.ty),
Rvalue::Ref(ref mut region, _, _) => *region = ty::ReStatic,
self.super_constant(constant);
}
}
+
+pub struct EraseRegions;
+
+impl Pass for EraseRegions {}
+
+impl<'tcx> MirPass<'tcx> for EraseRegions {
+ fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) {
+ EraseRegionsVisitor::new(tcx).visit_mir(mir);
+ }
+}