@@ -139,7 +139,6 @@ pub struct LoweringContext<'a> {
139
139
type_def_lifetime_params : DefIdMap < usize > ,
140
140
141
141
current_hir_id_owner : Vec < ( DefIndex , u32 ) > ,
142
- current_impl_trait_owner : Vec < DefId > ,
143
142
item_local_id_counters : NodeMap < u32 > ,
144
143
node_id_to_hir_id : IndexVec < NodeId , hir:: HirId > ,
145
144
}
@@ -233,7 +232,6 @@ pub fn lower_crate(
233
232
anonymous_lifetime_mode : AnonymousLifetimeMode :: PassThrough ,
234
233
type_def_lifetime_params : DefIdMap ( ) ,
235
234
current_hir_id_owner : vec ! [ ( CRATE_DEF_INDEX , 0 ) ] ,
236
- current_impl_trait_owner : vec ! [ ] ,
237
235
item_local_id_counters : NodeMap ( ) ,
238
236
node_id_to_hir_id : IndexVec :: new ( ) ,
239
237
is_generator : false ,
@@ -392,17 +390,6 @@ impl<'a> LoweringContext<'a> {
392
390
}
393
391
394
392
impl < ' lcx , ' interner > ItemLowerer < ' lcx , ' interner > {
395
- fn with_impl_trait_owner < F , T > ( & mut self , def_id : DefId , f : F ) -> T
396
- where
397
- F : FnOnce ( & mut Self ) -> T ,
398
- {
399
- self . lctx . current_impl_trait_owner . push ( def_id) ;
400
- let ret = f ( self ) ;
401
- self . lctx . current_impl_trait_owner . pop ( ) ;
402
-
403
- ret
404
- }
405
-
406
393
fn with_trait_impl_ref < F > ( & mut self , trait_impl_ref : & Option < TraitRef > , f : F )
407
394
where
408
395
F : FnOnce ( & mut Self ) ,
@@ -440,12 +427,7 @@ impl<'a> LoweringContext<'a> {
440
427
441
428
self . lctx . with_parent_impl_lifetime_defs ( & item_generics, |this| {
442
429
let this = & mut ItemLowerer { lctx : this } ;
443
- if let ItemKind :: Fn ( ..) = item. node {
444
- let fn_def_id = this. lctx . resolver . definitions ( ) . local_def_id ( item. id ) ;
445
- this. with_impl_trait_owner ( fn_def_id, |this| {
446
- visit:: walk_item ( this, item)
447
- } ) ;
448
- } else if let ItemKind :: Impl ( .., ref opt_trait_ref, _, _) = item. node {
430
+ if let ItemKind :: Impl ( .., ref opt_trait_ref, _, _) = item. node {
449
431
this. with_trait_impl_ref ( opt_trait_ref, |this| {
450
432
visit:: walk_item ( this, item)
451
433
} ) ;
@@ -573,17 +555,6 @@ impl<'a> LoweringContext<'a> {
573
555
ret
574
556
}
575
557
576
- fn with_impl_trait_owner < F , T > ( & mut self , def_id : DefId , f : F ) -> T
577
- where
578
- F : FnOnce ( & mut LoweringContext ) -> T ,
579
- {
580
- self . current_impl_trait_owner . push ( def_id) ;
581
- let ret = f ( self ) ;
582
- self . current_impl_trait_owner . pop ( ) ;
583
-
584
- ret
585
- }
586
-
587
558
/// This method allocates a new HirId for the given NodeId and stores it in
588
559
/// the LoweringContext's NodeId => HirId map.
589
560
/// Take care not to call this method if the resulting HirId is then not
@@ -1939,15 +1910,15 @@ impl<'a> LoweringContext<'a> {
1939
1910
visitor. visit_ty ( ty) ;
1940
1911
}
1941
1912
}
1942
- let impl_trait_owner_id = self . current_impl_trait_owner . last ( ) . map ( |id| * id ) ;
1913
+ let parent_def_id = DefId :: local ( self . current_hir_id_owner . last ( ) . unwrap ( ) . 0 ) ;
1943
1914
( P ( hir:: Local {
1944
1915
id : node_id,
1945
1916
hir_id,
1946
1917
ty : l. ty
1947
1918
. as_ref ( )
1948
1919
. map ( |t| self . lower_ty ( t,
1949
1920
if self . sess . features_untracked ( ) . impl_trait_in_bindings {
1950
- ImplTraitContext :: Existential ( impl_trait_owner_id )
1921
+ ImplTraitContext :: Existential ( Some ( parent_def_id ) )
1951
1922
} else {
1952
1923
ImplTraitContext :: Disallowed
1953
1924
}
@@ -2213,8 +2184,7 @@ impl<'a> LoweringContext<'a> {
2213
2184
span, Some ( fn_def_id) , return_impl_trait_id, |this| {
2214
2185
let output_ty = match output {
2215
2186
FunctionRetTy :: Ty ( ty) => {
2216
- let impl_trait_owner_id = * this. current_impl_trait_owner . last ( ) . unwrap ( ) ;
2217
- this. lower_ty ( ty, ImplTraitContext :: Existential ( Some ( impl_trait_owner_id) ) )
2187
+ this. lower_ty ( ty, ImplTraitContext :: Existential ( Some ( fn_def_id) ) )
2218
2188
}
2219
2189
FunctionRetTy :: Default ( span) => {
2220
2190
let LoweredNodeId { node_id, hir_id } = this. next_id ( ) ;
@@ -2738,8 +2708,7 @@ impl<'a> LoweringContext<'a> {
2738
2708
}
2739
2709
ItemKind :: Fn ( ref decl, header, ref generics, ref body) => {
2740
2710
let fn_def_id = self . resolver . definitions ( ) . local_def_id ( id) ;
2741
- self . with_impl_trait_owner ( fn_def_id, |this| {
2742
- this. with_new_scopes ( |this| {
2711
+ self . with_new_scopes ( |this| {
2743
2712
// Note: we don't need to change the return type from `T` to
2744
2713
// `impl Future<Output = T>` here because lower_body
2745
2714
// only cares about the input argument patterns in the function
@@ -2765,7 +2734,6 @@ impl<'a> LoweringContext<'a> {
2765
2734
body_id,
2766
2735
)
2767
2736
} )
2768
- } )
2769
2737
}
2770
2738
ItemKind :: Mod ( ref m) => hir:: ItemKind :: Mod ( self . lower_mod ( m) ) ,
2771
2739
ItemKind :: ForeignMod ( ref nm) => hir:: ItemKind :: ForeignMod ( self . lower_foreign_mod ( nm) ) ,
@@ -3083,33 +3051,29 @@ impl<'a> LoweringContext<'a> {
3083
3051
) ,
3084
3052
) ,
3085
3053
TraitItemKind :: Method ( ref sig, None ) => {
3086
- self . with_impl_trait_owner ( trait_item_def_id, |this| {
3087
- let names = this. lower_fn_args_to_names ( & sig. decl ) ;
3088
- let ( generics, sig) = this. lower_method_sig (
3054
+ let names = self . lower_fn_args_to_names ( & sig. decl ) ;
3055
+ let ( generics, sig) = self . lower_method_sig (
3089
3056
& i. generics ,
3090
3057
sig,
3091
3058
trait_item_def_id,
3092
3059
false ,
3093
3060
None ,
3094
3061
) ;
3095
3062
( generics, hir:: TraitItemKind :: Method ( sig, hir:: TraitMethod :: Required ( names) ) )
3096
- } )
3097
3063
}
3098
3064
TraitItemKind :: Method ( ref sig, Some ( ref body) ) => {
3099
- self . with_impl_trait_owner ( trait_item_def_id, |this| {
3100
- let body_id = this. lower_body ( Some ( & sig. decl ) , |this| {
3065
+ let body_id = self . lower_body ( Some ( & sig. decl ) , |this| {
3101
3066
let body = this. lower_block ( body, false ) ;
3102
3067
this. expr_block ( body, ThinVec :: new ( ) )
3103
3068
} ) ;
3104
- let ( generics, sig) = this . lower_method_sig (
3069
+ let ( generics, sig) = self . lower_method_sig (
3105
3070
& i. generics ,
3106
3071
sig,
3107
3072
trait_item_def_id,
3108
3073
false ,
3109
3074
None ,
3110
3075
) ;
3111
3076
( generics, hir:: TraitItemKind :: Method ( sig, hir:: TraitMethod :: Provided ( body_id) ) )
3112
- } )
3113
3077
}
3114
3078
TraitItemKind :: Type ( ref bounds, ref default) => (
3115
3079
self . lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
@@ -3175,18 +3139,16 @@ impl<'a> LoweringContext<'a> {
3175
3139
)
3176
3140
}
3177
3141
ImplItemKind :: Method ( ref sig, ref body) => {
3178
- self . with_impl_trait_owner ( impl_item_def_id, |this| {
3179
- let body_id = this. lower_async_body ( & sig. decl , sig. header . asyncness , body) ;
3180
- let impl_trait_return_allow = !this. is_in_trait_impl ;
3181
- let ( generics, sig) = this. lower_method_sig (
3142
+ let body_id = self . lower_async_body ( & sig. decl , sig. header . asyncness , body) ;
3143
+ let impl_trait_return_allow = !self . is_in_trait_impl ;
3144
+ let ( generics, sig) = self . lower_method_sig (
3182
3145
& i. generics ,
3183
3146
sig,
3184
3147
impl_item_def_id,
3185
3148
impl_trait_return_allow,
3186
3149
sig. header . asyncness . opt_return_id ( ) ,
3187
3150
) ;
3188
3151
( generics, hir:: ImplItemKind :: Method ( sig, body_id) )
3189
- } )
3190
3152
}
3191
3153
ImplItemKind :: Type ( ref ty) => (
3192
3154
self . lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
0 commit comments