@@ -28,6 +28,7 @@ use syntax::ext::expand::{AstFragment, Invocation, InvocationKind};
28
28
use syntax:: ext:: hygiene:: { self , Mark } ;
29
29
use syntax:: ext:: tt:: macro_rules;
30
30
use syntax:: feature_gate:: { self , feature_err, emit_feature_err, is_builtin_attr_name, GateIssue } ;
31
+ use syntax:: feature_gate:: EXPLAIN_DERIVE_UNDERSCORE ;
31
32
use syntax:: fold:: { self , Folder } ;
32
33
use syntax:: parse:: parser:: PathStyle ;
33
34
use syntax:: parse:: token:: { self , Token } ;
@@ -195,9 +196,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
195
196
196
197
self . current_module = invocation. module . get ( ) ;
197
198
self . current_module . unresolved_invocations . borrow_mut ( ) . remove ( & mark) ;
198
- self . unresolved_invocations_macro_export . remove ( & mark) ;
199
199
self . current_module . unresolved_invocations . borrow_mut ( ) . extend ( derives) ;
200
- self . unresolved_invocations_macro_export . extend ( derives) ;
201
200
for & derive in derives {
202
201
self . invocations . insert ( derive, invocation) ;
203
202
}
@@ -338,19 +337,37 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
338
337
match attr_kind {
339
338
NonMacroAttrKind :: Tool | NonMacroAttrKind :: DeriveHelper |
340
339
NonMacroAttrKind :: Custom if is_attr_invoc => {
340
+ let features = self . session . features_untracked ( ) ;
341
341
if attr_kind == NonMacroAttrKind :: Tool &&
342
- !self . session . features_untracked ( ) . tool_attributes {
342
+ !features . tool_attributes {
343
343
feature_err ( & self . session . parse_sess , "tool_attributes" ,
344
344
invoc. span ( ) , GateIssue :: Language ,
345
345
"tool attributes are unstable" ) . emit ( ) ;
346
346
}
347
- if attr_kind == NonMacroAttrKind :: Custom &&
348
- !self . session . features_untracked ( ) . custom_attribute {
349
- let msg = format ! ( "The attribute `{}` is currently unknown to the compiler \
350
- and may have meaning added to it in the future", path) ;
351
- feature_err ( & self . session . parse_sess , "custom_attribute" , invoc. span ( ) ,
352
- GateIssue :: Language , & msg) . emit ( ) ;
347
+ if attr_kind == NonMacroAttrKind :: Custom {
348
+ assert ! ( path. segments. len( ) == 1 ) ;
349
+ let name = path. segments [ 0 ] . ident . name . as_str ( ) ;
350
+ if name. starts_with ( "rustc_" ) {
351
+ if !features. rustc_attrs {
352
+ let msg = "unless otherwise specified, attributes with the prefix \
353
+ `rustc_` are reserved for internal compiler diagnostics";
354
+ feature_err ( & self . session . parse_sess , "rustc_attrs" , invoc. span ( ) ,
355
+ GateIssue :: Language , & msg) . emit ( ) ;
356
+ }
357
+ } else if name. starts_with ( "derive_" ) {
358
+ if !features. custom_derive {
359
+ feature_err ( & self . session . parse_sess , "custom_derive" , invoc. span ( ) ,
360
+ GateIssue :: Language , EXPLAIN_DERIVE_UNDERSCORE ) . emit ( ) ;
361
+ }
362
+ } else if !features. custom_attribute {
363
+ let msg = format ! ( "The attribute `{}` is currently unknown to the \
364
+ compiler and may have meaning added to it in the \
365
+ future", path) ;
366
+ feature_err ( & self . session . parse_sess , "custom_attribute" , invoc. span ( ) ,
367
+ GateIssue :: Language , & msg) . emit ( ) ;
368
+ }
353
369
}
370
+
354
371
return Ok ( Some ( Lrc :: new ( SyntaxExtension :: NonMacroAttr {
355
372
mark_used : attr_kind == NonMacroAttrKind :: Tool ,
356
373
} ) ) ) ;
@@ -650,7 +667,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
650
667
}
651
668
}
652
669
WhereToResolve :: BuiltinAttrs => {
653
- if is_builtin_attr_name ( ident. name ) {
670
+ // FIXME: Only built-in attributes are not considered as candidates for
671
+ // non-attributes to fight off regressions on stable channel (#53205).
672
+ // We need to come up with some more principled approach instead.
673
+ if is_attr && is_builtin_attr_name ( ident. name ) {
654
674
let binding = ( Def :: NonMacroAttr ( NonMacroAttrKind :: Builtin ) ,
655
675
ty:: Visibility :: Public , ident. span , Mark :: root ( ) )
656
676
. to_name_binding ( self . arenas ) ;
0 commit comments