2015-11-16 18:41:16 +01:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! This pass erases all early-bound regions from the types occuring in the MIR.
|
|
|
|
//! We want to do this once just before trans, so trans does not have to take
|
|
|
|
//! care erasing regions all over the place.
|
|
|
|
|
2016-03-25 13:10:32 -04:00
|
|
|
use rustc::middle::subst::Substs;
|
|
|
|
use rustc::middle::ty::{Ty, TyCtxt};
|
2015-11-19 16:37:34 +01:00
|
|
|
use rustc::mir::repr::*;
|
2016-01-31 20:25:17 +02:00
|
|
|
use rustc::mir::visit::MutVisitor;
|
2016-02-26 18:05:50 +02:00
|
|
|
use rustc::mir::transform::{MirPass, Pass};
|
2016-03-07 14:07:07 +02:00
|
|
|
use syntax::ast::NodeId;
|
2015-11-16 18:41:16 +01:00
|
|
|
|
2016-02-05 09:35:00 +01:00
|
|
|
struct EraseRegionsVisitor<'a, 'tcx: 'a> {
|
2016-02-29 23:36:51 +00:00
|
|
|
tcx: &'a TyCtxt<'tcx>,
|
2015-11-16 18:41:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-05 09:35:00 +01:00
|
|
|
impl<'a, 'tcx> EraseRegionsVisitor<'a, 'tcx> {
|
2016-02-29 23:36:51 +00:00
|
|
|
pub fn new(tcx: &'a TyCtxt<'tcx>) -> Self {
|
2016-02-05 09:35:00 +01:00
|
|
|
EraseRegionsVisitor {
|
2015-11-16 18:41:16 +01:00
|
|
|
tcx: tcx
|
|
|
|
}
|
|
|
|
}
|
2016-01-31 20:25:17 +02:00
|
|
|
}
|
|
|
|
|
2016-02-05 09:35:00 +01:00
|
|
|
impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
|
2016-03-25 13:10:32 -04:00
|
|
|
fn visit_ty(&mut self, ty: &mut Ty<'tcx>) {
|
|
|
|
let old_ty = *ty;
|
|
|
|
*ty = self.tcx.erase_regions(&old_ty);
|
2015-11-16 18:41:16 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 13:10:32 -04:00
|
|
|
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>) {
|
|
|
|
*substs = self.tcx.mk_substs(self.tcx.erase_regions(*substs));
|
2015-11-16 18:41:16 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-26 18:05:50 +02:00
|
|
|
|
|
|
|
pub struct EraseRegions;
|
|
|
|
|
|
|
|
impl Pass for EraseRegions {}
|
|
|
|
|
|
|
|
impl<'tcx> MirPass<'tcx> for EraseRegions {
|
2016-03-07 14:07:07 +02:00
|
|
|
fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) {
|
2016-02-26 18:05:50 +02:00
|
|
|
EraseRegionsVisitor::new(tcx).visit_mir(mir);
|
|
|
|
}
|
|
|
|
}
|