@@ -34,9 +34,9 @@ use hir_def::{
34
34
ConstRef , LifetimeRef , TraitBoundModifier , TraitRef as HirTraitRef , TypeBound , TypeRef ,
35
35
} ,
36
36
AdtId , AssocItemId , ConstId , ConstParamId , DefWithBodyId , EnumId , EnumVariantId , FunctionId ,
37
- GenericDefId , HasModule , ImplId , InTypeConstLoc , ItemContainerId , LocalFieldId , Lookup ,
38
- ModuleDefId , StaticId , StructId , TraitId , TypeAliasId , TypeOrConstParamId , TypeOwnerId ,
39
- TypeParamId , UnionId , VariantId ,
37
+ GenericDefId , GenericParamId , HasModule , ImplId , InTypeConstLoc , ItemContainerId , LocalFieldId ,
38
+ Lookup , ModuleDefId , StaticId , StructId , TraitId , TypeAliasId , TypeOrConstParamId , TypeOwnerId ,
39
+ UnionId , VariantId ,
40
40
} ;
41
41
use hir_expand:: { name:: Name , ExpandResult } ;
42
42
use intern:: Interned ;
@@ -377,15 +377,20 @@ impl<'a> TyLoweringContext<'a> {
377
377
list_params,
378
378
const_params,
379
379
_impl_trait_params,
380
+ lifetime_params,
380
381
) = if let Some ( def) = self . resolver . generic_def ( ) {
381
382
let generics = generics ( self . db . upcast ( ) , def) ;
382
383
generics. provenance_split ( )
383
384
} else {
384
- ( 0 , 0 , 0 , 0 , 0 )
385
+ ( 0 , 0 , 0 , 0 , 0 , 0 )
385
386
} ;
386
387
TyKind :: BoundVar ( BoundVar :: new (
387
388
self . in_binders ,
388
- idx as usize + self_params + list_params + const_params,
389
+ idx as usize
390
+ + self_params
391
+ + list_params
392
+ + const_params
393
+ + lifetime_params,
389
394
) )
390
395
. intern ( Interner )
391
396
}
@@ -818,14 +823,21 @@ impl<'a> TyLoweringContext<'a> {
818
823
return Substitution :: empty ( Interner ) ;
819
824
} ;
820
825
let def_generics = generics ( self . db . upcast ( ) , def) ;
821
- let ( parent_params, self_params, type_params, const_params, impl_trait_params) =
822
- def_generics. provenance_split ( ) ;
823
- let item_len = self_params + type_params + const_params + impl_trait_params;
826
+ let (
827
+ parent_params,
828
+ self_params,
829
+ type_params,
830
+ const_params,
831
+ impl_trait_params,
832
+ lifetime_params,
833
+ ) = def_generics. provenance_split ( ) ;
834
+ let item_len =
835
+ self_params + type_params + const_params + impl_trait_params + lifetime_params;
824
836
let total_len = parent_params + item_len;
825
837
826
838
let ty_error = TyKind :: Error . intern ( Interner ) . cast ( Interner ) ;
827
839
828
- let mut def_generic_iter = def_generics. iter_id ( ) ;
840
+ let mut def_generic_iter = def_generics. iter_id_with_lt ( ) ;
829
841
830
842
let fill_self_params = || {
831
843
for x in explicit_self_ty
@@ -835,7 +847,10 @@ impl<'a> TyLoweringContext<'a> {
835
847
. take ( self_params)
836
848
{
837
849
if let Some ( id) = def_generic_iter. next ( ) {
838
- assert ! ( id. is_left( ) ) ;
850
+ assert ! ( matches!(
851
+ id,
852
+ GenericParamId :: TypeParamId ( _) | GenericParamId :: LifetimeParamId ( _)
853
+ ) ) ;
839
854
substs. push ( x) ;
840
855
}
841
856
}
@@ -847,19 +862,13 @@ impl<'a> TyLoweringContext<'a> {
847
862
fill_self_params ( ) ;
848
863
}
849
864
let expected_num = if generic_args. has_self_type {
850
- self_params + type_params + const_params
865
+ self_params + type_params + const_params + lifetime_params
851
866
} else {
852
867
type_params + const_params
853
868
} ;
854
869
let skip = if generic_args. has_self_type && self_params == 0 { 1 } else { 0 } ;
855
870
// if args are provided, it should be all of them, but we can't rely on that
856
- for arg in generic_args
857
- . args
858
- . iter ( )
859
- . filter ( |arg| !matches ! ( arg, GenericArg :: Lifetime ( _) ) )
860
- . skip ( skip)
861
- . take ( expected_num)
862
- {
871
+ for arg in generic_args. args . iter ( ) . skip ( skip) . take ( expected_num) {
863
872
if let Some ( id) = def_generic_iter. next ( ) {
864
873
if let Some ( x) = generic_arg_to_chalk (
865
874
self . db ,
@@ -868,6 +877,7 @@ impl<'a> TyLoweringContext<'a> {
868
877
& mut ( ) ,
869
878
|_, type_ref| self . lower_ty ( type_ref) ,
870
879
|_, const_ref, ty| self . lower_const ( const_ref, ty) ,
880
+ |_, lifetime_ref| self . lower_lifetime ( lifetime_ref) ,
871
881
) {
872
882
had_explicit_args = true ;
873
883
substs. push ( x) ;
@@ -883,9 +893,12 @@ impl<'a> TyLoweringContext<'a> {
883
893
884
894
// These params include those of parent.
885
895
let remaining_params: SmallVec < [ _ ; 2 ] > = def_generic_iter
886
- . map ( |eid| match eid {
887
- Either :: Left ( _) => ty_error. clone ( ) ,
888
- Either :: Right ( x) => unknown_const_as_generic ( self . db . const_param_ty ( x) ) ,
896
+ . map ( |id| match id {
897
+ GenericParamId :: ConstParamId ( x) => {
898
+ unknown_const_as_generic ( self . db . const_param_ty ( x) )
899
+ }
900
+ GenericParamId :: TypeParamId ( _) => ty_error. clone ( ) ,
901
+ GenericParamId :: LifetimeParamId ( _) => error_lifetime ( ) . cast ( Interner ) ,
889
902
} )
890
903
. collect ( ) ;
891
904
assert_eq ! ( remaining_params. len( ) + substs. len( ) , total_len) ;
@@ -1719,7 +1732,7 @@ pub(crate) fn generic_defaults_query(
1719
1732
let generic_params = generics ( db. upcast ( ) , def) ;
1720
1733
let parent_start_idx = generic_params. len_self ( ) ;
1721
1734
1722
- let defaults = Arc :: from_iter ( generic_params. iter ( ) . enumerate ( ) . map ( |( idx, ( id, p) ) | {
1735
+ let toc_iter = generic_params. iter ( ) . enumerate ( ) . map ( |( idx, ( id, p) ) | {
1723
1736
match p {
1724
1737
TypeOrConstParamData :: TypeParamData ( p) => {
1725
1738
let mut ty =
@@ -1747,7 +1760,14 @@ pub(crate) fn generic_defaults_query(
1747
1760
make_binders ( db, & generic_params, val)
1748
1761
}
1749
1762
}
1750
- } ) ) ;
1763
+ } ) ;
1764
+
1765
+ let lt_iter = generic_params
1766
+ . iter_lt ( )
1767
+ . enumerate ( )
1768
+ . map ( |_| make_binders ( db, & generic_params, static_lifetime ( ) . cast ( Interner ) ) ) ;
1769
+
1770
+ let defaults = Arc :: from_iter ( toc_iter. chain ( lt_iter) ) ;
1751
1771
1752
1772
defaults
1753
1773
}
@@ -2127,23 +2147,29 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut
2127
2147
/// Returns `Some` of the lowered generic arg. `None` if the provided arg is a lifetime.
2128
2148
pub ( crate ) fn generic_arg_to_chalk < ' a , T > (
2129
2149
db : & dyn HirDatabase ,
2130
- kind_id : Either < TypeParamId , ConstParamId > ,
2150
+ kind_id : GenericParamId ,
2131
2151
arg : & ' a GenericArg ,
2132
2152
this : & mut T ,
2133
2153
for_type : impl FnOnce ( & mut T , & TypeRef ) -> Ty + ' a ,
2134
2154
for_const : impl FnOnce ( & mut T , & ConstRef , Ty ) -> Const + ' a ,
2155
+ for_lifetime : impl FnOnce ( & mut T , & LifetimeRef ) -> Lifetime + ' a ,
2135
2156
) -> Option < crate :: GenericArg > {
2136
2157
let kind = match kind_id {
2137
- Either :: Left ( _) => ParamKind :: Type ,
2138
- Either :: Right ( id) => {
2158
+ GenericParamId :: TypeParamId ( _) => ParamKind :: Type ,
2159
+ GenericParamId :: ConstParamId ( id) => {
2139
2160
let ty = db. const_param_ty ( id) ;
2140
2161
ParamKind :: Const ( ty)
2141
2162
}
2163
+ GenericParamId :: LifetimeParamId ( _) => ParamKind :: Lifetime ,
2142
2164
} ;
2143
2165
Some ( match ( arg, kind) {
2144
2166
( GenericArg :: Type ( type_ref) , ParamKind :: Type ) => for_type ( this, type_ref) . cast ( Interner ) ,
2145
2167
( GenericArg :: Const ( c) , ParamKind :: Const ( c_ty) ) => for_const ( this, c, c_ty) . cast ( Interner ) ,
2168
+ ( GenericArg :: Lifetime ( lifetime_ref) , ParamKind :: Lifetime ) => {
2169
+ for_lifetime ( this, lifetime_ref) . cast ( Interner )
2170
+ }
2146
2171
( GenericArg :: Const ( _) , ParamKind :: Type ) => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
2172
+ ( GenericArg :: Lifetime ( _) , ParamKind :: Type ) => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
2147
2173
( GenericArg :: Type ( t) , ParamKind :: Const ( c_ty) ) => {
2148
2174
// We want to recover simple idents, which parser detects them
2149
2175
// as types. Maybe here is not the best place to do it, but
@@ -2159,7 +2185,9 @@ pub(crate) fn generic_arg_to_chalk<'a, T>(
2159
2185
}
2160
2186
unknown_const_as_generic ( c_ty)
2161
2187
}
2162
- ( GenericArg :: Lifetime ( _) , _) => return None ,
2188
+ ( GenericArg :: Lifetime ( _) , ParamKind :: Const ( c_ty) ) => unknown_const_as_generic ( c_ty) ,
2189
+ ( GenericArg :: Type ( _) , ParamKind :: Lifetime ) => error_lifetime ( ) . cast ( Interner ) ,
2190
+ ( GenericArg :: Const ( _) , ParamKind :: Lifetime ) => error_lifetime ( ) . cast ( Interner ) ,
2163
2191
} )
2164
2192
}
2165
2193
0 commit comments