@@ -29,8 +29,10 @@ use hir_def::{
2929 lang_item:: LangItem ,
3030 nameres:: MacroSubNs ,
3131 path:: { GenericArg , GenericArgs , ModPath , Path , PathKind , PathSegment , PathSegments } ,
32- resolver:: { HasResolver , Resolver , TypeNs } ,
33- type_ref:: { ConstRef , TraitBoundModifier , TraitRef as HirTraitRef , TypeBound , TypeRef } ,
32+ resolver:: { HasResolver , LifetimeNs , Resolver , TypeNs } ,
33+ type_ref:: {
34+ ConstRef , LifetimeRef , TraitBoundModifier , TraitRef as HirTraitRef , TypeBound , TypeRef ,
35+ } ,
3436 AdtId , AssocItemId , ConstId , ConstParamId , DefWithBodyId , EnumId , EnumVariantId , FunctionId ,
3537 GenericDefId , HasModule , ImplId , InTypeConstLoc , ItemContainerId , LocalFieldId , Lookup ,
3638 ModuleDefId , StaticId , StructId , TraitId , TypeAliasId , TypeOrConstParamId , TypeOwnerId ,
@@ -53,17 +55,17 @@ use crate::{
5355 } ,
5456 db:: HirDatabase ,
5557 make_binders,
56- mapping:: { from_chalk_trait_id, ToChalk } ,
58+ mapping:: { from_chalk_trait_id, lt_to_placeholder_idx , ToChalk } ,
5759 static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
58- utils:: Generics ,
5960 utils:: {
60- all_super_trait_refs, associated_type_by_name_including_super_traits, generics,
61+ all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics ,
6162 InTypeConstIdMetadata ,
6263 } ,
6364 AliasEq , AliasTy , Binders , BoundVar , CallableSig , Const , ConstScalar , DebruijnIndex , DynTy ,
64- FnAbi , FnPointer , FnSig , FnSubst , ImplTrait , ImplTraitId , ImplTraits , Interner , ParamKind ,
65- PolyFnSig , ProjectionTy , QuantifiedWhereClause , QuantifiedWhereClauses , Substitution ,
66- TraitEnvironment , TraitRef , TraitRefExt , Ty , TyBuilder , TyKind , WhereClause ,
65+ FnAbi , FnPointer , FnSig , FnSubst , ImplTrait , ImplTraitId , ImplTraits , Interner , Lifetime ,
66+ LifetimeData , ParamKind , PolyFnSig , ProjectionTy , QuantifiedWhereClause ,
67+ QuantifiedWhereClauses , Substitution , TraitEnvironment , TraitRef , TraitRefExt , Ty , TyBuilder ,
68+ TyKind , WhereClause ,
6769} ;
6870
6971#[ derive( Debug ) ]
@@ -275,9 +277,10 @@ impl<'a> TyLoweringContext<'a> {
275277 let inner_ty = self . lower_ty ( inner) ;
276278 TyKind :: Slice ( inner_ty) . intern ( Interner )
277279 }
278- TypeRef :: Reference ( inner, _ , mutability) => {
280+ TypeRef :: Reference ( inner, lifetime , mutability) => {
279281 let inner_ty = self . lower_ty ( inner) ;
280- let lifetime = static_lifetime ( ) ;
282+ let lifetime =
283+ lifetime. as_ref ( ) . map_or_else ( static_lifetime, |lr| self . lower_lifetime ( lr) ) ;
281284 TyKind :: Ref ( lower_to_chalk_mutability ( * mutability) , lifetime, inner_ty)
282285 . intern ( Interner )
283286 }
@@ -1309,6 +1312,33 @@ impl<'a> TyLoweringContext<'a> {
13091312 } ) ;
13101313 ImplTrait { bounds : crate :: make_single_type_binders ( predicates) }
13111314 }
1315+
1316+ fn lower_lifetime ( & self , lifetime : & LifetimeRef ) -> Lifetime {
1317+ match self . resolver . resolve_lifetime ( lifetime) {
1318+ Some ( resolution) => match resolution {
1319+ LifetimeNs :: Static => static_lifetime ( ) ,
1320+ LifetimeNs :: LifetimeParam ( id) => match self . type_param_mode {
1321+ ParamLoweringMode :: Placeholder => {
1322+ LifetimeData :: Placeholder ( lt_to_placeholder_idx ( self . db , id) )
1323+ }
1324+ ParamLoweringMode :: Variable => {
1325+ let generics = generics (
1326+ self . db . upcast ( ) ,
1327+ self . resolver . generic_def ( ) . expect ( "generics in scope" ) ,
1328+ ) ;
1329+ let idx = match generics. lifetime_idx ( id) {
1330+ None => return static_lifetime ( ) ,
1331+ Some ( idx) => idx,
1332+ } ;
1333+
1334+ LifetimeData :: BoundVar ( BoundVar :: new ( self . in_binders , idx) )
1335+ }
1336+ }
1337+ . intern ( Interner ) ,
1338+ } ,
1339+ None => static_lifetime ( ) ,
1340+ }
1341+ }
13121342}
13131343
13141344fn count_impl_traits ( type_ref : & TypeRef ) -> usize {
0 commit comments