@@ -8,22 +8,25 @@ use rustc_hir::def_id::LocalDefId;
8
8
use rustc_span:: hygiene:: LocalExpnId ;
9
9
use rustc_span:: symbol:: { kw, sym, Symbol } ;
10
10
use rustc_span:: Span ;
11
+ use std:: mem;
11
12
use tracing:: debug;
12
13
13
14
pub ( crate ) fn collect_definitions (
14
15
resolver : & mut Resolver < ' _ , ' _ > ,
15
16
fragment : & AstFragment ,
16
17
expansion : LocalExpnId ,
17
18
) {
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) ;
20
22
}
21
23
22
24
/// Creates `DefId`s for nodes in the AST.
23
25
struct DefCollector < ' a , ' b , ' tcx > {
24
26
resolver : & ' a mut Resolver < ' b , ' tcx > ,
25
27
parent_def : LocalDefId ,
26
28
impl_trait_context : ImplTraitContext ,
29
+ in_attr : bool ,
27
30
expansion : LocalExpnId ,
28
31
}
29
32
@@ -53,7 +56,7 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
53
56
}
54
57
55
58
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) ;
57
60
f ( self ) ;
58
61
self . parent_def = orig_parent_def;
59
62
}
@@ -63,7 +66,7 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
63
66
impl_trait_context : ImplTraitContext ,
64
67
f : F ,
65
68
) {
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) ;
67
70
f ( self ) ;
68
71
self . impl_trait_context = orig_itc;
69
72
}
@@ -105,8 +108,10 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
105
108
106
109
fn visit_macro_invoc ( & mut self , id : NodeId ) {
107
110
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 ) ) ;
110
115
assert ! ( old_parent. is_none( ) , "parent `LocalDefId` is reset for an invocation" ) ;
111
116
}
112
117
}
@@ -413,4 +418,10 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
413
418
visit:: walk_crate ( self , krate)
414
419
}
415
420
}
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
+ }
416
427
}
0 commit comments