@@ -8,22 +8,25 @@ use rustc_hir::def_id::LocalDefId;
88use  rustc_span:: hygiene:: LocalExpnId ; 
99use  rustc_span:: symbol:: { kw,  sym,  Symbol } ; 
1010use  rustc_span:: Span ; 
11+ use  std:: mem; 
1112use  tracing:: debug; 
1213
1314pub ( crate )  fn  collect_definitions ( 
1415    resolver :  & mut  Resolver < ' _ ,  ' _ > , 
1516    fragment :  & AstFragment , 
1617    expansion :  LocalExpnId , 
1718)  { 
18-     let  ( parent_def,  impl_trait_context)  = resolver. invocation_parents [ & expansion] ; 
19-     fragment. visit_with ( & mut  DefCollector  {  resolver,  parent_def,  expansion,  impl_trait_context } ) ; 
19+     let  ( parent_def,  impl_trait_context,  in_attr)  = resolver. invocation_parents [ & expansion] ; 
20+     let  mut  visitor = DefCollector  {  resolver,  parent_def,  expansion,  impl_trait_context,  in_attr } ; 
21+     fragment. visit_with ( & mut  visitor) ; 
2022} 
2123
2224/// Creates `DefId`s for nodes in the AST. 
2325struct  DefCollector < ' a ,  ' b ,  ' tcx >  { 
2426    resolver :  & ' a  mut  Resolver < ' b ,  ' tcx > , 
2527    parent_def :  LocalDefId , 
2628    impl_trait_context :  ImplTraitContext , 
29+     in_attr :  bool , 
2730    expansion :  LocalExpnId , 
2831} 
2932
@@ -53,7 +56,7 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
5356    } 
5457
5558    fn  with_parent < F :  FnOnce ( & mut  Self ) > ( & mut  self ,  parent_def :  LocalDefId ,  f :  F )  { 
56-         let  orig_parent_def = std :: mem:: replace ( & mut  self . parent_def ,  parent_def) ; 
59+         let  orig_parent_def = mem:: replace ( & mut  self . parent_def ,  parent_def) ; 
5760        f ( self ) ; 
5861        self . parent_def  = orig_parent_def; 
5962    } 
@@ -63,7 +66,7 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
6366        impl_trait_context :  ImplTraitContext , 
6467        f :  F , 
6568    )  { 
66-         let  orig_itc = std :: mem:: replace ( & mut  self . impl_trait_context ,  impl_trait_context) ; 
69+         let  orig_itc = mem:: replace ( & mut  self . impl_trait_context ,  impl_trait_context) ; 
6770        f ( self ) ; 
6871        self . impl_trait_context  = orig_itc; 
6972    } 
@@ -105,8 +108,10 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
105108
106109    fn  visit_macro_invoc ( & mut  self ,  id :  NodeId )  { 
107110        let  id = id. placeholder_to_expn_id ( ) ; 
108-         let  old_parent =
109-             self . resolver . invocation_parents . insert ( id,  ( self . parent_def ,  self . impl_trait_context ) ) ; 
111+         let  old_parent = self 
112+             . resolver 
113+             . invocation_parents 
114+             . insert ( id,  ( self . parent_def ,  self . impl_trait_context ,  self . in_attr ) ) ; 
110115        assert ! ( old_parent. is_none( ) ,  "parent `LocalDefId` is reset for an invocation" ) ; 
111116    } 
112117} 
@@ -413,4 +418,10 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
413418            visit:: walk_crate ( self ,  krate) 
414419        } 
415420    } 
421+ 
422+     fn  visit_attribute ( & mut  self ,  attr :  & ' a  Attribute )  -> Self :: Result  { 
423+         let  orig_in_attr = mem:: replace ( & mut  self . in_attr ,  true ) ; 
424+         visit:: walk_attribute ( self ,  attr) ; 
425+         self . in_attr  = orig_in_attr; 
426+     } 
416427} 
0 commit comments