@@ -13,7 +13,7 @@ use rustc_ast::{
1313 MetaItemKind , ModKind , NodeId , PatKind , StmtKind , TyKind , token,
1414} ;
1515use rustc_ast_pretty:: pprust;
16- use rustc_attr_parsing:: { EvalConfigResult , ShouldEmit } ;
16+ use rustc_attr_parsing:: { AttributeParser , EvalConfigResult , ShouldEmit } ;
1717use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
1818use rustc_errors:: PResult ;
1919use rustc_feature:: Features ;
@@ -2119,17 +2119,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21192119
21202120 // Detect use of feature-gated or invalid attributes on macro invocations
21212121 // 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 ) {
21232123 let features = self . cx . ecfg . features ;
21242124 let mut attrs = attrs. iter ( ) . peekable ( ) ;
21252125 let mut span: Option < Span > = None ;
21262126 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
21272129 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) ;
21332131
21342132 let current_span = if let Some ( sp) = span { sp. to ( attr. span ) } else { attr. span } ;
21352133 span = Some ( current_span) ;
@@ -2228,8 +2226,9 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
22282226 }
22292227 } ,
22302228 None if node. is_mac_call ( ) => {
2229+ let mac_node_id = node. node_id ( ) ;
22312230 let ( mac, attrs, add_semicolon) = node. take_mac_call ( ) ;
2232- self . check_attributes ( & attrs, & mac) ;
2231+ self . check_attributes ( & attrs, & mac, mac_node_id ) ;
22332232 let mut res = self . collect_bang ( mac, Node :: KIND ) . make_ast :: < Node > ( ) ;
22342233 Node :: post_flat_map_node_collect_bang ( & mut res, add_semicolon) ;
22352234 res
@@ -2315,7 +2314,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
23152314 None if node. is_mac_call ( ) => {
23162315 let n = mem:: replace ( node, Node :: dummy ( ) ) ;
23172316 let ( mac, attrs, _) = n. take_mac_call ( ) ;
2318- self . check_attributes ( & attrs, & mac) ;
2317+ self . check_attributes ( & attrs, & mac, node . node_id ( ) ) ;
23192318
23202319 * node = self . collect_bang ( mac, Node :: KIND ) . make_ast :: < Node > ( ) . into ( )
23212320 }
0 commit comments