1 use rustc
::ty
::subst
::Substs
;
2 use rustc
::ty
::{self, ClosureSubsts, GeneratorSubsts, Ty, TypeFoldable}
;
3 use rustc
::mir
::{Location, Mir}
;
4 use rustc
::mir
::visit
::{MutVisitor, TyContext}
;
5 use rustc
::infer
::{InferCtxt, NLLRegionVariableOrigin}
;
7 /// Replaces all free regions appearing in the MIR with fresh
8 /// inference variables, returning the number of variables created.
9 pub fn renumber_mir
<'tcx
>(infcx
: &InferCtxt
<'_
, '_
, 'tcx
>, mir
: &mut Mir
<'tcx
>) {
10 debug
!("renumber_mir()");
11 debug
!("renumber_mir: mir.arg_count={:?}", mir
.arg_count
);
13 let mut visitor
= NLLVisitor { infcx }
;
14 visitor
.visit_mir(mir
);
17 /// Replaces all regions appearing in `value` with fresh inference
19 pub fn renumber_regions
<'tcx
, T
>(
20 infcx
: &InferCtxt
<'_
, '_
, 'tcx
>,
24 T
: TypeFoldable
<'tcx
>,
26 debug
!("renumber_regions(value={:?})", value
);
30 .fold_regions(value
, &mut false, |_region
, _depth
| {
31 let origin
= NLLRegionVariableOrigin
::Existential
;
32 infcx
.next_nll_region_var(origin
)
36 struct NLLVisitor
<'a
, 'gcx
: 'a
+ 'tcx
, 'tcx
: 'a
> {
37 infcx
: &'a InferCtxt
<'a
, 'gcx
, 'tcx
>,
40 impl<'a
, 'gcx
, 'tcx
> NLLVisitor
<'a
, 'gcx
, 'tcx
> {
41 fn renumber_regions
<T
>(&mut self, value
: &T
) -> T
43 T
: TypeFoldable
<'tcx
>,
45 renumber_regions(self.infcx
, value
)
49 impl<'a
, 'gcx
, 'tcx
> MutVisitor
<'tcx
> for NLLVisitor
<'a
, 'gcx
, 'tcx
> {
50 fn visit_mir(&mut self, mir
: &mut Mir
<'tcx
>) {
51 for promoted
in mir
.promoted
.iter_mut() {
52 self.visit_mir(promoted
);
58 fn visit_ty(&mut self, ty
: &mut Ty
<'tcx
>, ty_context
: TyContext
) {
59 debug
!("visit_ty(ty={:?}, ty_context={:?})", ty
, ty_context
);
61 *ty
= self.renumber_regions(ty
);
63 debug
!("visit_ty: ty={:?}", ty
);
66 fn visit_substs(&mut self, substs
: &mut &'tcx Substs
<'tcx
>, location
: Location
) {
67 debug
!("visit_substs(substs={:?}, location={:?})", substs
, location
);
69 *substs
= self.renumber_regions(&{ *substs }
);
71 debug
!("visit_substs: substs={:?}", substs
);
74 fn visit_region(&mut self, region
: &mut ty
::Region
<'tcx
>, location
: Location
) {
75 debug
!("visit_region(region={:?}, location={:?})", region
, location
);
77 let old_region
= *region
;
78 *region
= self.renumber_regions(&old_region
);
80 debug
!("visit_region: region={:?}", region
);
83 fn visit_const(&mut self, constant
: &mut &'tcx ty
::LazyConst
<'tcx
>, _location
: Location
) {
84 *constant
= self.renumber_regions(&*constant
);
87 fn visit_generator_substs(&mut self,
88 substs
: &mut GeneratorSubsts
<'tcx
>,
91 "visit_generator_substs(substs={:?}, location={:?})",
96 *substs
= self.renumber_regions(substs
);
98 debug
!("visit_generator_substs: substs={:?}", substs
);
101 fn visit_closure_substs(&mut self, substs
: &mut ClosureSubsts
<'tcx
>, location
: Location
) {
103 "visit_closure_substs(substs={:?}, location={:?})",
108 *substs
= self.renumber_regions(substs
);
110 debug
!("visit_closure_substs: substs={:?}", substs
);