@@ -19,9 +19,8 @@ use syntax::ext::base::{MacroKind, SyntaxExtension};
19
19
use syntax:: ext:: expand:: { AstFragment , Invocation , InvocationKind } ;
20
20
use syntax:: ext:: hygiene:: Mark ;
21
21
use syntax:: ext:: tt:: macro_rules;
22
- use syntax:: feature_gate:: {
23
- feature_err, is_builtin_attr_name, AttributeGate , GateIssue , Stability , BUILTIN_ATTRIBUTES ,
24
- } ;
22
+ use syntax:: feature_gate:: { feature_err, emit_feature_err, is_builtin_attr_name} ;
23
+ use syntax:: feature_gate:: { AttributeGate , GateIssue , Stability , BUILTIN_ATTRIBUTES } ;
25
24
use syntax:: symbol:: { Symbol , kw, sym} ;
26
25
use syntax:: visit:: Visitor ;
27
26
use syntax:: util:: lev_distance:: find_best_match_for_name;
@@ -298,12 +297,25 @@ impl<'a> Resolver<'a> {
298
297
let res = self . resolve_macro_to_res_inner ( path, kind, parent_scope, trace, force) ;
299
298
300
299
// Report errors and enforce feature gates for the resolved macro.
300
+ let features = self . session . features_untracked ( ) ;
301
301
if res != Err ( Determinacy :: Undetermined ) {
302
302
// Do not report duplicated errors on every undetermined resolution.
303
303
for segment in & path. segments {
304
304
if let Some ( args) = & segment. args {
305
305
self . session . span_err ( args. span ( ) , "generic arguments in macro path" ) ;
306
306
}
307
+ if kind == MacroKind :: Attr && !features. rustc_attrs &&
308
+ segment. ident . as_str ( ) . starts_with ( "rustc" ) {
309
+ let msg = "attributes starting with `rustc` are \
310
+ reserved for use by the `rustc` compiler";
311
+ emit_feature_err (
312
+ & self . session . parse_sess ,
313
+ sym:: rustc_attrs,
314
+ segment. ident . span ,
315
+ GateIssue :: Language ,
316
+ msg,
317
+ ) ;
318
+ }
307
319
}
308
320
}
309
321
@@ -320,18 +332,10 @@ impl<'a> Resolver<'a> {
320
332
}
321
333
Res :: NonMacroAttr ( attr_kind) => {
322
334
if kind == MacroKind :: Attr {
323
- let features = self . session . features_untracked ( ) ;
324
335
if attr_kind == NonMacroAttrKind :: Custom {
325
336
assert ! ( path. segments. len( ) == 1 ) ;
326
337
let name = path. segments [ 0 ] . ident . as_str ( ) ;
327
- if name. starts_with ( "rustc_" ) {
328
- if !features. rustc_attrs {
329
- let msg = "unless otherwise specified, attributes with the prefix \
330
- `rustc_` are reserved for internal compiler diagnostics";
331
- self . report_unknown_attribute ( path. span , & name, msg,
332
- sym:: rustc_attrs) ;
333
- }
334
- } else if !features. custom_attribute {
338
+ if !features. custom_attribute && !name. starts_with ( "rustc_" ) {
335
339
let msg = format ! ( "The attribute `{}` is currently unknown to the \
336
340
compiler and may have meaning added to it in the \
337
341
future", path) ;
0 commit comments