1- use crate :: infer:: type_variable:: TypeVariableMap ;
2- use crate :: ty:: { self , Ty , TyCtxt } ;
1+ use crate :: ty:: { self , Ty , TyCtxt , TyVid , RegionVid } ;
32use crate :: ty:: fold:: { TypeFoldable , TypeFolder } ;
43
54use super :: InferCtxt ;
65use super :: RegionVariableOrigin ;
76
7+ use std:: ops:: Range ;
8+
89impl < ' a , ' gcx , ' tcx > InferCtxt < ' a , ' gcx , ' tcx > {
910 /// This rather funky routine is used while processing expected
1011 /// types. What happens here is that we want to propagate a
@@ -42,12 +43,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
4243 /// regions in question are not particularly important. We will
4344 /// use the expected types to guide coercions, but we will still
4445 /// type-check the resulting types from those coercions against
45- /// the actual types (`?T`, `Option<?T`) -- and remember that
46+ /// the actual types (`?T`, `Option<?T> `) -- and remember that
4647 /// after the snapshot is popped, the variable `?T` is no longer
4748 /// unified.
48- pub fn fudge_regions_if_ok < T , E , F > ( & self ,
49- origin : & RegionVariableOrigin ,
50- f : F ) -> Result < T , E > where
49+ pub fn fudge_regions_if_ok < T , E , F > (
50+ & self ,
51+ origin : & RegionVariableOrigin ,
52+ f : F ,
53+ ) -> Result < T , E > where
5154 F : FnOnce ( ) -> Result < T , E > ,
5255 T : TypeFoldable < ' tcx > ,
5356 {
@@ -101,8 +104,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
101104
102105pub struct RegionFudger < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
103106 infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
104- type_variables : & ' a TypeVariableMap ,
105- region_vars : & ' a Vec < ty :: RegionVid > ,
107+ type_variables : & ' a Range < TyVid > ,
108+ region_vars : & ' a Range < RegionVid > ,
106109 origin : & ' a RegionVariableOrigin ,
107110}
108111
@@ -114,25 +117,21 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
114117 fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
115118 match ty. sty {
116119 ty:: Infer ( ty:: InferTy :: TyVar ( vid) ) => {
117- match self . type_variables . get ( & vid) {
118- None => {
119- // This variable was created before the
120- // "fudging". Since we refresh all type
121- // variables to their binding anyhow, we know
122- // that it is unbound, so we can just return
123- // it.
124- debug_assert ! ( self . infcx. type_variables. borrow_mut( )
125- . probe( vid)
126- . is_unknown( ) ) ;
127- ty
128- }
129-
130- Some ( & origin) => {
131- // This variable was created during the
132- // fudging. Recreate it with a fresh variable
133- // here.
134- self . infcx . next_ty_var ( origin)
135- }
120+ if self . type_variables . contains ( & vid) {
121+ // This variable was created during the fudging.
122+ // Recreate it with a fresh variable here.
123+ let origin = self . infcx . type_variables . borrow ( ) . var_origin ( vid) . clone ( ) ;
124+ self . infcx . next_ty_var ( origin)
125+ } else {
126+ // This variable was created before the
127+ // "fudging". Since we refresh all type
128+ // variables to their binding anyhow, we know
129+ // that it is unbound, so we can just return
130+ // it.
131+ debug_assert ! ( self . infcx. type_variables. borrow_mut( )
132+ . probe( vid)
133+ . is_unknown( ) ) ;
134+ ty
136135 }
137136 }
138137 _ => ty. super_fold_with ( self ) ,
@@ -141,12 +140,10 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
141140
142141 fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
143142 match * r {
144- ty:: ReVar ( v ) if self . region_vars . contains ( & v ) => {
143+ ty:: ReVar ( vid ) if self . region_vars . contains ( & vid ) => {
145144 self . infcx . next_region_var ( self . origin . clone ( ) )
146145 }
147- _ => {
148- r
149- }
146+ _ => r,
150147 }
151148 }
152149}
0 commit comments