41
41
//! in the HIR, especially for multiple identifiers.
42
42
43
43
use dep_graph:: DepGraph ;
44
- use hir;
44
+ use hir:: { self , ParamName } ;
45
45
use hir:: HirVec ;
46
46
use hir:: map:: { DefKey , DefPathData , Definitions } ;
47
47
use hir:: def_id:: { DefId , DefIndex , DefIndexAddressSpace , CRATE_DEF_INDEX } ;
@@ -125,7 +125,7 @@ pub struct LoweringContext<'a> {
125
125
// (i.e. it doesn't appear in the in_scope_lifetimes list), it is added
126
126
// to this list. The results of this list are then added to the list of
127
127
// lifetime definitions in the corresponding impl or function generics.
128
- lifetimes_to_define : Vec < ( Span , hir :: LifetimeName ) > ,
128
+ lifetimes_to_define : Vec < ( Span , ParamName ) > ,
129
129
130
130
// Whether or not in-band lifetimes are being collected. This is used to
131
131
// indicate whether or not we're in a place where new lifetimes will result
@@ -678,13 +678,8 @@ impl<'a> LoweringContext<'a> {
678
678
// that collisions are ok here and this shouldn't
679
679
// really show up for end-user.
680
680
let str_name = match hir_name {
681
- hir:: LifetimeName :: Name ( n) => n. as_str ( ) ,
682
- hir:: LifetimeName :: Fresh ( _) => keywords:: UnderscoreLifetime . name ( ) . as_str ( ) ,
683
- hir:: LifetimeName :: Implicit
684
- | hir:: LifetimeName :: Underscore
685
- | hir:: LifetimeName :: Static => {
686
- span_bug ! ( span, "unexpected in-band lifetime name: {:?}" , hir_name)
687
- }
681
+ ParamName :: Plain ( name) => name. as_str ( ) ,
682
+ ParamName :: Fresh ( _) => keywords:: UnderscoreLifetime . name ( ) . as_str ( ) ,
688
683
} ;
689
684
690
685
// Add a definition for the in-band lifetime def
@@ -699,15 +694,12 @@ impl<'a> LoweringContext<'a> {
699
694
700
695
hir:: GenericParam {
701
696
id : def_node_id,
702
- name : hir_name. name ( ) ,
697
+ name : hir_name,
703
698
span,
704
699
pure_wrt_drop : false ,
705
700
bounds : vec ! [ ] . into ( ) ,
706
- kind : hir:: GenericParamKind :: Lifetime {
707
- lt_name : hir_name,
708
- in_band : true ,
709
- }
710
- }
701
+ kind : hir:: GenericParamKind :: Lifetime { in_band : true }
702
+ }
711
703
} )
712
704
. chain ( in_band_ty_params. into_iter ( ) )
713
705
. collect ( ) ;
@@ -728,7 +720,7 @@ impl<'a> LoweringContext<'a> {
728
720
return ;
729
721
}
730
722
731
- let hir_name = hir :: LifetimeName :: Name ( name) ;
723
+ let hir_name = ParamName :: Plain ( name) ;
732
724
733
725
if self . lifetimes_to_define . iter ( ) . any ( |( _, lt_name) | * lt_name == hir_name) {
734
726
return ;
@@ -739,10 +731,10 @@ impl<'a> LoweringContext<'a> {
739
731
740
732
/// When we have either an elided or `'_` lifetime in an impl
741
733
/// header, we convert it to
742
- fn collect_fresh_in_band_lifetime ( & mut self , span : Span ) -> hir :: LifetimeName {
734
+ fn collect_fresh_in_band_lifetime ( & mut self , span : Span ) -> ParamName {
743
735
assert ! ( self . is_collecting_in_band_lifetimes) ;
744
736
let index = self . lifetimes_to_define . len ( ) ;
745
- let hir_name = hir :: LifetimeName :: Fresh ( index) ;
737
+ let hir_name = ParamName :: Fresh ( index) ;
746
738
self . lifetimes_to_define . push ( ( span, hir_name) ) ;
747
739
hir_name
748
740
}
@@ -781,7 +773,7 @@ impl<'a> LoweringContext<'a> {
781
773
{
782
774
let old_len = self . in_scope_lifetimes . len ( ) ;
783
775
let lt_def_names = params. iter ( ) . filter_map ( |param| match param. kind {
784
- hir:: GenericParamKind :: Lifetime { .. } => Some ( param. name ) ,
776
+ hir:: GenericParamKind :: Lifetime { .. } => Some ( param. name . name ( ) ) ,
785
777
_ => None ,
786
778
} ) ;
787
779
self . in_scope_lifetimes . extend ( lt_def_names) ;
@@ -1244,7 +1236,7 @@ impl<'a> LoweringContext<'a> {
1244
1236
let name = Symbol :: intern ( & pprust:: ty_to_string ( t) ) ;
1245
1237
self . in_band_ty_params . push ( hir:: GenericParam {
1246
1238
id : def_node_id,
1247
- name,
1239
+ name : ParamName :: Plain ( name ) ,
1248
1240
span,
1249
1241
pure_wrt_drop : false ,
1250
1242
bounds : hir_bounds,
@@ -1359,9 +1351,10 @@ impl<'a> LoweringContext<'a> {
1359
1351
1360
1352
fn visit_generic_param ( & mut self , param : & ' v hir:: GenericParam ) {
1361
1353
// Record the introduction of 'a in `for<'a> ...`
1362
- if let hir:: GenericParamKind :: Lifetime { lt_name , .. } = param. kind {
1354
+ if let hir:: GenericParamKind :: Lifetime { .. } = param. kind {
1363
1355
// Introduce lifetimes one at a time so that we can handle
1364
1356
// cases like `fn foo<'d>() -> impl for<'a, 'b: 'a, 'c: 'b + 'd>`
1357
+ let lt_name = hir:: LifetimeName :: Param ( param. name ) ;
1365
1358
self . currently_bound_lifetimes . push ( lt_name) ;
1366
1359
}
1367
1360
@@ -1379,14 +1372,12 @@ impl<'a> LoweringContext<'a> {
1379
1372
return ;
1380
1373
}
1381
1374
}
1382
- name @ hir:: LifetimeName :: Fresh ( _) => name,
1383
- name @ hir:: LifetimeName :: Name ( _) => name,
1375
+ hir:: LifetimeName :: Param ( _) => lifetime. name ,
1384
1376
hir:: LifetimeName :: Static => return ,
1385
1377
} ;
1386
1378
1387
1379
if !self . currently_bound_lifetimes . contains ( & name)
1388
- && !self . already_defined_lifetimes . contains ( & name)
1389
- {
1380
+ && !self . already_defined_lifetimes . contains ( & name) {
1390
1381
self . already_defined_lifetimes . insert ( name) ;
1391
1382
1392
1383
self . output_lifetimes . push ( hir:: Lifetime {
@@ -1409,16 +1400,23 @@ impl<'a> LoweringContext<'a> {
1409
1400
lifetime. span ,
1410
1401
) ;
1411
1402
1403
+ let name = match name {
1404
+ hir:: LifetimeName :: Underscore => {
1405
+ hir:: ParamName :: Plain ( keywords:: UnderscoreLifetime . name ( ) )
1406
+ }
1407
+ hir:: LifetimeName :: Param ( param_name) => param_name,
1408
+ _ => bug ! ( "expected LifetimeName::Param or ParamName::Plain" ) ,
1409
+ } ;
1410
+
1412
1411
self . output_lifetime_params . push ( hir:: GenericParam {
1413
1412
id : def_node_id,
1414
- name : name . name ( ) ,
1413
+ name,
1415
1414
span : lifetime. span ,
1416
1415
pure_wrt_drop : false ,
1417
1416
bounds : vec ! [ ] . into ( ) ,
1418
1417
kind : hir:: GenericParamKind :: Lifetime {
1419
- lt_name : name,
1420
1418
in_band : false ,
1421
- }
1419
+ }
1422
1420
} ) ;
1423
1421
}
1424
1422
}
@@ -1894,7 +1892,7 @@ impl<'a> LoweringContext<'a> {
1894
1892
x if x == "'_" => match self . anonymous_lifetime_mode {
1895
1893
AnonymousLifetimeMode :: CreateParameter => {
1896
1894
let fresh_name = self . collect_fresh_in_band_lifetime ( span) ;
1897
- self . new_named_lifetime ( l. id , span, fresh_name)
1895
+ self . new_named_lifetime ( l. id , span, hir :: LifetimeName :: Param ( fresh_name) )
1898
1896
}
1899
1897
1900
1898
AnonymousLifetimeMode :: PassThrough => {
@@ -1903,7 +1901,8 @@ impl<'a> LoweringContext<'a> {
1903
1901
} ,
1904
1902
name => {
1905
1903
self . maybe_collect_in_band_lifetime ( span, name) ;
1906
- self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Name ( name) )
1904
+ let param_name = ParamName :: Plain ( name) ;
1905
+ self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Param ( param_name) )
1907
1906
}
1908
1907
}
1909
1908
}
@@ -1942,16 +1941,17 @@ impl<'a> LoweringContext<'a> {
1942
1941
self . is_collecting_in_band_lifetimes = false ;
1943
1942
1944
1943
let lt = self . lower_lifetime ( & Lifetime { id : param. id , ident : param. ident } ) ;
1944
+ let param_name = match lt. name {
1945
+ hir:: LifetimeName :: Param ( param_name) => param_name,
1946
+ _ => hir:: ParamName :: Plain ( lt. name . name ( ) ) ,
1947
+ } ;
1945
1948
let param = hir:: GenericParam {
1946
1949
id : lt. id ,
1947
- name : lt . name . name ( ) ,
1950
+ name : param_name ,
1948
1951
span : lt. span ,
1949
1952
pure_wrt_drop : attr:: contains_name ( & param. attrs , "may_dangle" ) ,
1950
1953
bounds,
1951
- kind : hir:: GenericParamKind :: Lifetime {
1952
- lt_name : lt. name ,
1953
- in_band : false ,
1954
- }
1954
+ kind : hir:: GenericParamKind :: Lifetime { in_band : false }
1955
1955
} ;
1956
1956
1957
1957
self . is_collecting_in_band_lifetimes = was_collecting_in_band;
@@ -1977,7 +1977,7 @@ impl<'a> LoweringContext<'a> {
1977
1977
1978
1978
hir:: GenericParam {
1979
1979
id : self . lower_node_id ( param. id ) . node_id ,
1980
- name,
1980
+ name : hir :: ParamName :: Plain ( name ) ,
1981
1981
span : param. ident . span ,
1982
1982
pure_wrt_drop : attr:: contains_name ( & param. attrs , "may_dangle" ) ,
1983
1983
bounds,
@@ -4193,7 +4193,7 @@ impl<'a> LoweringContext<'a> {
4193
4193
hir:: Lifetime {
4194
4194
id : self . next_id ( ) . node_id ,
4195
4195
span,
4196
- name : fresh_name,
4196
+ name : hir :: LifetimeName :: Param ( fresh_name) ,
4197
4197
}
4198
4198
}
4199
4199
0 commit comments