@@ -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,8 @@ 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) ?;
2180+ write ! ( f, " " ) ?;
21652181 }
21662182 write ! ( f, "{mutability}" ) ?;
21672183 ref_. ty . hir_fmt ( f, store) ?;
@@ -2255,9 +2271,7 @@ impl HirDisplayWithExpressionStore for TypeBound {
22552271 }
22562272 store[ path] . hir_fmt ( f, store)
22572273 }
2258- TypeBound :: Lifetime ( lifetime) => {
2259- write ! ( f, "{}" , lifetime. name. display( f. db. upcast( ) , f. edition( ) ) )
2260- }
2274+ TypeBound :: Lifetime ( lifetime) => lifetime. hir_fmt ( f, store) ,
22612275 TypeBound :: ForLifetime ( lifetimes, path) => {
22622276 let edition = f. edition ( ) ;
22632277 write ! (
@@ -2269,16 +2283,17 @@ impl HirDisplayWithExpressionStore for TypeBound {
22692283 }
22702284 TypeBound :: Use ( args) => {
22712285 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- )
2286+ let last = args. len ( ) . saturating_sub ( 1 ) ;
2287+ for ( idx, arg) in args. iter ( ) . enumerate ( ) {
2288+ match arg {
2289+ UseArgRef :: Lifetime ( lt) => lt. hir_fmt ( f, store) ?,
2290+ UseArgRef :: Name ( n) => write ! ( f, "{}" , n. display( f. db. upcast( ) , edition) ) ?,
2291+ }
2292+ if idx != last {
2293+ write ! ( f, ", " ) ?;
2294+ }
2295+ }
2296+ write ! ( f, "> " )
22822297 }
22832298 TypeBound :: Error => write ! ( f, "{{error}}" ) ,
22842299 }
@@ -2449,9 +2464,7 @@ impl HirDisplayWithExpressionStore for hir_def::expr_store::path::GenericArg {
24492464 // write!(f, "{}", c.display(f.db.upcast(), f.edition()))
24502465 write ! ( f, "<expr>" )
24512466 }
2452- hir_def:: expr_store:: path:: GenericArg :: Lifetime ( lifetime) => {
2453- write ! ( f, "{}" , lifetime. name. display( f. db. upcast( ) , f. edition( ) ) )
2454- }
2467+ hir_def:: expr_store:: path:: GenericArg :: Lifetime ( lifetime) => lifetime. hir_fmt ( f, store) ,
24552468 }
24562469 }
24572470}
0 commit comments