@@ -46,51 +46,56 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
46
46
}
47
47
}
48
48
49
- /// The opportunistic type and region resolver is similar to the
50
- /// opportunistic type resolver, but also opportunistically resolves
51
- /// regions. It is useful for canonicalization.
52
- pub struct OpportunisticTypeAndRegionResolver < ' a , ' tcx > {
49
+ /// The opportunistic region resolver opportunistically resolves regions
50
+ /// variables to the variable with the least variable id. It is used when
51
+ /// normlizing projections to avoid hitting the recursion limit by creating
52
+ /// many versions of a predicate for types that in the end have to unify.
53
+ ///
54
+ /// If you want to resolve type and const variables as well, call
55
+ /// [InferCtxt::resolve_vars_if_possible] first.
56
+ pub struct OpportunisticRegionResolver < ' a , ' tcx > {
53
57
infcx : & ' a InferCtxt < ' a , ' tcx > ,
54
58
}
55
59
56
- impl < ' a , ' tcx > OpportunisticTypeAndRegionResolver < ' a , ' tcx > {
60
+ impl < ' a , ' tcx > OpportunisticRegionResolver < ' a , ' tcx > {
57
61
pub fn new ( infcx : & ' a InferCtxt < ' a , ' tcx > ) -> Self {
58
- OpportunisticTypeAndRegionResolver { infcx }
62
+ OpportunisticRegionResolver { infcx }
59
63
}
60
64
}
61
65
62
- impl < ' a , ' tcx > TypeFolder < ' tcx > for OpportunisticTypeAndRegionResolver < ' a , ' tcx > {
66
+ impl < ' a , ' tcx > TypeFolder < ' tcx > for OpportunisticRegionResolver < ' a , ' tcx > {
63
67
fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' tcx > {
64
68
self . infcx . tcx
65
69
}
66
70
67
71
fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
68
- if !t. needs_infer ( ) {
72
+ if !t. has_infer_regions ( ) {
69
73
t // micro-optimize -- if there is nothing in this type that this fold affects...
70
74
} else {
71
- let t0 = self . infcx . shallow_resolve ( t) ;
72
- t0. super_fold_with ( self )
75
+ t. super_fold_with ( self )
73
76
}
74
77
}
75
78
76
79
fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
77
80
match * r {
78
- ty:: ReVar ( rid) => self
79
- . infcx
80
- . inner
81
- . borrow_mut ( )
82
- . unwrap_region_constraints ( )
83
- . opportunistic_resolve_var ( self . tcx ( ) , rid) ,
81
+ ty:: ReVar ( rid) => {
82
+ let resolved = self
83
+ . infcx
84
+ . inner
85
+ . borrow_mut ( )
86
+ . unwrap_region_constraints ( )
87
+ . opportunistic_resolve_var ( rid) ;
88
+ self . tcx ( ) . reuse_or_mk_region ( r, ty:: ReVar ( resolved) )
89
+ }
84
90
_ => r,
85
91
}
86
92
}
87
93
88
94
fn fold_const ( & mut self , ct : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
89
- if !ct. needs_infer ( ) {
95
+ if !ct. has_infer_regions ( ) {
90
96
ct // micro-optimize -- if there is nothing in this const that this fold affects...
91
97
} else {
92
- let c0 = self . infcx . shallow_resolve ( ct) ;
93
- c0. super_fold_with ( self )
98
+ ct. super_fold_with ( self )
94
99
}
95
100
}
96
101
}
0 commit comments