check_attrs: Warn when #[macro_export] is used on macros 2.0
The compiler should emit a more specific error when the `#[macro_export]` attribute is present on a decl macro, instead of silently ignoring it. This commit adds the required error message in rustc_passes/messages.ftl, as well as a note. A new variant is added to the `errors::MacroExport` enum, specifically for the case where the attribute is added to a macro 2.0.
This commit is contained in:
parent
f1776250eb
commit
bdf4e3de9c
5 changed files with 47 additions and 0 deletions
|
@ -2133,6 +2133,20 @@ impl CheckAttrVisitor<'_> {
|
|||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// special case when `#[macro_export]` is applied to a macro 2.0
|
||||
let (macro_definition, _) =
|
||||
self.tcx.hir().find(hir_id).unwrap().expect_item().expect_macro();
|
||||
let is_decl_macro = !macro_definition.macro_rules;
|
||||
|
||||
if is_decl_macro {
|
||||
self.tcx.emit_spanned_lint(
|
||||
UNUSED_ATTRIBUTES,
|
||||
hir_id,
|
||||
attr.span,
|
||||
errors::MacroExport::OnDeclMacro,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -690,6 +690,10 @@ pub enum MacroExport {
|
|||
#[diag(passes_macro_export)]
|
||||
Normal,
|
||||
|
||||
#[diag(passes_macro_export_on_decl_macro)]
|
||||
#[note]
|
||||
OnDeclMacro,
|
||||
|
||||
#[diag(passes_invalid_macro_export_arguments)]
|
||||
UnknownItem { name: Symbol },
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue