@@ -373,9 +373,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
373
373
( trait_ref, lowered_ty)
374
374
} ) ;
375
375
376
- let new_impl_items = self
377
- . arena
378
- . alloc_from_iter ( impl_items. iter ( ) . map ( |item| self . lower_impl_item_ref ( item) ) ) ;
376
+ let new_impl_items = self . with_trait_impl ( trait_ref. is_some ( ) , |this| {
377
+ this. arena . alloc_from_iter (
378
+ impl_items. iter ( ) . map ( |item| this. lower_impl_item_ref ( item) ) ,
379
+ )
380
+ } ) ;
379
381
380
382
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
381
383
// to not cause an assertion failure inside the `lower_defaultness` function.
@@ -606,9 +608,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
606
608
// This is used to track which lifetimes have already been defined,
607
609
// and which need to be replicated when lowering an async fn.
608
610
611
+ let mut is_in_trait_impl = false ;
609
612
let generics = match parent_hir. node ( ) . expect_item ( ) . kind {
610
613
hir:: ItemKind :: Impl ( impl_) => {
611
- self . is_in_trait_impl = impl_. of_trait . is_some ( ) ;
614
+ is_in_trait_impl = impl_. of_trait . is_some ( ) ;
612
615
& impl_. generics
613
616
}
614
617
hir:: ItemKind :: Trait ( _, _, generics, _, _) => generics,
@@ -629,7 +632,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
629
632
630
633
match ctxt {
631
634
AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
632
- AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item) ) ,
635
+ AssocCtxt :: Impl => self . with_trait_impl ( is_in_trait_impl, |this| {
636
+ hir:: OwnerNode :: ImplItem ( this. lower_impl_item ( item) )
637
+ } ) ,
633
638
}
634
639
}
635
640
@@ -978,13 +983,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
978
983
}
979
984
980
985
fn lower_impl_item_ref ( & mut self , i : & AssocItem ) -> hir:: ImplItemRef {
981
- let trait_item_def_id = self
982
- . resolver
983
- . get_partial_res ( i. id )
984
- . map ( |r| r. expect_full_res ( ) . opt_def_id ( ) )
985
- . unwrap_or ( None ) ;
986
- self . is_in_trait_impl = trait_item_def_id. is_some ( ) ;
987
-
988
986
hir:: ImplItemRef {
989
987
id : hir:: ImplItemId { owner_id : hir:: OwnerId { def_id : self . local_def_id ( i. id ) } } ,
990
988
ident : self . lower_ident ( i. ident ) ,
@@ -1000,7 +998,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
1000
998
} ,
1001
999
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
1002
1000
} ,
1003
- trait_item_def_id,
1001
+ trait_item_def_id : self
1002
+ . resolver
1003
+ . get_partial_res ( i. id )
1004
+ . map ( |r| r. expect_full_res ( ) . opt_def_id ( ) )
1005
+ . unwrap_or ( None ) ,
1004
1006
}
1005
1007
}
1006
1008
0 commit comments