@@ -46,14 +46,16 @@ pub enum Region {
46
46
}
47
47
48
48
impl Region {
49
- fn early ( hir_map : & Map , index : & mut u32 , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
49
+ fn early ( hir_map : & Map , index : & mut u32 , def : & hir:: LifetimeDef )
50
+ -> ( hir:: LifetimeName , Region )
51
+ {
50
52
let i = * index;
51
53
* index += 1 ;
52
54
let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
53
55
( def. lifetime . name , Region :: EarlyBound ( i, def_id) )
54
56
}
55
57
56
- fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( ast :: Name , Region ) {
58
+ fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( hir :: LifetimeName , Region ) {
57
59
let depth = ty:: DebruijnIndex :: new ( 1 ) ;
58
60
let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
59
61
( def. lifetime . name , Region :: LateBound ( depth, def_id) )
@@ -198,7 +200,7 @@ enum Scope<'a> {
198
200
/// it should be shifted by the number of `Binder`s in between the
199
201
/// declaration `Binder` and the location it's referenced from.
200
202
Binder {
201
- lifetimes : FxHashMap < ast :: Name , Region > ,
203
+ lifetimes : FxHashMap < hir :: LifetimeName , Region > ,
202
204
s : ScopeRef < ' a >
203
205
} ,
204
206
@@ -654,7 +656,7 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) {
654
656
655
657
Scope :: Binder { ref lifetimes, s } => {
656
658
// FIXME (#24278): non-hygienic comparison
657
- if let Some ( def) = lifetimes. get ( & label) {
659
+ if let Some ( def) = lifetimes. get ( & hir :: LifetimeName :: Name ( label) ) {
658
660
let node_id = hir_map. as_local_node_id ( def. id ( ) . unwrap ( ) )
659
661
. unwrap ( ) ;
660
662
@@ -692,7 +694,7 @@ fn compute_object_lifetime_defaults(sess: &Session, hir_map: &Map)
692
694
Set1 :: Empty => "BaseDefault" . to_string ( ) ,
693
695
Set1 :: One ( Region :: Static ) => "'static" . to_string ( ) ,
694
696
Set1 :: One ( Region :: EarlyBound ( i, _) ) => {
695
- generics. lifetimes [ i as usize ] . lifetime . name . to_string ( )
697
+ generics. lifetimes [ i as usize ] . lifetime . name . name ( ) . to_string ( )
696
698
}
697
699
Set1 :: One ( _) => bug ! ( ) ,
698
700
Set1 :: Many => "Ambiguous" . to_string ( ) ,
@@ -714,7 +716,7 @@ fn compute_object_lifetime_defaults(sess: &Session, hir_map: &Map)
714
716
/// for each type parameter.
715
717
fn object_lifetime_defaults_for_item ( hir_map : & Map , generics : & hir:: Generics )
716
718
-> Vec < ObjectLifetimeDefault > {
717
- fn add_bounds ( set : & mut Set1 < ast :: Name > , bounds : & [ hir:: TyParamBound ] ) {
719
+ fn add_bounds ( set : & mut Set1 < hir :: LifetimeName > , bounds : & [ hir:: TyParamBound ] ) {
718
720
for bound in bounds {
719
721
if let hir:: RegionTyParamBound ( ref lifetime) = * bound {
720
722
set. insert ( lifetime. name ) ;
@@ -754,7 +756,7 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
754
756
match set {
755
757
Set1 :: Empty => Set1 :: Empty ,
756
758
Set1 :: One ( name) => {
757
- if name == "'static" {
759
+ if name == hir :: LifetimeName :: Static {
758
760
Set1 :: One ( Region :: Static )
759
761
} else {
760
762
generics. lifetimes . iter ( ) . enumerate ( ) . find ( |& ( _, def) | {
@@ -922,7 +924,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
922
924
self . insert_lifetime ( lifetime_ref, def) ;
923
925
} else {
924
926
struct_span_err ! ( self . sess, lifetime_ref. span, E0261 ,
925
- "use of undeclared lifetime name `{}`" , lifetime_ref. name)
927
+ "use of undeclared lifetime name `{}`" , lifetime_ref. name. name ( ) )
926
928
. span_label ( lifetime_ref. span , "undeclared lifetime" )
927
929
. emit ( ) ;
928
930
}
@@ -1422,13 +1424,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1422
1424
let lifetime_i = & lifetimes[ i] ;
1423
1425
1424
1426
for lifetime in lifetimes {
1425
- if lifetime. lifetime . is_static ( ) {
1426
- let lifetime = lifetime. lifetime ;
1427
- let mut err = struct_span_err ! ( self . sess, lifetime. span, E0262 ,
1428
- "invalid lifetime parameter name: `{}`" , lifetime. name) ;
1429
- err. span_label ( lifetime. span ,
1430
- format ! ( "{} is a reserved lifetime name" , lifetime. name) ) ;
1431
- err. emit ( ) ;
1427
+ match lifetime. lifetime . name {
1428
+ hir:: LifetimeName :: Static | hir:: LifetimeName :: Underscore => {
1429
+ let lifetime = lifetime. lifetime ;
1430
+ let name = lifetime. name . name ( ) ;
1431
+ let mut err = struct_span_err ! ( self . sess, lifetime. span, E0262 ,
1432
+ "invalid lifetime parameter name: `{}`" , name) ;
1433
+ err. span_label ( lifetime. span ,
1434
+ format ! ( "{} is a reserved lifetime name" , name) ) ;
1435
+ err. emit ( ) ;
1436
+ }
1437
+ hir:: LifetimeName :: Implicit | hir:: LifetimeName :: Name ( _) => { }
1432
1438
}
1433
1439
}
1434
1440
@@ -1439,7 +1445,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1439
1445
if lifetime_i. lifetime . name == lifetime_j. lifetime . name {
1440
1446
struct_span_err ! ( self . sess, lifetime_j. lifetime. span, E0263 ,
1441
1447
"lifetime name `{}` declared twice in the same scope" ,
1442
- lifetime_j. lifetime. name)
1448
+ lifetime_j. lifetime. name. name ( ) )
1443
1449
. span_label ( lifetime_j. lifetime . span ,
1444
1450
"declared twice" )
1445
1451
. span_label ( lifetime_i. lifetime . span ,
@@ -1452,15 +1458,27 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1452
1458
self . check_lifetime_def_for_shadowing ( old_scope, & lifetime_i. lifetime ) ;
1453
1459
1454
1460
for bound in & lifetime_i. bounds {
1455
- if !bound. is_static ( ) {
1456
- self . resolve_lifetime_ref ( bound) ;
1457
- } else {
1458
- self . insert_lifetime ( bound, Region :: Static ) ;
1459
- self . sess . struct_span_warn ( lifetime_i. lifetime . span . to ( bound. span ) ,
1460
- & format ! ( "unnecessary lifetime parameter `{}`" , lifetime_i. lifetime. name) )
1461
- . help ( & format ! ( "you can use the `'static` lifetime directly, in place \
1462
- of `{}`", lifetime_i. lifetime. name) )
1463
- . emit ( ) ;
1461
+ match bound. name {
1462
+ hir:: LifetimeName :: Underscore => {
1463
+ let mut err = struct_span_err ! ( self . sess, bound. span, E0637 ,
1464
+ "invalid lifetime bound name: `'_`" ) ;
1465
+ err. span_label ( bound. span , "`'_` is a reserved lifetime name" ) ;
1466
+ err. emit ( ) ;
1467
+ }
1468
+ hir:: LifetimeName :: Static => {
1469
+ self . insert_lifetime ( bound, Region :: Static ) ;
1470
+ self . sess . struct_span_warn ( lifetime_i. lifetime . span . to ( bound. span ) ,
1471
+ & format ! ( "unnecessary lifetime parameter `{}`" ,
1472
+ lifetime_i. lifetime. name. name( ) ) )
1473
+ . help ( & format ! (
1474
+ "you can use the `'static` lifetime directly, in place \
1475
+ of `{}`", lifetime_i. lifetime. name. name( ) ) )
1476
+ . emit ( ) ;
1477
+ }
1478
+ hir:: LifetimeName :: Implicit |
1479
+ hir:: LifetimeName :: Name ( _) => {
1480
+ self . resolve_lifetime_ref ( bound) ;
1481
+ }
1464
1482
}
1465
1483
}
1466
1484
}
@@ -1472,9 +1490,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1472
1490
{
1473
1491
for & ( label, label_span) in & self . labels_in_fn {
1474
1492
// FIXME (#24278): non-hygienic comparison
1475
- if lifetime. name == label {
1493
+ if lifetime. name . name ( ) == label {
1476
1494
signal_shadowing_problem ( self . sess ,
1477
- lifetime . name ,
1495
+ label ,
1478
1496
original_label ( label_span) ,
1479
1497
shadower_lifetime ( & lifetime) ) ;
1480
1498
return ;
@@ -1501,7 +1519,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1501
1519
1502
1520
signal_shadowing_problem (
1503
1521
self . sess ,
1504
- lifetime. name ,
1522
+ lifetime. name . name ( ) ,
1505
1523
original_lifetime ( self . hir_map . span ( node_id) ) ,
1506
1524
shadower_lifetime ( & lifetime) ) ;
1507
1525
return ;
@@ -1617,7 +1635,7 @@ fn insert_late_bound_lifetimes(map: &mut NamedRegionMap,
1617
1635
return ;
1618
1636
1619
1637
struct ConstrainedCollector {
1620
- regions : FxHashSet < ast :: Name > ,
1638
+ regions : FxHashSet < hir :: LifetimeName > ,
1621
1639
}
1622
1640
1623
1641
impl < ' v > Visitor < ' v > for ConstrainedCollector {
@@ -1657,7 +1675,7 @@ fn insert_late_bound_lifetimes(map: &mut NamedRegionMap,
1657
1675
}
1658
1676
1659
1677
struct AllCollector {
1660
- regions : FxHashSet < ast :: Name > ,
1678
+ regions : FxHashSet < hir :: LifetimeName > ,
1661
1679
impl_trait : bool
1662
1680
}
1663
1681
0 commit comments