@@ -24,7 +24,9 @@ use hir_def::{
24
24
lang_item:: { LangItem , LangItemTarget } ,
25
25
nameres:: DefMap ,
26
26
signatures:: VariantFields ,
27
- type_ref:: { ConstRef , TraitBoundModifier , TypeBound , TypeRef , TypeRefId , UseArgRef } ,
27
+ type_ref:: {
28
+ ConstRef , LifetimeRef , TraitBoundModifier , TypeBound , TypeRef , TypeRefId , UseArgRef ,
29
+ } ,
28
30
visibility:: Visibility ,
29
31
} ;
30
32
use hir_expand:: { mod_path:: PathKind , name:: Name } ;
@@ -2100,7 +2102,20 @@ impl<T: HirDisplayWithExpressionStore> HirDisplay for ExpressionStoreAdapter<'_,
2100
2102
T :: hir_fmt ( & self . 0 , f, self . 1 )
2101
2103
}
2102
2104
}
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 :: Placeholder => write ! ( f, "'_" ) ,
2115
+ LifetimeRef :: Error => write ! ( f, "'{{error}}" ) ,
2116
+ }
2117
+ }
2118
+ }
2104
2119
impl HirDisplayWithExpressionStore for TypeRefId {
2105
2120
fn hir_fmt (
2106
2121
& self ,
@@ -2161,7 +2176,8 @@ impl HirDisplayWithExpressionStore for TypeRefId {
2161
2176
} ;
2162
2177
write ! ( f, "&" ) ?;
2163
2178
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, " " ) ?;
2165
2181
}
2166
2182
write ! ( f, "{mutability}" ) ?;
2167
2183
ref_. ty . hir_fmt ( f, store) ?;
@@ -2255,9 +2271,7 @@ impl HirDisplayWithExpressionStore for TypeBound {
2255
2271
}
2256
2272
store[ path] . hir_fmt ( f, store)
2257
2273
}
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) ,
2261
2275
TypeBound :: ForLifetime ( lifetimes, path) => {
2262
2276
let edition = f. edition ( ) ;
2263
2277
write ! (
@@ -2269,16 +2283,17 @@ impl HirDisplayWithExpressionStore for TypeBound {
2269
2283
}
2270
2284
TypeBound :: Use ( args) => {
2271
2285
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, "> " )
2282
2297
}
2283
2298
TypeBound :: Error => write ! ( f, "{{error}}" ) ,
2284
2299
}
@@ -2449,9 +2464,7 @@ impl HirDisplayWithExpressionStore for hir_def::expr_store::path::GenericArg {
2449
2464
// write!(f, "{}", c.display(f.db.upcast(), f.edition()))
2450
2465
write ! ( f, "<expr>" )
2451
2466
}
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) ,
2455
2468
}
2456
2469
}
2457
2470
}
0 commit comments