@@ -55,8 +55,8 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
55
55
use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
56
56
use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
57
57
use rustc_hir:: {
58
- self as hir, ConstArg , GenericArg , HirId , IsAnonInPath , ItemLocalMap , LangItem , ParamName ,
59
- TraitCandidate ,
58
+ self as hir, ConstArg , GenericArg , HirId , ItemLocalMap , LangItem , LifetimeSource ,
59
+ LifetimeSyntax , ParamName , TraitCandidate ,
60
60
} ;
61
61
use rustc_index:: { Idx , IndexSlice , IndexVec } ;
62
62
use rustc_macros:: extension;
@@ -1080,7 +1080,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1080
1080
itctx : ImplTraitContext ,
1081
1081
) -> hir:: GenericArg < ' hir > {
1082
1082
match arg {
1083
- ast:: GenericArg :: Lifetime ( lt) => GenericArg :: Lifetime ( self . lower_lifetime ( lt) ) ,
1083
+ ast:: GenericArg :: Lifetime ( lt) => GenericArg :: Lifetime ( self . lower_lifetime (
1084
+ lt,
1085
+ LifetimeSource :: Path { with_angle_brackets : true } ,
1086
+ lt. ident . into ( ) ,
1087
+ ) ) ,
1084
1088
ast:: GenericArg :: Type ( ty) => {
1085
1089
// We cannot just match on `TyKind::Infer` as `(_)` is represented as
1086
1090
// `TyKind::Paren(TyKind::Infer)` and should also be lowered to `GenericArg::Infer`
@@ -1199,35 +1203,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1199
1203
TyKind :: Slice ( ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
1200
1204
TyKind :: Ptr ( mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
1201
1205
TyKind :: Ref ( region, mt) => {
1202
- let region = region. unwrap_or_else ( || {
1203
- let id = if let Some ( LifetimeRes :: ElidedAnchor { start, end } ) =
1204
- self . resolver . get_lifetime_res ( t. id )
1205
- {
1206
- debug_assert_eq ! ( start. plus( 1 ) , end) ;
1207
- start
1208
- } else {
1209
- self . next_node_id ( )
1210
- } ;
1211
- let span = self . tcx . sess . source_map ( ) . start_point ( t. span ) . shrink_to_hi ( ) ;
1212
- Lifetime { ident : Ident :: new ( kw:: UnderscoreLifetime , span) , id }
1213
- } ) ;
1214
- let lifetime = self . lower_lifetime ( & region) ;
1206
+ let lifetime = self . lower_ty_direct_lifetime ( t, * region) ;
1215
1207
hir:: TyKind :: Ref ( lifetime, self . lower_mt ( mt, itctx) )
1216
1208
}
1217
1209
TyKind :: PinnedRef ( region, mt) => {
1218
- let region = region. unwrap_or_else ( || {
1219
- let id = if let Some ( LifetimeRes :: ElidedAnchor { start, end } ) =
1220
- self . resolver . get_lifetime_res ( t. id )
1221
- {
1222
- debug_assert_eq ! ( start. plus( 1 ) , end) ;
1223
- start
1224
- } else {
1225
- self . next_node_id ( )
1226
- } ;
1227
- let span = self . tcx . sess . source_map ( ) . start_point ( t. span ) . shrink_to_hi ( ) ;
1228
- Lifetime { ident : Ident :: new ( kw:: UnderscoreLifetime , span) , id }
1229
- } ) ;
1230
- let lifetime = self . lower_lifetime ( & region) ;
1210
+ let lifetime = self . lower_ty_direct_lifetime ( t, * region) ;
1231
1211
let kind = hir:: TyKind :: Ref ( lifetime, self . lower_mt ( mt, itctx) ) ;
1232
1212
let span = self . lower_span ( t. span ) ;
1233
1213
let arg = hir:: Ty { kind, span, hir_id : self . next_id ( ) } ;
@@ -1303,7 +1283,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1303
1283
}
1304
1284
GenericBound :: Outlives ( lifetime) => {
1305
1285
if lifetime_bound. is_none ( ) {
1306
- lifetime_bound = Some ( this. lower_lifetime ( lifetime) ) ;
1286
+ lifetime_bound = Some ( this. lower_lifetime (
1287
+ lifetime,
1288
+ LifetimeSource :: Other ,
1289
+ lifetime. ident . into ( ) ,
1290
+ ) ) ;
1307
1291
}
1308
1292
None
1309
1293
}
@@ -1394,6 +1378,31 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1394
1378
hir:: Ty { kind, span : self . lower_span ( t. span ) , hir_id : self . lower_node_id ( t. id ) }
1395
1379
}
1396
1380
1381
+ fn lower_ty_direct_lifetime (
1382
+ & mut self ,
1383
+ t : & Ty ,
1384
+ region : Option < Lifetime > ,
1385
+ ) -> & ' hir hir:: Lifetime {
1386
+ let ( region, syntax) = match region {
1387
+ Some ( region) => ( region, region. ident . into ( ) ) ,
1388
+
1389
+ None => {
1390
+ let id = if let Some ( LifetimeRes :: ElidedAnchor { start, end } ) =
1391
+ self . resolver . get_lifetime_res ( t. id )
1392
+ {
1393
+ debug_assert_eq ! ( start. plus( 1 ) , end) ;
1394
+ start
1395
+ } else {
1396
+ self . next_node_id ( )
1397
+ } ;
1398
+ let span = self . tcx . sess . source_map ( ) . start_point ( t. span ) . shrink_to_hi ( ) ;
1399
+ let region = Lifetime { ident : Ident :: new ( kw:: UnderscoreLifetime , span) , id } ;
1400
+ ( region, LifetimeSyntax :: Hidden )
1401
+ }
1402
+ } ;
1403
+ self . lower_lifetime ( & region, LifetimeSource :: Reference , syntax)
1404
+ }
1405
+
1397
1406
/// Lowers a `ReturnPositionOpaqueTy` (`-> impl Trait`) or a `TypeAliasesOpaqueTy` (`type F =
1398
1407
/// impl Trait`): this creates the associated Opaque Type (TAIT) definition and then returns a
1399
1408
/// HIR type that references the TAIT.
@@ -1475,9 +1484,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1475
1484
precise_capturing_args : & [ PreciseCapturingArg ] ,
1476
1485
) -> & ' hir [ hir:: PreciseCapturingArg < ' hir > ] {
1477
1486
self . arena . alloc_from_iter ( precise_capturing_args. iter ( ) . map ( |arg| match arg {
1478
- PreciseCapturingArg :: Lifetime ( lt) => {
1479
- hir :: PreciseCapturingArg :: Lifetime ( self . lower_lifetime ( lt) )
1480
- }
1487
+ PreciseCapturingArg :: Lifetime ( lt) => hir :: PreciseCapturingArg :: Lifetime (
1488
+ self . lower_lifetime ( lt, LifetimeSource :: PreciseCapturing , lt . ident . into ( ) ) ,
1489
+ ) ,
1481
1490
PreciseCapturingArg :: Arg ( path, id) => {
1482
1491
let [ segment] = path. segments . as_slice ( ) else {
1483
1492
panic ! ( ) ;
@@ -1745,22 +1754,40 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1745
1754
) -> hir:: GenericBound < ' hir > {
1746
1755
match tpb {
1747
1756
GenericBound :: Trait ( p) => hir:: GenericBound :: Trait ( self . lower_poly_trait_ref ( p, itctx) ) ,
1748
- GenericBound :: Outlives ( lifetime) => {
1749
- hir:: GenericBound :: Outlives ( self . lower_lifetime ( lifetime) )
1750
- }
1757
+ GenericBound :: Outlives ( lifetime) => hir:: GenericBound :: Outlives ( self . lower_lifetime (
1758
+ lifetime,
1759
+ LifetimeSource :: OutlivesBound ,
1760
+ lifetime. ident . into ( ) ,
1761
+ ) ) ,
1751
1762
GenericBound :: Use ( args, span) => hir:: GenericBound :: Use (
1752
1763
self . lower_precise_capturing_args ( args) ,
1753
1764
self . lower_span ( * span) ,
1754
1765
) ,
1755
1766
}
1756
1767
}
1757
1768
1758
- fn lower_lifetime ( & mut self , l : & Lifetime ) -> & ' hir hir:: Lifetime {
1759
- self . new_named_lifetime ( l. id , l. id , l. ident , IsAnonInPath :: No )
1769
+ fn lower_lifetime (
1770
+ & mut self ,
1771
+ l : & Lifetime ,
1772
+ source : LifetimeSource ,
1773
+ syntax : LifetimeSyntax ,
1774
+ ) -> & ' hir hir:: Lifetime {
1775
+ self . new_named_lifetime ( l. id , l. id , l. ident , source, syntax)
1760
1776
}
1761
1777
1762
- fn lower_lifetime_anon_in_path ( & mut self , id : NodeId , span : Span ) -> & ' hir hir:: Lifetime {
1763
- self . new_named_lifetime ( id, id, Ident :: new ( kw:: UnderscoreLifetime , span) , IsAnonInPath :: Yes )
1778
+ fn lower_lifetime_hidden_in_path (
1779
+ & mut self ,
1780
+ id : NodeId ,
1781
+ span : Span ,
1782
+ with_angle_brackets : bool ,
1783
+ ) -> & ' hir hir:: Lifetime {
1784
+ self . new_named_lifetime (
1785
+ id,
1786
+ id,
1787
+ Ident :: new ( kw:: UnderscoreLifetime , span) ,
1788
+ LifetimeSource :: Path { with_angle_brackets } ,
1789
+ LifetimeSyntax :: Hidden ,
1790
+ )
1764
1791
}
1765
1792
1766
1793
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -1769,7 +1796,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1769
1796
id : NodeId ,
1770
1797
new_id : NodeId ,
1771
1798
ident : Ident ,
1772
- is_anon_in_path : IsAnonInPath ,
1799
+ source : LifetimeSource ,
1800
+ syntax : LifetimeSyntax ,
1773
1801
) -> & ' hir hir:: Lifetime {
1774
1802
debug_assert_ne ! ( ident. name, kw:: Empty ) ;
1775
1803
let res = self . resolver . get_lifetime_res ( id) . unwrap_or ( LifetimeRes :: Error ) ;
@@ -1794,17 +1822,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1794
1822
}
1795
1823
} ;
1796
1824
1797
- #[ cfg( debug_assertions) ]
1798
- if is_anon_in_path == IsAnonInPath :: Yes {
1799
- debug_assert_eq ! ( ident. name, kw:: UnderscoreLifetime ) ;
1800
- }
1801
-
1802
1825
debug ! ( ?res) ;
1803
1826
self . arena . alloc ( hir:: Lifetime :: new (
1804
1827
self . lower_node_id ( new_id) ,
1805
1828
self . lower_ident ( ident) ,
1806
1829
res,
1807
- is_anon_in_path,
1830
+ source,
1831
+ syntax,
1808
1832
) )
1809
1833
}
1810
1834
@@ -2393,7 +2417,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2393
2417
self . next_id ( ) ,
2394
2418
Ident :: new ( kw:: UnderscoreLifetime , self . lower_span ( span) ) ,
2395
2419
hir:: LifetimeName :: ImplicitObjectLifetimeDefault ,
2396
- IsAnonInPath :: No ,
2420
+ LifetimeSource :: Other ,
2421
+ LifetimeSyntax :: Hidden ,
2397
2422
) ;
2398
2423
debug ! ( "elided_dyn_bound: r={:?}" , r) ;
2399
2424
self . arena . alloc ( r)
0 commit comments