@@ -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 > ,
@@ -377,7 +373,7 @@ pub fn lower_crate<'a, 'hir>(
377
373
task_context : None ,
378
374
current_item : None ,
379
375
lifetimes_to_define : Vec :: new ( ) ,
380
- is_collecting_in_band_lifetimes : false ,
376
+ is_collecting_anonymous_lifetimes : false ,
381
377
in_scope_lifetimes : Vec :: new ( ) ,
382
378
allow_try_trait : Some ( [ sym:: try_trait_v2] [ ..] . into ( ) ) ,
383
379
allow_gen_future : Some ( [ sym:: gen_future] [ ..] . into ( ) ) ,
@@ -724,13 +720,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
724
720
& mut self ,
725
721
f : impl FnOnce ( & mut Self ) -> T ,
726
722
) -> ( Vec < ( Span , ParamName ) > , T ) {
727
- let was_collecting = std:: mem:: replace ( & mut self . is_collecting_in_band_lifetimes , true ) ;
723
+ let was_collecting = std:: mem:: replace ( & mut self . is_collecting_anonymous_lifetimes , true ) ;
728
724
let len = self . lifetimes_to_define . len ( ) ;
729
725
730
726
let res = f ( self ) ;
731
727
732
728
let lifetimes_to_define = self . lifetimes_to_define . split_off ( len) ;
733
- self . is_collecting_in_band_lifetimes = was_collecting;
729
+ self . is_collecting_anonymous_lifetimes = was_collecting;
734
730
( lifetimes_to_define, res)
735
731
}
736
732
@@ -747,7 +743,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
747
743
// that collisions are ok here and this shouldn't
748
744
// really show up for end-user.
749
745
let ( str_name, kind) = match hir_name {
750
- ParamName :: Plain ( ident) => ( ident. name , hir:: LifetimeParamKind :: InBand ) ,
746
+ ParamName :: Plain ( ident) => ( ident. name , hir:: LifetimeParamKind :: Explicit ) ,
751
747
ParamName :: Fresh ( _) => ( kw:: UnderscoreLifetime , hir:: LifetimeParamKind :: Elided ) ,
752
748
ParamName :: Error => ( kw:: UnderscoreLifetime , hir:: LifetimeParamKind :: Error ) ,
753
749
} ;
@@ -771,38 +767,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
771
767
}
772
768
}
773
769
774
- /// When there is a reference to some lifetime `'a`, and in-band
775
- /// lifetimes are enabled, then we want to push that lifetime into
776
- /// the vector of names to define later. In that case, it will get
777
- /// added to the appropriate generics.
778
- fn maybe_collect_in_band_lifetime ( & mut self , ident : Ident ) {
779
- if !self . is_collecting_in_band_lifetimes {
780
- return ;
781
- }
782
-
783
- if !self . sess . features_untracked ( ) . in_band_lifetimes {
784
- return ;
785
- }
786
-
787
- if self . in_scope_lifetimes . contains ( & ParamName :: Plain ( ident. normalize_to_macros_2_0 ( ) ) ) {
788
- return ;
789
- }
790
-
791
- let hir_name = ParamName :: Plain ( ident) ;
792
-
793
- if self . lifetimes_to_define . iter ( ) . any ( |( _, lt_name) | {
794
- lt_name. normalize_to_macros_2_0 ( ) == hir_name. normalize_to_macros_2_0 ( )
795
- } ) {
796
- return ;
797
- }
798
-
799
- self . lifetimes_to_define . push ( ( ident. span , hir_name) ) ;
800
- }
801
-
802
770
/// When we have either an elided or `'_` lifetime in an impl
803
771
/// header, we convert it to an in-band lifetime.
804
- fn collect_fresh_in_band_lifetime ( & mut self , span : Span ) -> ParamName {
805
- assert ! ( self . is_collecting_in_band_lifetimes ) ;
772
+ fn collect_fresh_anonymous_lifetime ( & mut self , span : Span ) -> ParamName {
773
+ assert ! ( self . is_collecting_anonymous_lifetimes ) ;
806
774
let index = self . lifetimes_to_define . len ( ) + self . in_scope_lifetimes . len ( ) ;
807
775
let hir_name = ParamName :: Fresh ( index) ;
808
776
self . lifetimes_to_define . push ( ( span, hir_name) ) ;
@@ -1944,7 +1912,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1944
1912
}
1945
1913
ident if ident. name == kw:: UnderscoreLifetime => match self . anonymous_lifetime_mode {
1946
1914
AnonymousLifetimeMode :: CreateParameter => {
1947
- let fresh_name = self . collect_fresh_in_band_lifetime ( span) ;
1915
+ let fresh_name = self . collect_fresh_anonymous_lifetime ( span) ;
1948
1916
self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Param ( fresh_name) )
1949
1917
}
1950
1918
@@ -1955,7 +1923,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1955
1923
AnonymousLifetimeMode :: ReportError => self . new_error_lifetime ( Some ( l. id ) , span) ,
1956
1924
} ,
1957
1925
ident => {
1958
- self . maybe_collect_in_band_lifetime ( ident) ;
1959
1926
let param_name = ParamName :: Plain ( self . lower_ident ( ident) ) ;
1960
1927
self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Param ( param_name) )
1961
1928
}
@@ -1999,8 +1966,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1999
1966
2000
1967
let ( name, kind) = match param. kind {
2001
1968
GenericParamKind :: Lifetime => {
2002
- let was_collecting_in_band = self . is_collecting_in_band_lifetimes ;
2003
- self . is_collecting_in_band_lifetimes = false ;
1969
+ let was_collecting_in_band = self . is_collecting_anonymous_lifetimes ;
1970
+ self . is_collecting_anonymous_lifetimes = false ;
2004
1971
2005
1972
let lt = self
2006
1973
. with_anonymous_lifetime_mode ( AnonymousLifetimeMode :: ReportError , |this| {
@@ -2023,7 +1990,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2023
1990
let kind =
2024
1991
hir:: GenericParamKind :: Lifetime { kind : hir:: LifetimeParamKind :: Explicit } ;
2025
1992
2026
- self . is_collecting_in_band_lifetimes = was_collecting_in_band;
1993
+ self . is_collecting_anonymous_lifetimes = was_collecting_in_band;
2027
1994
2028
1995
( param_name, kind)
2029
1996
}
@@ -2382,7 +2349,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2382
2349
// Hence `impl Foo for &u32` becomes `impl<'f> Foo for &'f u32` for some fresh
2383
2350
// `'f`.
2384
2351
AnonymousLifetimeMode :: CreateParameter => {
2385
- let fresh_name = self . collect_fresh_in_band_lifetime ( span) ;
2352
+ let fresh_name = self . collect_fresh_anonymous_lifetime ( span) ;
2386
2353
hir:: Lifetime {
2387
2354
hir_id : self . next_id ( ) ,
2388
2355
span : self . lower_span ( span) ,
0 commit comments