@@ -9,21 +9,21 @@ use chalk_ir::{
9
9
AdtId , DebruijnIndex , Scalar ,
10
10
} ;
11
11
use hir_def:: {
12
- builtin_type:: BuiltinType , generics:: TypeOrConstParamData , ConstParamId , DefWithBodyId ,
13
- GenericDefId , TraitId , TypeAliasId ,
12
+ builtin_type:: BuiltinType , DefWithBodyId , GenericDefId , GenericParamId , TraitId , TypeAliasId ,
14
13
} ;
15
14
use smallvec:: SmallVec ;
16
15
17
16
use 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 ,
22
21
} ;
23
22
24
23
#[ derive( Debug , Clone , PartialEq , Eq ) ]
25
24
pub enum ParamKind {
26
25
Type ,
26
+ Lifetime ,
27
27
Const ( Ty ) ,
28
28
}
29
29
@@ -107,6 +107,9 @@ impl<D> TyBuilder<D> {
107
107
ParamKind :: Const ( ty) => {
108
108
BoundVar :: new ( debruijn, idx) . to_const ( Interner , ty. clone ( ) ) . cast ( Interner )
109
109
}
110
+ ParamKind :: Lifetime => {
111
+ BoundVar :: new ( debruijn, idx) . to_lifetime ( Interner ) . cast ( Interner )
112
+ }
110
113
} ) ;
111
114
this. vec . extend ( filler. take ( this. remaining ( ) ) . casted ( Interner ) ) ;
112
115
assert_eq ! ( this. remaining( ) , 0 ) ;
@@ -119,6 +122,7 @@ impl<D> TyBuilder<D> {
119
122
let filler = this. param_kinds [ this. vec . len ( ) ..] . iter ( ) . map ( |x| match x {
120
123
ParamKind :: Type => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
121
124
ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
125
+ ParamKind :: Lifetime => error_lifetime ( ) . cast ( Interner ) ,
122
126
} ) ;
123
127
this. vec . extend ( filler. casted ( Interner ) ) ;
124
128
assert_eq ! ( this. remaining( ) , 0 ) ;
@@ -130,6 +134,7 @@ impl<D> TyBuilder<D> {
130
134
self . fill ( |x| match x {
131
135
ParamKind :: Type => table. new_type_var ( ) . cast ( Interner ) ,
132
136
ParamKind :: Const ( ty) => table. new_const_var ( ty. clone ( ) ) . cast ( Interner ) ,
137
+ ParamKind :: Lifetime => table. new_lifetime_var ( ) . cast ( Interner ) ,
133
138
} )
134
139
}
135
140
@@ -142,7 +147,8 @@ impl<D> TyBuilder<D> {
142
147
fn assert_match_kind ( & self , a : & chalk_ir:: GenericArg < Interner > , e : & ParamKind ) {
143
148
match ( a. data ( Interner ) , e) {
144
149
( GenericArgData :: Ty ( _) , ParamKind :: Type )
145
- | ( GenericArgData :: Const ( _) , ParamKind :: Const ( _) ) => ( ) ,
150
+ | ( GenericArgData :: Const ( _) , ParamKind :: Const ( _) )
151
+ | ( GenericArgData :: Lifetime ( _) , ParamKind :: Lifetime ) => ( ) ,
146
152
_ => panic ! ( "Mismatched kinds: {a:?}, {:?}, {:?}" , self . vec, self . param_kinds) ,
147
153
}
148
154
}
@@ -201,10 +207,11 @@ impl TyBuilder<()> {
201
207
Substitution :: from_iter (
202
208
Interner ,
203
209
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) => {
206
212
unknown_const_as_generic ( db. const_param_ty ( id) ) . cast ( Interner )
207
213
}
214
+ GenericParamId :: LifetimeParamId ( _) => error_lifetime ( ) . cast ( Interner ) ,
208
215
} ) ,
209
216
)
210
217
}
@@ -219,11 +226,10 @@ impl TyBuilder<()> {
219
226
assert ! ( generics. parent_generics( ) . is_some( ) == parent_subst. is_some( ) ) ;
220
227
let params = generics
221
228
. 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 ,
227
233
} )
228
234
. collect ( ) ;
229
235
TyBuilder :: new ( ( ) , params, parent_subst)
0 commit comments