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