@@ -173,7 +173,7 @@ pub enum LifetimeRes {
173
173
Fresh {
174
174
/// Id of the generic parameter that introduced it.
175
175
param : LocalDefId ,
176
- /// Id to create the HirId.
176
+ /// Id to create the HirId. This is used when creating the `Fresh` lifetime parameters.
177
177
introducer : Option < NodeId > ,
178
178
/// Id of the introducing place. See `Param`.
179
179
binder : NodeId ,
@@ -693,27 +693,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
693
693
Ident :: new ( ident. name , self . lower_span ( ident. span ) )
694
694
}
695
695
696
- /// Creates a new `hir::GenericParam` for every new lifetime and
697
- /// type parameter encountered while evaluating `f`. Definitions
698
- /// are created with the parent provided. If no `parent_id` is
699
- /// provided, no definitions will be returned.
700
- fn collect_in_band_defs < T > (
701
- & mut self ,
702
- parent_def_id : LocalDefId ,
703
- f : impl FnOnce ( & mut Self ) -> T ,
704
- ) -> ( FxIndexMap < NodeId , Span > , T ) {
705
- let lifetime_stash = std:: mem:: take ( & mut self . lifetimes_to_define ) ;
706
- let was_collecting =
707
- std:: mem:: replace ( & mut self . is_collecting_anonymous_lifetimes , Some ( parent_def_id) ) ;
708
-
709
- let res = f ( self ) ;
710
-
711
- self . is_collecting_anonymous_lifetimes = was_collecting;
712
- let lifetimes_to_define = std:: mem:: replace ( & mut self . lifetimes_to_define , lifetime_stash) ;
713
-
714
- ( lifetimes_to_define, res)
715
- }
716
-
717
696
/// Converts a lifetime into a new generic parameter.
718
697
fn fresh_lifetime_to_generic_param (
719
698
& mut self ,
@@ -733,9 +712,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
733
712
}
734
713
735
714
/// Evaluates `f` with the lifetimes in `params` in-scope.
736
- /// This is used to track which lifetimes have already been defined, and
737
- /// which are new in-band lifetimes that need to have a definition created
738
- /// for them.
715
+ /// This is used to track which lifetimes have already been defined,
716
+ /// which need to be duplicated for async fns.
739
717
fn with_in_scope_lifetime_defs < T > (
740
718
& mut self ,
741
719
params : & [ GenericParam ] ,
@@ -758,37 +736,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
758
736
res
759
737
}
760
738
761
- /// Appends in-band lifetime defs and argument-position `impl
762
- /// Trait` defs to the existing set of generics.
763
- fn add_in_band_defs < T > (
739
+ /// Creates a new `hir::GenericParam` for every new `Fresh` lifetime and
740
+ /// universal `impl Trait` type parameter encountered while evaluating `f`.
741
+ /// Definitions are created with the provided `parent_def_id`.
742
+ fn add_implicit_generics < T > (
764
743
& mut self ,
765
744
generics : & Generics ,
766
745
parent_def_id : LocalDefId ,
767
746
f : impl FnOnce ( & mut Self , & mut Vec < hir:: GenericParam < ' hir > > ) -> T ,
768
747
) -> ( hir:: Generics < ' hir > , T ) {
769
- let ( lifetimes_to_define , ( mut lowered_generics , impl_trait_defs , res ) ) = self
770
- . collect_in_band_defs ( parent_def_id , |this| {
771
- this . with_in_scope_lifetime_defs ( & generics . params , |this| {
772
- let mut impl_trait_defs = Vec :: new ( ) ;
773
- // Note: it is necessary to lower generics *before* calling `f`.
774
- // When lowering `async fn`, there's a final step when lowering
775
- // the return type that assumes that all in-scope lifetimes have
776
- // already been added to either `in_scope_lifetimes` or
777
- // `lifetimes_to_define`. If we swapped the order of these two,
778
- // in-band-lifetimes introduced by generics or where-clauses
779
- // wouldn't have been added yet.
780
- let generics = this . lower_generics_mut (
781
- generics ,
782
- ImplTraitContext :: Universal (
783
- & mut impl_trait_defs ,
784
- this. current_hir_id_owner ,
785
- ) ,
786
- ) ;
787
- let res = f ( this , & mut impl_trait_defs ) ;
788
- ( generics , impl_trait_defs , res )
789
- } )
748
+ let lifetime_stash = std :: mem :: take ( & mut self . lifetimes_to_define ) ;
749
+ let was_collecting =
750
+ std :: mem :: replace ( & mut self . is_collecting_anonymous_lifetimes , Some ( parent_def_id ) ) ;
751
+
752
+ let mut impl_trait_defs = Vec :: new ( ) ;
753
+
754
+ let ( mut lowered_generics , res ) =
755
+ self . with_in_scope_lifetime_defs ( & generics . params , |this| {
756
+ // Note: it is necessary to lower generics *before* calling `f`.
757
+ // When lowering `async fn`, there's a final step when lowering
758
+ // the return type that assumes that all in-scope lifetimes have
759
+ // already been added to either `in_scope_lifetimes` or
760
+ // `lifetimes_to_define`. If we swapped the order of these two ,
761
+ // fresh lifetimes introduced by generics or where-clauses
762
+ // wouldn't have been added yet.
763
+ let generics = this. lower_generics_mut (
764
+ generics ,
765
+ ImplTraitContext :: Universal ( & mut impl_trait_defs , this . current_hir_id_owner ) ,
766
+ ) ;
767
+ let res = f ( this , & mut impl_trait_defs ) ;
768
+ ( generics , res )
790
769
} ) ;
791
770
771
+ self . is_collecting_anonymous_lifetimes = was_collecting;
772
+ let lifetimes_to_define = std:: mem:: replace ( & mut self . lifetimes_to_define , lifetime_stash) ;
773
+
792
774
lowered_generics. params . extend (
793
775
lifetimes_to_define
794
776
. into_iter ( )
@@ -1700,15 +1682,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1700
1682
// Calculate all the lifetimes that should be captured
1701
1683
// by the opaque type. This should include all in-scope
1702
1684
// lifetime parameters, including those defined in-band.
1703
- //
1704
1685
1705
1686
// Input lifetime like `'a`:
1706
1687
let mut captures = FxHashMap :: default ( ) ;
1707
1688
for & ( p_name, def_id) in & self . in_scope_lifetimes {
1708
1689
let Ident { name, span } = p_name. ident ( ) ;
1709
1690
let node_id = self . resolver . next_node_id ( ) ;
1710
1691
1711
- // Add a definition for the in-band lifetime def.
1692
+ // Add a definition for the in scope lifetime def.
1712
1693
self . resolver . create_def (
1713
1694
opaque_ty_def_id,
1714
1695
node_id,
@@ -1735,7 +1716,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1735
1716
let def_id = self . resolver . local_def_id ( node_id) ;
1736
1717
let new_node_id = self . resolver . next_node_id ( ) ;
1737
1718
1738
- // Add a definition for the in-band lifetime def.
1719
+ // Add a definition for the `Fresh` lifetime def.
1739
1720
let new_def_id = self . resolver . create_def (
1740
1721
opaque_ty_def_id,
1741
1722
new_node_id,
0 commit comments