21
21
//!
22
22
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
23
23
24
- use crate :: infer:: { InferCtxt , RegionVariableOrigin , TypeVariableOrigin } ;
24
+ use crate :: infer:: { InferCtxt , RegionVariableOrigin , TypeVariableOrigin , ConstVariableOrigin } ;
25
+ use crate :: mir:: interpret:: ConstValue ;
25
26
use rustc_data_structures:: indexed_vec:: IndexVec ;
26
27
use rustc_macros:: HashStable ;
27
28
use serialize:: UseSpecializedDecodable ;
@@ -30,7 +31,7 @@ use std::ops::Index;
30
31
use syntax:: source_map:: Span ;
31
32
use crate :: ty:: fold:: TypeFoldable ;
32
33
use crate :: ty:: subst:: Kind ;
33
- use crate :: ty:: { self , BoundVar , Lift , List , Region , TyCtxt } ;
34
+ use crate :: ty:: { self , BoundVar , InferConst , Lift , List , Region , TyCtxt } ;
34
35
35
36
mod canonicalizer;
36
37
@@ -115,6 +116,7 @@ impl CanonicalVarInfo {
115
116
CanonicalVarKind :: PlaceholderTy ( _) => false ,
116
117
CanonicalVarKind :: Region ( _) => true ,
117
118
CanonicalVarKind :: PlaceholderRegion ( ..) => false ,
119
+ CanonicalVarKind :: Const ( _) => true ,
118
120
}
119
121
}
120
122
}
@@ -137,6 +139,9 @@ pub enum CanonicalVarKind {
137
139
/// are solving a goal like `for<'a> T: Foo<'a>` to represent the
138
140
/// bound region `'a`.
139
141
PlaceholderRegion ( ty:: PlaceholderRegion ) ,
142
+
143
+ /// Some kind of const inference variable.
144
+ Const ( ty:: UniverseIndex ) ,
140
145
}
141
146
142
147
impl CanonicalVarKind {
@@ -150,6 +155,7 @@ impl CanonicalVarKind {
150
155
CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. universe ,
151
156
CanonicalVarKind :: Region ( ui) => ui,
152
157
CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ,
158
+ CanonicalVarKind :: Const ( ui) => ui,
153
159
}
154
160
}
155
161
}
@@ -388,6 +394,17 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
388
394
} ;
389
395
self . tcx . mk_region ( ty:: RePlaceholder ( placeholder_mapped) ) . into ( )
390
396
}
397
+
398
+ CanonicalVarKind :: Const ( ui) => {
399
+ self . next_const_var_in_universe (
400
+ self . next_ty_var_in_universe (
401
+ TypeVariableOrigin :: MiscVariable ( span) ,
402
+ universe_map ( ui) ,
403
+ ) ,
404
+ ConstVariableOrigin :: MiscVariable ( span) ,
405
+ universe_map ( ui) ,
406
+ ) . into ( )
407
+ }
391
408
}
392
409
}
393
410
}
@@ -443,8 +460,19 @@ impl<'tcx> CanonicalVarValues<'tcx> {
443
460
UnpackedKind :: Lifetime ( ..) => tcx. mk_region (
444
461
ty:: ReLateBound ( ty:: INNERMOST , ty:: BoundRegion :: BrAnon ( i) )
445
462
) . into ( ) ,
446
- UnpackedKind :: Const ( ..) => {
447
- unimplemented ! ( ) // FIXME(const_generics)
463
+ UnpackedKind :: Const ( ct) => {
464
+ let ty = match ct {
465
+ ty:: LazyConst :: Unevaluated ( def_id, _) => {
466
+ tcx. type_of ( * def_id)
467
+ }
468
+ ty:: LazyConst :: Evaluated ( ty:: Const { ty, .. } ) => ty,
469
+ } ;
470
+ tcx. mk_lazy_const ( ty:: LazyConst :: Evaluated ( ty:: Const {
471
+ ty : ty,
472
+ val : ConstValue :: Infer (
473
+ InferConst :: Canonical ( ty:: INNERMOST , ty:: BoundVar :: from_u32 ( i) )
474
+ ) ,
475
+ } ) ) . into ( )
448
476
}
449
477
} )
450
478
. collect ( )
0 commit comments