1 //! This pass erases all early-bound regions from the types occurring in the MIR.
2 //! We want to do this once just before codegen, so codegen does not have to take
3 //! care erasing regions all over the place.
4 //! NOTE: We do NOT erase regions of statements that are relevant for
5 //! "types-as-contracts"-validation, namely, AcquireValid, ReleaseValid
7 use rustc::ty::subst::Substs;
8 use rustc::ty::{self, Ty, TyCtxt};
10 use rustc::mir::visit::{MutVisitor, TyContext};
11 use crate::transform::{MirPass, MirSource};
13 struct EraseRegionsVisitor<'a, 'tcx: 'a> {
14 tcx: TyCtxt<'a, 'tcx, 'tcx>,
17 impl<'a, 'tcx> EraseRegionsVisitor<'a, 'tcx> {
18 pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
25 impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
26 fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
27 *ty = self.tcx.erase_regions(ty);
31 fn visit_region(&mut self, region: &mut ty::Region<'tcx>, _: Location) {
32 *region = self.tcx.types.re_erased;
35 fn visit_const(&mut self, constant: &mut &'tcx ty::LazyConst<'tcx>, _: Location) {
36 *constant = self.tcx.erase_regions(constant);
39 fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, _: Location) {
40 *substs = self.tcx.erase_regions(substs);
43 fn visit_statement(&mut self,
45 statement: &mut Statement<'tcx>,
47 self.super_statement(block, statement, location);
51 pub struct EraseRegions;
53 impl MirPass for EraseRegions {
54 fn run_pass<'a, 'tcx>(&self,
55 tcx: TyCtxt<'a, 'tcx, 'tcx>,
57 mir: &mut Mir<'tcx>) {
58 EraseRegionsVisitor::new(tcx).visit_mir(mir);