@@ -9,21 +9,21 @@ use chalk_ir::{
99 AdtId , DebruijnIndex , Scalar ,
1010} ;
1111use hir_def:: {
12- builtin_type:: BuiltinType , generics:: TypeOrConstParamData , ConstParamId , DefWithBodyId ,
13- GenericDefId , TraitId , TypeAliasId ,
12+ builtin_type:: BuiltinType , DefWithBodyId , GenericDefId , GenericParamId , TraitId , TypeAliasId ,
1413} ;
1514use smallvec:: SmallVec ;
1615
1716use crate :: {
18- consteval:: unknown_const_as_generic, db:: HirDatabase , infer :: unify :: InferenceTable , primitive ,
19- to_assoc_type_id, to_chalk_trait_id, utils:: generics, Binders , BoundVar , CallableSig ,
20- GenericArg , GenericArgData , Interner , ProjectionTy , Substitution , TraitRef , Ty , TyDefId , TyExt ,
21- TyKind ,
17+ consteval:: unknown_const_as_generic, db:: HirDatabase , error_lifetime ,
18+ infer :: unify :: InferenceTable , primitive , to_assoc_type_id, to_chalk_trait_id, utils:: generics,
19+ Binders , BoundVar , CallableSig , GenericArg , GenericArgData , Interner , ProjectionTy ,
20+ Substitution , TraitRef , Ty , TyDefId , TyExt , TyKind ,
2221} ;
2322
2423#[ derive( Debug , Clone , PartialEq , Eq ) ]
2524pub enum ParamKind {
2625 Type ,
26+ Lifetime ,
2727 Const ( Ty ) ,
2828}
2929
@@ -107,6 +107,9 @@ impl<D> TyBuilder<D> {
107107 ParamKind :: Const ( ty) => {
108108 BoundVar :: new ( debruijn, idx) . to_const ( Interner , ty. clone ( ) ) . cast ( Interner )
109109 }
110+ ParamKind :: Lifetime => {
111+ BoundVar :: new ( debruijn, idx) . to_lifetime ( Interner ) . cast ( Interner )
112+ }
110113 } ) ;
111114 this. vec . extend ( filler. take ( this. remaining ( ) ) . casted ( Interner ) ) ;
112115 assert_eq ! ( this. remaining( ) , 0 ) ;
@@ -119,6 +122,7 @@ impl<D> TyBuilder<D> {
119122 let filler = this. param_kinds [ this. vec . len ( ) ..] . iter ( ) . map ( |x| match x {
120123 ParamKind :: Type => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
121124 ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
125+ ParamKind :: Lifetime => error_lifetime ( ) . cast ( Interner ) ,
122126 } ) ;
123127 this. vec . extend ( filler. casted ( Interner ) ) ;
124128 assert_eq ! ( this. remaining( ) , 0 ) ;
@@ -130,6 +134,7 @@ impl<D> TyBuilder<D> {
130134 self . fill ( |x| match x {
131135 ParamKind :: Type => table. new_type_var ( ) . cast ( Interner ) ,
132136 ParamKind :: Const ( ty) => table. new_const_var ( ty. clone ( ) ) . cast ( Interner ) ,
137+ ParamKind :: Lifetime => table. new_lifetime_var ( ) . cast ( Interner ) ,
133138 } )
134139 }
135140
@@ -142,7 +147,8 @@ impl<D> TyBuilder<D> {
142147 fn assert_match_kind ( & self , a : & chalk_ir:: GenericArg < Interner > , e : & ParamKind ) {
143148 match ( a. data ( Interner ) , e) {
144149 ( GenericArgData :: Ty ( _) , ParamKind :: Type )
145- | ( GenericArgData :: Const ( _) , ParamKind :: Const ( _) ) => ( ) ,
150+ | ( GenericArgData :: Const ( _) , ParamKind :: Const ( _) )
151+ | ( GenericArgData :: Lifetime ( _) , ParamKind :: Lifetime ) => ( ) ,
146152 _ => panic ! ( "Mismatched kinds: {a:?}, {:?}, {:?}" , self . vec, self . param_kinds) ,
147153 }
148154 }
@@ -201,10 +207,11 @@ impl TyBuilder<()> {
201207 Substitution :: from_iter (
202208 Interner ,
203209 params. iter_id ( ) . map ( |id| match id {
204- either :: Either :: Left ( _) => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
205- either :: Either :: Right ( id) => {
210+ GenericParamId :: TypeParamId ( _) => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
211+ GenericParamId :: ConstParamId ( id) => {
206212 unknown_const_as_generic ( db. const_param_ty ( id) ) . cast ( Interner )
207213 }
214+ GenericParamId :: LifetimeParamId ( _) => error_lifetime ( ) . cast ( Interner ) ,
208215 } ) ,
209216 )
210217 }
@@ -219,11 +226,10 @@ impl TyBuilder<()> {
219226 assert ! ( generics. parent_generics( ) . is_some( ) == parent_subst. is_some( ) ) ;
220227 let params = generics
221228 . iter_self ( )
222- . map ( |( id, data) | match data {
223- TypeOrConstParamData :: TypeParamData ( _) => ParamKind :: Type ,
224- TypeOrConstParamData :: ConstParamData ( _) => {
225- ParamKind :: Const ( db. const_param_ty ( ConstParamId :: from_unchecked ( id) ) )
226- }
229+ . map ( |( id, _data) | match id {
230+ GenericParamId :: TypeParamId ( _) => ParamKind :: Type ,
231+ GenericParamId :: ConstParamId ( id) => ParamKind :: Const ( db. const_param_ty ( id) ) ,
232+ GenericParamId :: LifetimeParamId ( _) => ParamKind :: Lifetime ,
227233 } )
228234 . collect ( ) ;
229235 TyBuilder :: new ( ( ) , params, parent_subst)
0 commit comments