@@ -142,13 +142,9 @@ struct LoweringContext<'a, 'hir: 'a> {
142
142
/// indicate whether or not we're in a place where new lifetimes will result
143
143
/// in in-band lifetime definitions, such a function or an impl header,
144
144
/// including implicit lifetimes from `impl_header_lifetime_elision`.
145
- is_collecting_in_band_lifetimes : bool ,
145
+ is_collecting_anonymous_lifetimes : bool ,
146
146
147
147
/// Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB.
148
- /// When `is_collecting_in_band_lifetimes` is true, each lifetime is checked
149
- /// against this list to see if it is already in-scope, or if a definition
150
- /// needs to be created for it.
151
- ///
152
148
/// We always store a `normalize_to_macros_2_0()` version of the param-name in this
153
149
/// vector.
154
150
in_scope_lifetimes : Vec < ParamName > ,
@@ -379,7 +375,7 @@ pub fn lower_crate<'a, 'hir>(
379
375
task_context : None ,
380
376
current_item : None ,
381
377
lifetimes_to_define : Vec :: new ( ) ,
382
- is_collecting_in_band_lifetimes : false ,
378
+ is_collecting_anonymous_lifetimes : false ,
383
379
in_scope_lifetimes : Vec :: new ( ) ,
384
380
allow_try_trait : Some ( [ sym:: try_trait_v2] [ ..] . into ( ) ) ,
385
381
allow_gen_future : Some ( [ sym:: gen_future] [ ..] . into ( ) ) ,
@@ -726,13 +722,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
726
722
& mut self ,
727
723
f : impl FnOnce ( & mut Self ) -> T ,
728
724
) -> ( Vec < ( Span , ParamName ) > , T ) {
729
- let was_collecting = std:: mem:: replace ( & mut self . is_collecting_in_band_lifetimes , true ) ;
725
+ let was_collecting = std:: mem:: replace ( & mut self . is_collecting_anonymous_lifetimes , true ) ;
730
726
let len = self . lifetimes_to_define . len ( ) ;
731
727
732
728
let res = f ( self ) ;
733
729
734
730
let lifetimes_to_define = self . lifetimes_to_define . split_off ( len) ;
735
- self . is_collecting_in_band_lifetimes = was_collecting;
731
+ self . is_collecting_anonymous_lifetimes = was_collecting;
736
732
( lifetimes_to_define, res)
737
733
}
738
734
@@ -749,7 +745,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
749
745
// that collisions are ok here and this shouldn't
750
746
// really show up for end-user.
751
747
let ( str_name, kind) = match hir_name {
752
- ParamName :: Plain ( ident) => ( ident. name , hir:: LifetimeParamKind :: InBand ) ,
748
+ ParamName :: Plain ( ident) => ( ident. name , hir:: LifetimeParamKind :: Explicit ) ,
753
749
ParamName :: Fresh ( _) => ( kw:: UnderscoreLifetime , hir:: LifetimeParamKind :: Elided ) ,
754
750
ParamName :: Error => ( kw:: UnderscoreLifetime , hir:: LifetimeParamKind :: Error ) ,
755
751
} ;
@@ -773,38 +769,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
773
769
}
774
770
}
775
771
776
- /// When there is a reference to some lifetime `'a`, and in-band
777
- /// lifetimes are enabled, then we want to push that lifetime into
778
- /// the vector of names to define later. In that case, it will get
779
- /// added to the appropriate generics.
780
- fn maybe_collect_in_band_lifetime ( & mut self , ident : Ident ) {
781
- if !self . is_collecting_in_band_lifetimes {
782
- return ;
783
- }
784
-
785
- if !self . sess . features_untracked ( ) . in_band_lifetimes {
786
- return ;
787
- }
788
-
789
- if self . in_scope_lifetimes . contains ( & ParamName :: Plain ( ident. normalize_to_macros_2_0 ( ) ) ) {
790
- return ;
791
- }
792
-
793
- let hir_name = ParamName :: Plain ( ident) ;
794
-
795
- if self . lifetimes_to_define . iter ( ) . any ( |( _, lt_name) | {
796
- lt_name. normalize_to_macros_2_0 ( ) == hir_name. normalize_to_macros_2_0 ( )
797
- } ) {
798
- return ;
799
- }
800
-
801
- self . lifetimes_to_define . push ( ( ident. span , hir_name) ) ;
802
- }
803
-
804
772
/// When we have either an elided or `'_` lifetime in an impl
805
773
/// header, we convert it to an in-band lifetime.
806
- fn collect_fresh_in_band_lifetime ( & mut self , span : Span ) -> ParamName {
807
- assert ! ( self . is_collecting_in_band_lifetimes ) ;
774
+ fn collect_fresh_anonymous_lifetime ( & mut self , span : Span ) -> ParamName {
775
+ assert ! ( self . is_collecting_anonymous_lifetimes ) ;
808
776
let index = self . lifetimes_to_define . len ( ) + self . in_scope_lifetimes . len ( ) ;
809
777
let hir_name = ParamName :: Fresh ( index) ;
810
778
self . lifetimes_to_define . push ( ( span, hir_name) ) ;
@@ -1946,7 +1914,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1946
1914
}
1947
1915
ident if ident. name == kw:: UnderscoreLifetime => match self . anonymous_lifetime_mode {
1948
1916
AnonymousLifetimeMode :: CreateParameter => {
1949
- let fresh_name = self . collect_fresh_in_band_lifetime ( span) ;
1917
+ let fresh_name = self . collect_fresh_anonymous_lifetime ( span) ;
1950
1918
self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Param ( fresh_name) )
1951
1919
}
1952
1920
@@ -1957,7 +1925,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1957
1925
AnonymousLifetimeMode :: ReportError => self . new_error_lifetime ( Some ( l. id ) , span) ,
1958
1926
} ,
1959
1927
ident => {
1960
- self . maybe_collect_in_band_lifetime ( ident) ;
1961
1928
let param_name = ParamName :: Plain ( self . lower_ident ( ident) ) ;
1962
1929
self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Param ( param_name) )
1963
1930
}
@@ -2001,8 +1968,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2001
1968
2002
1969
let ( name, kind) = match param. kind {
2003
1970
GenericParamKind :: Lifetime => {
2004
- let was_collecting_in_band = self . is_collecting_in_band_lifetimes ;
2005
- self . is_collecting_in_band_lifetimes = false ;
1971
+ let was_collecting_in_band = self . is_collecting_anonymous_lifetimes ;
1972
+ self . is_collecting_anonymous_lifetimes = false ;
2006
1973
2007
1974
let lt = self
2008
1975
. with_anonymous_lifetime_mode ( AnonymousLifetimeMode :: ReportError , |this| {
@@ -2025,7 +1992,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2025
1992
let kind =
2026
1993
hir:: GenericParamKind :: Lifetime { kind : hir:: LifetimeParamKind :: Explicit } ;
2027
1994
2028
- self . is_collecting_in_band_lifetimes = was_collecting_in_band;
1995
+ self . is_collecting_anonymous_lifetimes = was_collecting_in_band;
2029
1996
2030
1997
( param_name, kind)
2031
1998
}
@@ -2384,7 +2351,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2384
2351
// Hence `impl Foo for &u32` becomes `impl<'f> Foo for &'f u32` for some fresh
2385
2352
// `'f`.
2386
2353
AnonymousLifetimeMode :: CreateParameter => {
2387
- let fresh_name = self . collect_fresh_in_band_lifetime ( span) ;
2354
+ let fresh_name = self . collect_fresh_anonymous_lifetime ( span) ;
2388
2355
hir:: Lifetime {
2389
2356
hir_id : self . next_id ( ) ,
2390
2357
span : self . lower_span ( span) ,
0 commit comments