@@ -24,7 +24,9 @@ use hir_def::{
2424 lang_item:: { LangItem , LangItemTarget } ,
2525 nameres:: DefMap ,
2626 signatures:: VariantFields ,
27- type_ref:: { ConstRef , TraitBoundModifier , TypeBound , TypeRef , TypeRefId , UseArgRef } ,
27+ type_ref:: {
28+ ConstRef , LifetimeRef , TraitBoundModifier , TypeBound , TypeRef , TypeRefId , UseArgRef ,
29+ } ,
2830 visibility:: Visibility ,
2931} ;
3032use hir_expand:: { mod_path:: PathKind , name:: Name } ;
@@ -2100,7 +2102,20 @@ impl<T: HirDisplayWithExpressionStore> HirDisplay for ExpressionStoreAdapter<'_,
21002102 T :: hir_fmt ( & self . 0 , f, self . 1 )
21012103 }
21022104}
2103-
2105+ impl HirDisplayWithExpressionStore for LifetimeRef {
2106+ fn hir_fmt (
2107+ & self ,
2108+ f : & mut HirFormatter < ' _ > ,
2109+ _store : & ExpressionStore ,
2110+ ) -> Result < ( ) , HirDisplayError > {
2111+ match self {
2112+ LifetimeRef :: Named ( name) => write ! ( f, "{}" , name. display( f. db. upcast( ) , f. edition( ) ) ) ,
2113+ LifetimeRef :: Static => write ! ( f, "'static" ) ,
2114+ LifetimeRef :: Infer => write ! ( f, "'_" ) ,
2115+ LifetimeRef :: Error => write ! ( f, "'{{error}}" ) ,
2116+ }
2117+ }
2118+ }
21042119impl HirDisplayWithExpressionStore for TypeRefId {
21052120 fn hir_fmt (
21062121 & self ,
@@ -2161,7 +2176,7 @@ impl HirDisplayWithExpressionStore for TypeRefId {
21612176 } ;
21622177 write ! ( f, "&" ) ?;
21632178 if let Some ( lifetime) = & ref_. lifetime {
2164- write ! ( f , "{} " , lifetime. name . display ( f . db . upcast ( ) , f . edition ( ) ) ) ?;
2179+ lifetime. hir_fmt ( f , store ) ?;
21652180 }
21662181 write ! ( f, "{mutability}" ) ?;
21672182 ref_. ty . hir_fmt ( f, store) ?;
@@ -2255,9 +2270,7 @@ impl HirDisplayWithExpressionStore for TypeBound {
22552270 }
22562271 store[ path] . hir_fmt ( f, store)
22572272 }
2258- TypeBound :: Lifetime ( lifetime) => {
2259- write ! ( f, "{}" , lifetime. name. display( f. db. upcast( ) , f. edition( ) ) )
2260- }
2273+ TypeBound :: Lifetime ( lifetime) => lifetime. hir_fmt ( f, store) ,
22612274 TypeBound :: ForLifetime ( lifetimes, path) => {
22622275 let edition = f. edition ( ) ;
22632276 write ! (
@@ -2269,16 +2282,17 @@ impl HirDisplayWithExpressionStore for TypeBound {
22692282 }
22702283 TypeBound :: Use ( args) => {
22712284 let edition = f. edition ( ) ;
2272- write ! (
2273- f,
2274- "use<{}> " ,
2275- args. iter( )
2276- . map( |it| match it {
2277- UseArgRef :: Lifetime ( lt) => lt. name. display( f. db. upcast( ) , edition) ,
2278- UseArgRef :: Name ( n) => n. display( f. db. upcast( ) , edition) ,
2279- } )
2280- . format( ", " )
2281- )
2285+ let last = args. len ( ) . saturating_sub ( 1 ) ;
2286+ for ( idx, arg) in args. iter ( ) . enumerate ( ) {
2287+ match arg {
2288+ UseArgRef :: Lifetime ( lt) => lt. hir_fmt ( f, store) ?,
2289+ UseArgRef :: Name ( n) => write ! ( f, "{}" , n. display( f. db. upcast( ) , edition) ) ?,
2290+ }
2291+ if idx != last {
2292+ write ! ( f, ", " ) ?;
2293+ }
2294+ }
2295+ write ! ( f, "> " )
22822296 }
22832297 TypeBound :: Error => write ! ( f, "{{error}}" ) ,
22842298 }
@@ -2449,9 +2463,7 @@ impl HirDisplayWithExpressionStore for hir_def::expr_store::path::GenericArg {
24492463 // write!(f, "{}", c.display(f.db.upcast(), f.edition()))
24502464 write ! ( f, "<expr>" )
24512465 }
2452- hir_def:: expr_store:: path:: GenericArg :: Lifetime ( lifetime) => {
2453- write ! ( f, "{}" , lifetime. name. display( f. db. upcast( ) , f. edition( ) ) )
2454- }
2466+ hir_def:: expr_store:: path:: GenericArg :: Lifetime ( lifetime) => lifetime. hir_fmt ( f, store) ,
24552467 }
24562468 }
24572469}
0 commit comments