1
- use crate :: infer:: type_variable:: TypeVariableMap ;
2
- use crate :: ty:: { self , Ty , TyCtxt } ;
1
+ use crate :: ty:: { self , Ty , TyCtxt , TyVid , RegionVid } ;
3
2
use crate :: ty:: fold:: { TypeFoldable , TypeFolder } ;
4
3
5
4
use super :: InferCtxt ;
6
5
use super :: RegionVariableOrigin ;
7
6
7
+ use std:: ops:: Range ;
8
+
8
9
impl < ' a , ' gcx , ' tcx > InferCtxt < ' a , ' gcx , ' tcx > {
9
10
/// This rather funky routine is used while processing expected
10
11
/// types. What happens here is that we want to propagate a
@@ -42,12 +43,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
42
43
/// regions in question are not particularly important. We will
43
44
/// use the expected types to guide coercions, but we will still
44
45
/// 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
46
47
/// after the snapshot is popped, the variable `?T` is no longer
47
48
/// 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
51
54
F : FnOnce ( ) -> Result < T , E > ,
52
55
T : TypeFoldable < ' tcx > ,
53
56
{
@@ -101,8 +104,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
101
104
102
105
pub struct RegionFudger < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
103
106
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 > ,
106
109
origin : & ' a RegionVariableOrigin ,
107
110
}
108
111
@@ -114,25 +117,21 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
114
117
fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
115
118
match ty. sty {
116
119
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
136
135
}
137
136
}
138
137
_ => ty. super_fold_with ( self ) ,
@@ -141,12 +140,10 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
141
140
142
141
fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
143
142
match * r {
144
- ty:: ReVar ( v ) if self . region_vars . contains ( & v ) => {
143
+ ty:: ReVar ( vid ) if self . region_vars . contains ( & vid ) => {
145
144
self . infcx . next_region_var ( self . origin . clone ( ) )
146
145
}
147
- _ => {
148
- r
149
- }
146
+ _ => r,
150
147
}
151
148
}
152
149
}
0 commit comments