@@ -46,14 +46,16 @@ pub enum Region {
4646}
4747
4848impl 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+ {
5052 let i = * index;
5153 * index += 1 ;
5254 let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
5355 ( def. lifetime . name , Region :: EarlyBound ( i, def_id) )
5456 }
5557
56- fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( ast :: Name , Region ) {
58+ fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( hir :: LifetimeName , Region ) {
5759 let depth = ty:: DebruijnIndex :: new ( 1 ) ;
5860 let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
5961 ( def. lifetime . name , Region :: LateBound ( depth, def_id) )
@@ -198,7 +200,7 @@ enum Scope<'a> {
198200 /// it should be shifted by the number of `Binder`s in between the
199201 /// declaration `Binder` and the location it's referenced from.
200202 Binder {
201- lifetimes : FxHashMap < ast :: Name , Region > ,
203+ lifetimes : FxHashMap < hir :: LifetimeName , Region > ,
202204 s : ScopeRef < ' a >
203205 } ,
204206
@@ -654,7 +656,7 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) {
654656
655657 Scope :: Binder { ref lifetimes, s } => {
656658 // FIXME (#24278): non-hygienic comparison
657- if let Some ( def) = lifetimes. get ( & label) {
659+ if let Some ( def) = lifetimes. get ( & hir :: LifetimeName :: Name ( label) ) {
658660 let node_id = hir_map. as_local_node_id ( def. id ( ) . unwrap ( ) )
659661 . unwrap ( ) ;
660662
@@ -692,7 +694,7 @@ fn compute_object_lifetime_defaults(sess: &Session, hir_map: &Map)
692694 Set1 :: Empty => "BaseDefault" . to_string ( ) ,
693695 Set1 :: One ( Region :: Static ) => "'static" . to_string ( ) ,
694696 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 ( )
696698 }
697699 Set1 :: One ( _) => bug ! ( ) ,
698700 Set1 :: Many => "Ambiguous" . to_string ( ) ,
@@ -714,7 +716,7 @@ fn compute_object_lifetime_defaults(sess: &Session, hir_map: &Map)
714716/// for each type parameter.
715717fn object_lifetime_defaults_for_item ( hir_map : & Map , generics : & hir:: Generics )
716718 -> 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 ] ) {
718720 for bound in bounds {
719721 if let hir:: RegionTyParamBound ( ref lifetime) = * bound {
720722 set. insert ( lifetime. name ) ;
@@ -754,7 +756,7 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
754756 match set {
755757 Set1 :: Empty => Set1 :: Empty ,
756758 Set1 :: One ( name) => {
757- if name == "'static" {
759+ if name == hir :: LifetimeName :: Static {
758760 Set1 :: One ( Region :: Static )
759761 } else {
760762 generics. lifetimes . iter ( ) . enumerate ( ) . find ( |& ( _, def) | {
@@ -922,7 +924,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
922924 self . insert_lifetime ( lifetime_ref, def) ;
923925 } else {
924926 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 ( ) )
926928 . span_label ( lifetime_ref. span , "undeclared lifetime" )
927929 . emit ( ) ;
928930 }
@@ -1422,13 +1424,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14221424 let lifetime_i = & lifetimes[ i] ;
14231425
14241426 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 ( _) => { }
14321438 }
14331439 }
14341440
@@ -1439,7 +1445,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14391445 if lifetime_i. lifetime . name == lifetime_j. lifetime . name {
14401446 struct_span_err ! ( self . sess, lifetime_j. lifetime. span, E0263 ,
14411447 "lifetime name `{}` declared twice in the same scope" ,
1442- lifetime_j. lifetime. name)
1448+ lifetime_j. lifetime. name. name ( ) )
14431449 . span_label ( lifetime_j. lifetime . span ,
14441450 "declared twice" )
14451451 . span_label ( lifetime_i. lifetime . span ,
@@ -1452,15 +1458,27 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14521458 self . check_lifetime_def_for_shadowing ( old_scope, & lifetime_i. lifetime ) ;
14531459
14541460 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+ }
14641482 }
14651483 }
14661484 }
@@ -1472,9 +1490,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14721490 {
14731491 for & ( label, label_span) in & self . labels_in_fn {
14741492 // FIXME (#24278): non-hygienic comparison
1475- if lifetime. name == label {
1493+ if lifetime. name . name ( ) == label {
14761494 signal_shadowing_problem ( self . sess ,
1477- lifetime . name ,
1495+ label ,
14781496 original_label ( label_span) ,
14791497 shadower_lifetime ( & lifetime) ) ;
14801498 return ;
@@ -1501,7 +1519,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15011519
15021520 signal_shadowing_problem (
15031521 self . sess ,
1504- lifetime. name ,
1522+ lifetime. name . name ( ) ,
15051523 original_lifetime ( self . hir_map . span ( node_id) ) ,
15061524 shadower_lifetime ( & lifetime) ) ;
15071525 return ;
@@ -1617,7 +1635,7 @@ fn insert_late_bound_lifetimes(map: &mut NamedRegionMap,
16171635 return ;
16181636
16191637 struct ConstrainedCollector {
1620- regions : FxHashSet < ast :: Name > ,
1638+ regions : FxHashSet < hir :: LifetimeName > ,
16211639 }
16221640
16231641 impl < ' v > Visitor < ' v > for ConstrainedCollector {
@@ -1657,7 +1675,7 @@ fn insert_late_bound_lifetimes(map: &mut NamedRegionMap,
16571675 }
16581676
16591677 struct AllCollector {
1660- regions : FxHashSet < ast :: Name > ,
1678+ regions : FxHashSet < hir :: LifetimeName > ,
16611679 impl_trait : bool
16621680 }
16631681
0 commit comments