@@ -141,13 +141,9 @@ struct LoweringContext<'a, 'hir: 'a> {
141
141
/// indicate whether or not we're in a place where new lifetimes will result
142
142
/// in in-band lifetime definitions, such a function or an impl header,
143
143
/// including implicit lifetimes from `impl_header_lifetime_elision`.
144
- is_collecting_in_band_lifetimes : bool ,
144
+ is_collecting_anonymous_lifetimes : bool ,
145
145
146
146
/// Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB.
147
- /// When `is_collecting_in_band_lifetimes` is true, each lifetime is checked
148
- /// against this list to see if it is already in-scope, or if a definition
149
- /// needs to be created for it.
150
- ///
151
147
/// We always store a `normalize_to_macros_2_0()` version of the param-name in this
152
148
/// vector.
153
149
in_scope_lifetimes : Vec < ParamName > ,
@@ -374,7 +370,7 @@ pub fn lower_crate<'a, 'hir>(
374
370
task_context : None ,
375
371
current_item : None ,
376
372
lifetimes_to_define : Vec :: new ( ) ,
377
- is_collecting_in_band_lifetimes : false ,
373
+ is_collecting_anonymous_lifetimes : false ,
378
374
in_scope_lifetimes : Vec :: new ( ) ,
379
375
allow_try_trait : Some ( [ sym:: try_trait_v2] [ ..] . into ( ) ) ,
380
376
allow_gen_future : Some ( [ sym:: gen_future] [ ..] . into ( ) ) ,
@@ -718,13 +714,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
718
714
& mut self ,
719
715
f : impl FnOnce ( & mut Self ) -> T ,
720
716
) -> ( Vec < ( Span , ParamName ) > , T ) {
721
- let was_collecting = std:: mem:: replace ( & mut self . is_collecting_in_band_lifetimes , true ) ;
717
+ let was_collecting = std:: mem:: replace ( & mut self . is_collecting_anonymous_lifetimes , true ) ;
722
718
let len = self . lifetimes_to_define . len ( ) ;
723
719
724
720
let res = f ( self ) ;
725
721
726
722
let lifetimes_to_define = self . lifetimes_to_define . split_off ( len) ;
727
- self . is_collecting_in_band_lifetimes = was_collecting;
723
+ self . is_collecting_anonymous_lifetimes = was_collecting;
728
724
( lifetimes_to_define, res)
729
725
}
730
726
@@ -741,7 +737,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
741
737
// that collisions are ok here and this shouldn't
742
738
// really show up for end-user.
743
739
let ( str_name, kind) = match hir_name {
744
- ParamName :: Plain ( ident) => ( ident. name , hir:: LifetimeParamKind :: InBand ) ,
740
+ ParamName :: Plain ( ident) => ( ident. name , hir:: LifetimeParamKind :: Explicit ) ,
745
741
ParamName :: Fresh ( _) => ( kw:: UnderscoreLifetime , hir:: LifetimeParamKind :: Elided ) ,
746
742
ParamName :: Error => ( kw:: UnderscoreLifetime , hir:: LifetimeParamKind :: Error ) ,
747
743
} ;
@@ -765,38 +761,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
765
761
}
766
762
}
767
763
768
- /// When there is a reference to some lifetime `'a`, and in-band
769
- /// lifetimes are enabled, then we want to push that lifetime into
770
- /// the vector of names to define later. In that case, it will get
771
- /// added to the appropriate generics.
772
- fn maybe_collect_in_band_lifetime ( & mut self , ident : Ident ) {
773
- if !self . is_collecting_in_band_lifetimes {
774
- return ;
775
- }
776
-
777
- if !self . sess . features_untracked ( ) . in_band_lifetimes {
778
- return ;
779
- }
780
-
781
- if self . in_scope_lifetimes . contains ( & ParamName :: Plain ( ident. normalize_to_macros_2_0 ( ) ) ) {
782
- return ;
783
- }
784
-
785
- let hir_name = ParamName :: Plain ( ident) ;
786
-
787
- if self . lifetimes_to_define . iter ( ) . any ( |( _, lt_name) | {
788
- lt_name. normalize_to_macros_2_0 ( ) == hir_name. normalize_to_macros_2_0 ( )
789
- } ) {
790
- return ;
791
- }
792
-
793
- self . lifetimes_to_define . push ( ( ident. span , hir_name) ) ;
794
- }
795
-
796
764
/// When we have either an elided or `'_` lifetime in an impl
797
765
/// header, we convert it to an in-band lifetime.
798
- fn collect_fresh_in_band_lifetime ( & mut self , span : Span ) -> ParamName {
799
- assert ! ( self . is_collecting_in_band_lifetimes ) ;
766
+ fn collect_fresh_anonymous_lifetime ( & mut self , span : Span ) -> ParamName {
767
+ assert ! ( self . is_collecting_anonymous_lifetimes ) ;
800
768
let index = self . lifetimes_to_define . len ( ) + self . in_scope_lifetimes . len ( ) ;
801
769
let hir_name = ParamName :: Fresh ( index) ;
802
770
self . lifetimes_to_define . push ( ( span, hir_name) ) ;
@@ -1938,7 +1906,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1938
1906
}
1939
1907
ident if ident. name == kw:: UnderscoreLifetime => match self . anonymous_lifetime_mode {
1940
1908
AnonymousLifetimeMode :: CreateParameter => {
1941
- let fresh_name = self . collect_fresh_in_band_lifetime ( span) ;
1909
+ let fresh_name = self . collect_fresh_anonymous_lifetime ( span) ;
1942
1910
self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Param ( fresh_name) )
1943
1911
}
1944
1912
@@ -1949,7 +1917,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1949
1917
AnonymousLifetimeMode :: ReportError => self . new_error_lifetime ( Some ( l. id ) , span) ,
1950
1918
} ,
1951
1919
ident => {
1952
- self . maybe_collect_in_band_lifetime ( ident) ;
1953
1920
let param_name = ParamName :: Plain ( self . lower_ident ( ident) ) ;
1954
1921
self . new_named_lifetime ( l. id , span, hir:: LifetimeName :: Param ( param_name) )
1955
1922
}
@@ -1993,8 +1960,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1993
1960
1994
1961
let ( name, kind) = match param. kind {
1995
1962
GenericParamKind :: Lifetime => {
1996
- let was_collecting_in_band = self . is_collecting_in_band_lifetimes ;
1997
- self . is_collecting_in_band_lifetimes = false ;
1963
+ let was_collecting_in_band = self . is_collecting_anonymous_lifetimes ;
1964
+ self . is_collecting_anonymous_lifetimes = false ;
1998
1965
1999
1966
let lt = self
2000
1967
. with_anonymous_lifetime_mode ( AnonymousLifetimeMode :: ReportError , |this| {
@@ -2017,7 +1984,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2017
1984
let kind =
2018
1985
hir:: GenericParamKind :: Lifetime { kind : hir:: LifetimeParamKind :: Explicit } ;
2019
1986
2020
- self . is_collecting_in_band_lifetimes = was_collecting_in_band;
1987
+ self . is_collecting_anonymous_lifetimes = was_collecting_in_band;
2021
1988
2022
1989
( param_name, kind)
2023
1990
}
@@ -2376,7 +2343,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2376
2343
// Hence `impl Foo for &u32` becomes `impl<'f> Foo for &'f u32` for some fresh
2377
2344
// `'f`.
2378
2345
AnonymousLifetimeMode :: CreateParameter => {
2379
- let fresh_name = self . collect_fresh_in_band_lifetime ( span) ;
2346
+ let fresh_name = self . collect_fresh_anonymous_lifetime ( span) ;
2380
2347
hir:: Lifetime {
2381
2348
hir_id : self . next_id ( ) ,
2382
2349
span : self . lower_span ( span) ,
0 commit comments