@@ -15,11 +15,11 @@ use triomphe::Arc;
15
15
16
16
use super :: { InferOk , InferResult , InferenceContext , TypeError } ;
17
17
use crate :: {
18
- db:: HirDatabase , fold_tys , fold_tys_and_consts, static_lifetime, to_chalk_trait_id,
19
- traits :: FnTrait , AliasEq , AliasTy , BoundVar , Canonical , Const , ConstValue , DebruijnIndex ,
20
- GenericArg , GenericArgData , Goal , Guidance , InEnvironment , InferenceVar , Interner , Lifetime ,
21
- ParamKind , ProjectionTy , ProjectionTyExt , Scalar , Solution , Substitution , TraitEnvironment , Ty ,
22
- TyBuilder , TyExt , TyKind , VariableKind ,
18
+ db:: HirDatabase , fold_tys_and_consts, static_lifetime, to_chalk_trait_id, traits :: FnTrait ,
19
+ AliasEq , AliasTy , BoundVar , Canonical , Const , ConstValue , DebruijnIndex , GenericArg ,
20
+ GenericArgData , Goal , Guidance , InEnvironment , InferenceVar , Interner , Lifetime , ParamKind ,
21
+ ProjectionTy , ProjectionTyExt , Scalar , Solution , Substitution , TraitEnvironment , Ty , TyBuilder ,
22
+ TyExt , TyKind , VariableKind ,
23
23
} ;
24
24
25
25
impl < ' a > InferenceContext < ' a > {
@@ -236,13 +236,36 @@ impl<'a> InferenceTable<'a> {
236
236
where
237
237
T : HasInterner < Interner = Interner > + TypeFoldable < Interner > ,
238
238
{
239
- fold_tys (
239
+ fold_tys_and_consts (
240
240
ty,
241
- |ty, _| match ty. kind ( Interner ) {
242
- TyKind :: Alias ( AliasTy :: Projection ( proj_ty) ) => {
243
- self . normalize_projection_ty ( proj_ty. clone ( ) )
244
- }
245
- _ => ty,
241
+ |e, _| match e {
242
+ Either :: Left ( ty) => Either :: Left ( match ty. kind ( Interner ) {
243
+ TyKind :: Alias ( AliasTy :: Projection ( proj_ty) ) => {
244
+ self . normalize_projection_ty ( proj_ty. clone ( ) )
245
+ }
246
+ _ => ty,
247
+ } ) ,
248
+ Either :: Right ( c) => Either :: Right ( match & c. data ( Interner ) . value {
249
+ chalk_ir:: ConstValue :: Concrete ( cc) => match & cc. interned {
250
+ crate :: ConstScalar :: UnevaluatedConst ( c_id, subst) => {
251
+ // FIXME: Ideally here we should do everything that we do with type alias, i.e. adding a variable
252
+ // and registering an obligation. But it needs chalk support, so we handle the most basic
253
+ // case (a non associated const without generic parameters) manually.
254
+ if subst. len ( Interner ) == 0 {
255
+ if let Ok ( eval) = self . db . const_eval ( ( * c_id) . into ( ) , subst. clone ( ) )
256
+ {
257
+ eval
258
+ } else {
259
+ c
260
+ }
261
+ } else {
262
+ c
263
+ }
264
+ }
265
+ _ => c,
266
+ } ,
267
+ _ => c,
268
+ } ) ,
246
269
} ,
247
270
DebruijnIndex :: INNERMOST ,
248
271
)
0 commit comments