1
- use crate :: ty:: { self , Ty , TyCtxt , TyVid , IntVid , FloatVid , RegionVid } ;
1
+ use crate :: ty:: { self , Ty , TyCtxt , TyVid , IntVid , FloatVid , RegionVid , ConstVid } ;
2
2
use crate :: ty:: fold:: { TypeFoldable , TypeFolder } ;
3
3
use crate :: mir:: interpret:: ConstValue ;
4
4
5
5
use super :: InferCtxt ;
6
- use super :: RegionVariableOrigin ;
6
+ use super :: { RegionVariableOrigin , ConstVariableOrigin } ;
7
7
use super :: type_variable:: TypeVariableOrigin ;
8
8
9
+ use rustc_data_structures:: unify as ut;
10
+ use ut:: UnifyKey ;
11
+
12
+ use std:: cell:: RefMut ;
9
13
use std:: ops:: Range ;
10
14
15
+ fn const_vars_since_snapshot < ' tcx > (
16
+ mut table : RefMut < ' _ , ut:: UnificationTable < ut:: InPlace < ConstVid < ' tcx > > > > ,
17
+ snapshot : & ut:: Snapshot < ut:: InPlace < ConstVid < ' tcx > > > ,
18
+ ) -> ( Range < ConstVid < ' tcx > > , Vec < ConstVariableOrigin > ) {
19
+ let range = table. vars_since_snapshot ( snapshot) ;
20
+ ( range. start ..range. end , ( range. start . index ..range. end . index ) . map ( |index| {
21
+ table. probe_value ( ConstVid :: from_index ( index) ) . origin . clone ( )
22
+ } ) . collect ( ) )
23
+ }
24
+
11
25
impl < ' a , ' gcx , ' tcx > InferCtxt < ' a , ' gcx , ' tcx > {
12
26
/// This rather funky routine is used while processing expected
13
27
/// types. What happens here is that we want to propagate a
@@ -80,13 +94,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
80
94
let region_vars = self . borrow_region_constraints ( ) . vars_since_snapshot (
81
95
& snapshot. region_constraints_snapshot ,
82
96
) ;
97
+ let const_vars = const_vars_since_snapshot (
98
+ self . const_unification_table . borrow_mut ( ) ,
99
+ & snapshot. const_snapshot ,
100
+ ) ;
83
101
84
102
let fudger = InferenceFudger {
85
103
infcx : self ,
86
104
type_vars,
87
105
int_vars,
88
106
float_vars,
89
107
region_vars,
108
+ const_vars,
90
109
} ;
91
110
92
111
Ok ( ( fudger, value) )
@@ -105,7 +124,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
105
124
if fudger. type_vars . 0 . is_empty ( ) &&
106
125
fudger. int_vars . is_empty ( ) &&
107
126
fudger. float_vars . is_empty ( ) &&
108
- fudger. region_vars . 0 . is_empty ( ) {
127
+ fudger. region_vars . 0 . is_empty ( ) &&
128
+ fudger. const_vars . 0 . is_empty ( ) {
109
129
Ok ( value)
110
130
} else {
111
131
Ok ( value. fold_with ( & mut fudger) )
@@ -119,6 +139,7 @@ pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
119
139
int_vars : Range < IntVid > ,
120
140
float_vars : Range < FloatVid > ,
121
141
region_vars : ( Range < RegionVid > , Vec < RegionVariableOrigin > ) ,
142
+ const_vars : ( Range < ConstVid < ' tcx > > , Vec < ConstVariableOrigin > ) ,
122
143
}
123
144
124
145
impl < ' a , ' gcx , ' tcx > TypeFolder < ' gcx , ' tcx > for InferenceFudger < ' a , ' gcx , ' tcx > {
@@ -166,9 +187,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
166
187
}
167
188
168
189
fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
169
- if let ty:: ReVar ( vid) = r {
190
+ if let ty:: ReVar ( vid) = * r {
170
191
if self . region_vars . 0 . contains ( & vid) {
171
- let idx = ( vid. index ( ) - self . region_vars . 0 . start . index ( ) ) as usize ;
192
+ let idx = vid. index ( ) - self . region_vars . 0 . start . index ( ) ;
172
193
let origin = self . region_vars . 1 [ idx] ;
173
194
return self . infcx . next_region_var ( origin) ;
174
195
}
@@ -177,14 +198,12 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
177
198
}
178
199
179
200
fn fold_const ( & mut self , ct : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
180
- if let ty:: Const { val : ConstValue :: Infer ( ty:: InferConst :: Var ( vid) ) , ty } = * ct {
181
- if self . const_variables . contains ( & vid) {
182
- // This variable was created during the
183
- // fudging. Recreate it with a fresh variable
184
- // here.
185
- let origin = self . infcx . const_unification_table . borrow_mut ( )
186
- . probe_value ( vid)
187
- . origin ;
201
+ if let ty:: Const { val : ConstValue :: Infer ( ty:: InferConst :: Var ( vid) ) , ty } = ct {
202
+ if self . const_vars . 0 . contains ( & vid) {
203
+ // This variable was created during the fudging.
204
+ // Recreate it with a fresh variable here.
205
+ let idx = ( vid. index - self . const_vars . 0 . start . index ) as usize ;
206
+ let origin = self . const_vars . 1 [ idx] ;
188
207
self . infcx . next_const_var ( ty, origin)
189
208
} else {
190
209
ct
0 commit comments