@@ -34,9 +34,9 @@ use hir_def::{
3434 ConstRef , LifetimeRef , TraitBoundModifier , TraitRef as HirTraitRef , TypeBound , TypeRef ,
3535 } ,
3636 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 ,
4040} ;
4141use hir_expand:: { name:: Name , ExpandResult } ;
4242use intern:: Interned ;
@@ -377,15 +377,20 @@ impl<'a> TyLoweringContext<'a> {
377377 list_params,
378378 const_params,
379379 _impl_trait_params,
380+ lifetime_params,
380381 ) = if let Some ( def) = self . resolver . generic_def ( ) {
381382 let generics = generics ( self . db . upcast ( ) , def) ;
382383 generics. provenance_split ( )
383384 } else {
384- ( 0 , 0 , 0 , 0 , 0 )
385+ ( 0 , 0 , 0 , 0 , 0 , 0 )
385386 } ;
386387 TyKind :: BoundVar ( BoundVar :: new (
387388 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,
389394 ) )
390395 . intern ( Interner )
391396 }
@@ -818,14 +823,21 @@ impl<'a> TyLoweringContext<'a> {
818823 return Substitution :: empty ( Interner ) ;
819824 } ;
820825 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;
824836 let total_len = parent_params + item_len;
825837
826838 let ty_error = TyKind :: Error . intern ( Interner ) . cast ( Interner ) ;
827839
828- let mut def_generic_iter = def_generics. iter_id ( ) ;
840+ let mut def_generic_iter = def_generics. iter_id_with_lt ( ) ;
829841
830842 let fill_self_params = || {
831843 for x in explicit_self_ty
@@ -835,7 +847,10 @@ impl<'a> TyLoweringContext<'a> {
835847 . take ( self_params)
836848 {
837849 if let Some ( id) = def_generic_iter. next ( ) {
838- assert ! ( id. is_left( ) ) ;
850+ assert ! ( matches!(
851+ id,
852+ GenericParamId :: TypeParamId ( _) | GenericParamId :: LifetimeParamId ( _)
853+ ) ) ;
839854 substs. push ( x) ;
840855 }
841856 }
@@ -847,19 +862,13 @@ impl<'a> TyLoweringContext<'a> {
847862 fill_self_params ( ) ;
848863 }
849864 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
851866 } else {
852867 type_params + const_params
853868 } ;
854869 let skip = if generic_args. has_self_type && self_params == 0 { 1 } else { 0 } ;
855870 // 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) {
863872 if let Some ( id) = def_generic_iter. next ( ) {
864873 if let Some ( x) = generic_arg_to_chalk (
865874 self . db ,
@@ -868,6 +877,7 @@ impl<'a> TyLoweringContext<'a> {
868877 & mut ( ) ,
869878 |_, type_ref| self . lower_ty ( type_ref) ,
870879 |_, const_ref, ty| self . lower_const ( const_ref, ty) ,
880+ |_, lifetime_ref| self . lower_lifetime ( lifetime_ref) ,
871881 ) {
872882 had_explicit_args = true ;
873883 substs. push ( x) ;
@@ -883,9 +893,12 @@ impl<'a> TyLoweringContext<'a> {
883893
884894 // These params include those of parent.
885895 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 ) ,
889902 } )
890903 . collect ( ) ;
891904 assert_eq ! ( remaining_params. len( ) + substs. len( ) , total_len) ;
@@ -1719,7 +1732,7 @@ pub(crate) fn generic_defaults_query(
17191732 let generic_params = generics ( db. upcast ( ) , def) ;
17201733 let parent_start_idx = generic_params. len_self ( ) ;
17211734
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) ) | {
17231736 match p {
17241737 TypeOrConstParamData :: TypeParamData ( p) => {
17251738 let mut ty =
@@ -1747,7 +1760,14 @@ pub(crate) fn generic_defaults_query(
17471760 make_binders ( db, & generic_params, val)
17481761 }
17491762 }
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) ) ;
17511771
17521772 defaults
17531773}
@@ -2127,23 +2147,29 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut
21272147/// Returns `Some` of the lowered generic arg. `None` if the provided arg is a lifetime.
21282148pub ( crate ) fn generic_arg_to_chalk < ' a , T > (
21292149 db : & dyn HirDatabase ,
2130- kind_id : Either < TypeParamId , ConstParamId > ,
2150+ kind_id : GenericParamId ,
21312151 arg : & ' a GenericArg ,
21322152 this : & mut T ,
21332153 for_type : impl FnOnce ( & mut T , & TypeRef ) -> Ty + ' a ,
21342154 for_const : impl FnOnce ( & mut T , & ConstRef , Ty ) -> Const + ' a ,
2155+ for_lifetime : impl FnOnce ( & mut T , & LifetimeRef ) -> Lifetime + ' a ,
21352156) -> Option < crate :: GenericArg > {
21362157 let kind = match kind_id {
2137- Either :: Left ( _) => ParamKind :: Type ,
2138- Either :: Right ( id) => {
2158+ GenericParamId :: TypeParamId ( _) => ParamKind :: Type ,
2159+ GenericParamId :: ConstParamId ( id) => {
21392160 let ty = db. const_param_ty ( id) ;
21402161 ParamKind :: Const ( ty)
21412162 }
2163+ GenericParamId :: LifetimeParamId ( _) => ParamKind :: Lifetime ,
21422164 } ;
21432165 Some ( match ( arg, kind) {
21442166 ( GenericArg :: Type ( type_ref) , ParamKind :: Type ) => for_type ( this, type_ref) . cast ( Interner ) ,
21452167 ( 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+ }
21462171 ( GenericArg :: Const ( _) , ParamKind :: Type ) => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
2172+ ( GenericArg :: Lifetime ( _) , ParamKind :: Type ) => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
21472173 ( GenericArg :: Type ( t) , ParamKind :: Const ( c_ty) ) => {
21482174 // We want to recover simple idents, which parser detects them
21492175 // 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>(
21592185 }
21602186 unknown_const_as_generic ( c_ty)
21612187 }
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 ) ,
21632191 } )
21642192}
21652193
0 commit comments