@@ -13,7 +13,7 @@ use rustc_ast::{
13
13
MetaItemKind , ModKind , NodeId , PatKind , StmtKind , TyKind , token,
14
14
} ;
15
15
use rustc_ast_pretty:: pprust;
16
- use rustc_attr_parsing:: { EvalConfigResult , ShouldEmit } ;
16
+ use rustc_attr_parsing:: { AttributeParser , EvalConfigResult , ShouldEmit } ;
17
17
use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
18
18
use rustc_errors:: PResult ;
19
19
use rustc_feature:: Features ;
@@ -2119,17 +2119,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
2119
2119
2120
2120
// Detect use of feature-gated or invalid attributes on macro invocations
2121
2121
// since they will not be detected after macro expansion.
2122
- fn check_attributes ( & self , attrs : & [ ast:: Attribute ] , call : & ast:: MacCall ) {
2122
+ fn check_attributes ( & self , attrs : & [ ast:: Attribute ] , call : & ast:: MacCall , call_id : NodeId ) {
2123
2123
let features = self . cx . ecfg . features ;
2124
2124
let mut attrs = attrs. iter ( ) . peekable ( ) ;
2125
2125
let mut span: Option < Span > = None ;
2126
2126
while let Some ( attr) = attrs. next ( ) {
2127
+ // Attributes on a macro call will not be checked during late parsing since we'll remove them
2128
+ // We do some basic checks now, but we don't fully parse them
2127
2129
rustc_ast_passes:: feature_gate:: check_attribute ( attr, self . cx . sess , features) ;
2128
- validate_attr:: check_attr (
2129
- & self . cx . sess . psess ,
2130
- attr,
2131
- self . cx . current_expansion . lint_node_id ,
2132
- ) ;
2130
+ AttributeParser :: validate_attribute_early ( self . cx . sess , attr, call_id) ;
2133
2131
2134
2132
let current_span = if let Some ( sp) = span { sp. to ( attr. span ) } else { attr. span } ;
2135
2133
span = Some ( current_span) ;
@@ -2228,8 +2226,9 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
2228
2226
}
2229
2227
} ,
2230
2228
None if node. is_mac_call ( ) => {
2229
+ let mac_node_id = node. node_id ( ) ;
2231
2230
let ( mac, attrs, add_semicolon) = node. take_mac_call ( ) ;
2232
- self . check_attributes ( & attrs, & mac) ;
2231
+ self . check_attributes ( & attrs, & mac, mac_node_id ) ;
2233
2232
let mut res = self . collect_bang ( mac, Node :: KIND ) . make_ast :: < Node > ( ) ;
2234
2233
Node :: post_flat_map_node_collect_bang ( & mut res, add_semicolon) ;
2235
2234
res
@@ -2315,7 +2314,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
2315
2314
None if node. is_mac_call ( ) => {
2316
2315
let n = mem:: replace ( node, Node :: dummy ( ) ) ;
2317
2316
let ( mac, attrs, _) = n. take_mac_call ( ) ;
2318
- self . check_attributes ( & attrs, & mac) ;
2317
+ self . check_attributes ( & attrs, & mac, node . node_id ( ) ) ;
2319
2318
2320
2319
* node = self . collect_bang ( mac, Node :: KIND ) . make_ast :: < Node > ( ) . into ( )
2321
2320
}
0 commit comments