@@ -55,17 +55,19 @@ use hir_def::{
55
55
use hir_expand:: { name:: name, MacroCallKind } ;
56
56
use hir_ty:: {
57
57
autoderef,
58
- consteval:: { eval_const, ComputedExpr , ConstEvalCtx , ConstEvalError , ConstExt } ,
58
+ consteval:: {
59
+ eval_const, unknown_const_as_generic, ComputedExpr , ConstEvalCtx , ConstEvalError , ConstExt ,
60
+ } ,
59
61
could_unify,
60
62
diagnostics:: BodyValidationDiagnostic ,
61
63
method_resolution:: { self , TyFingerprint } ,
62
64
primitive:: UintTy ,
63
65
subst_prefix,
64
66
traits:: FnTrait ,
65
67
AliasEq , AliasTy , BoundVar , CallableDefId , CallableSig , Canonical , CanonicalVarKinds , Cast ,
66
- DebruijnIndex , InEnvironment , Interner , QuantifiedWhereClause , Scalar , Solution , Substitution ,
67
- TraitEnvironment , TraitRefExt , Ty , TyBuilder , TyDefId , TyExt , TyKind , TyVariableKind ,
68
- WhereClause ,
68
+ DebruijnIndex , GenericArgData , InEnvironment , Interner , ParamKind , QuantifiedWhereClause ,
69
+ Scalar , Solution , Substitution , TraitEnvironment , TraitRefExt , Ty , TyBuilder , TyDefId , TyExt ,
70
+ TyKind , TyVariableKind , WhereClause ,
69
71
} ;
70
72
use itertools:: Itertools ;
71
73
use nameres:: diagnostics:: DefDiagnosticKind ;
@@ -796,7 +798,7 @@ impl Field {
796
798
VariantDef :: Union ( it) => it. id . into ( ) ,
797
799
VariantDef :: Variant ( it) => it. parent . id . into ( ) ,
798
800
} ;
799
- let substs = TyBuilder :: type_params_subst ( db, generic_def_id) ;
801
+ let substs = TyBuilder :: placeholder_subst ( db, generic_def_id) ;
800
802
let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
801
803
Type :: new ( db, self . parent . module ( db) . id . krate ( ) , var_id, ty)
802
804
}
@@ -983,7 +985,10 @@ impl_from!(Struct, Union, Enum for Adt);
983
985
impl Adt {
984
986
pub fn has_non_default_type_params ( self , db : & dyn HirDatabase ) -> bool {
985
987
let subst = db. generic_defaults ( self . into ( ) ) ;
986
- subst. iter ( ) . any ( |ty| ty. skip_binders ( ) . is_unknown ( ) )
988
+ subst. iter ( ) . any ( |ty| match ty. skip_binders ( ) . data ( Interner ) {
989
+ GenericArgData :: Ty ( x) => x. is_unknown ( ) ,
990
+ _ => false ,
991
+ } )
987
992
}
988
993
989
994
/// Turns this ADT into a type. Any type parameters of the ADT will be
@@ -1680,7 +1685,10 @@ pub struct TypeAlias {
1680
1685
impl TypeAlias {
1681
1686
pub fn has_non_default_type_params ( self , db : & dyn HirDatabase ) -> bool {
1682
1687
let subst = db. generic_defaults ( self . id . into ( ) ) ;
1683
- subst. iter ( ) . any ( |ty| ty. skip_binders ( ) . is_unknown ( ) )
1688
+ subst. iter ( ) . any ( |ty| match ty. skip_binders ( ) . data ( Interner ) {
1689
+ GenericArgData :: Ty ( x) => x. is_unknown ( ) ,
1690
+ _ => false ,
1691
+ } )
1684
1692
}
1685
1693
1686
1694
pub fn module ( self , db : & dyn HirDatabase ) -> Module {
@@ -2047,7 +2055,7 @@ impl_from!(
2047
2055
impl GenericDef {
2048
2056
pub fn params ( self , db : & dyn HirDatabase ) -> Vec < GenericParam > {
2049
2057
let generics = db. generic_params ( self . into ( ) ) ;
2050
- let ty_params = generics. tocs . iter ( ) . map ( |( local_id, _) | {
2058
+ let ty_params = generics. type_or_consts . iter ( ) . map ( |( local_id, _) | {
2051
2059
let toc = TypeOrConstParam { id : TypeOrConstParamId { parent : self . into ( ) , local_id } } ;
2052
2060
match toc. split ( db) {
2053
2061
Either :: Left ( x) => GenericParam :: ConstParam ( x) ,
@@ -2067,7 +2075,7 @@ impl GenericDef {
2067
2075
pub fn type_params ( self , db : & dyn HirDatabase ) -> Vec < TypeOrConstParam > {
2068
2076
let generics = db. generic_params ( self . into ( ) ) ;
2069
2077
generics
2070
- . tocs
2078
+ . type_or_consts
2071
2079
. iter ( )
2072
2080
. map ( |( local_id, _) | TypeOrConstParam {
2073
2081
id : TypeOrConstParamId { parent : self . into ( ) , local_id } ,
@@ -2351,9 +2359,14 @@ impl TypeParam {
2351
2359
let resolver = self . id . parent ( ) . resolver ( db. upcast ( ) ) ;
2352
2360
let krate = self . id . parent ( ) . module ( db. upcast ( ) ) . krate ( ) ;
2353
2361
let ty = params. get ( local_idx) ?. clone ( ) ;
2354
- let subst = TyBuilder :: type_params_subst ( db, self . id . parent ( ) ) ;
2362
+ let subst = TyBuilder :: placeholder_subst ( db, self . id . parent ( ) ) ;
2355
2363
let ty = ty. substitute ( Interner , & subst_prefix ( & subst, local_idx) ) ;
2356
- Some ( Type :: new_with_resolver_inner ( db, krate, & resolver, ty) )
2364
+ match ty. data ( Interner ) {
2365
+ GenericArgData :: Ty ( x) => {
2366
+ Some ( Type :: new_with_resolver_inner ( db, krate, & resolver, x. clone ( ) ) )
2367
+ }
2368
+ _ => None ,
2369
+ }
2357
2370
}
2358
2371
}
2359
2372
@@ -2389,7 +2402,7 @@ impl ConstParam {
2389
2402
2390
2403
pub fn name ( self , db : & dyn HirDatabase ) -> Name {
2391
2404
let params = db. generic_params ( self . id . parent ( ) ) ;
2392
- match params. tocs [ self . id . local_id ( ) ] . name ( ) {
2405
+ match params. type_or_consts [ self . id . local_id ( ) ] . name ( ) {
2393
2406
Some ( x) => x. clone ( ) ,
2394
2407
None => {
2395
2408
never ! ( ) ;
@@ -2421,7 +2434,7 @@ pub struct TypeOrConstParam {
2421
2434
impl TypeOrConstParam {
2422
2435
pub fn name ( self , db : & dyn HirDatabase ) -> Name {
2423
2436
let params = db. generic_params ( self . id . parent ) ;
2424
- match params. tocs [ self . id . local_id ] . name ( ) {
2437
+ match params. type_or_consts [ self . id . local_id ] . name ( ) {
2425
2438
Some ( n) => n. clone ( ) ,
2426
2439
_ => Name :: missing ( ) ,
2427
2440
}
@@ -2437,12 +2450,12 @@ impl TypeOrConstParam {
2437
2450
2438
2451
pub fn split ( self , db : & dyn HirDatabase ) -> Either < ConstParam , TypeParam > {
2439
2452
let params = db. generic_params ( self . id . parent ) ;
2440
- match & params. tocs [ self . id . local_id ] {
2453
+ match & params. type_or_consts [ self . id . local_id ] {
2441
2454
hir_def:: generics:: TypeOrConstParamData :: TypeParamData ( _) => {
2442
- Either :: Right ( TypeParam { id : self . id . into ( ) } )
2455
+ Either :: Right ( TypeParam { id : TypeParamId :: from_unchecked ( self . id ) } )
2443
2456
}
2444
2457
hir_def:: generics:: TypeOrConstParamData :: ConstParamData ( _) => {
2445
- Either :: Left ( ConstParam { id : self . id . into ( ) } )
2458
+ Either :: Left ( ConstParam { id : ConstParamId :: from_unchecked ( self . id ) } )
2446
2459
}
2447
2460
}
2448
2461
}
@@ -2688,9 +2701,19 @@ impl Type {
2688
2701
}
2689
2702
2690
2703
pub fn impls_trait ( & self , db : & dyn HirDatabase , trait_ : Trait , args : & [ Type ] ) -> bool {
2704
+ let mut it = args. iter ( ) . map ( |t| t. ty . clone ( ) ) ;
2691
2705
let trait_ref = TyBuilder :: trait_ref ( db, trait_. id )
2692
2706
. push ( self . ty . clone ( ) )
2693
- . fill ( args. iter ( ) . map ( |t| t. ty . clone ( ) ) )
2707
+ . fill ( |x| {
2708
+ let r = it. next ( ) . unwrap ( ) ;
2709
+ match x {
2710
+ ParamKind :: Type => GenericArgData :: Ty ( r) . intern ( Interner ) ,
2711
+ ParamKind :: Const ( ty) => {
2712
+ // FIXME: this code is not covered in tests.
2713
+ unknown_const_as_generic ( ty. clone ( ) )
2714
+ }
2715
+ }
2716
+ } )
2694
2717
. build ( ) ;
2695
2718
2696
2719
let goal = Canonical {
@@ -2707,9 +2730,18 @@ impl Type {
2707
2730
args : & [ Type ] ,
2708
2731
alias : TypeAlias ,
2709
2732
) -> Option < Type > {
2733
+ let mut args = args. iter ( ) ;
2710
2734
let projection = TyBuilder :: assoc_type_projection ( db, alias. id )
2711
2735
. push ( self . ty . clone ( ) )
2712
- . fill ( args. iter ( ) . map ( |t| t. ty . clone ( ) ) )
2736
+ . fill ( |x| {
2737
+ // FIXME: this code is not covered in tests.
2738
+ match x {
2739
+ ParamKind :: Type => {
2740
+ GenericArgData :: Ty ( args. next ( ) . unwrap ( ) . ty . clone ( ) ) . intern ( Interner )
2741
+ }
2742
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2743
+ }
2744
+ } )
2713
2745
. build ( ) ;
2714
2746
let goal = hir_ty:: make_canonical (
2715
2747
InEnvironment :: new (
0 commit comments