about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-08-02 20:08:28 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2023-08-07 21:14:28 +0200
commitbdf4e3de9c4634af517c05c58f049eda0c28ea5f (patch)
tree06f15cc0d5f61d1459c99a6db6f4edbc3886a0c0 /tests
parentf1776250eb6034569617007abcd0b518f67dc20c (diff)
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/attributes/macro_export_on_decl_macro.rs9
-rw-r--r--tests/ui/attributes/macro_export_on_decl_macro.stderr16
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/attributes/macro_export_on_decl_macro.rs b/tests/ui/attributes/macro_export_on_decl_macro.rs
new file mode 100644
index 00000000000..e6fe66ac6c3
--- /dev/null
+++ b/tests/ui/attributes/macro_export_on_decl_macro.rs
@@ -0,0 +1,9 @@
+// Using #[macro_export] on a decl macro has no effect and should warn
+
+#![feature(decl_macro)]
+#![deny(unused)]
+
+#[macro_export] //~ ERROR `#[macro_export]` has no effect on declarative macro definitions
+pub macro foo() {}
+
+fn main() {}
diff --git a/tests/ui/attributes/macro_export_on_decl_macro.stderr b/tests/ui/attributes/macro_export_on_decl_macro.stderr
new file mode 100644
index 00000000000..565e07919bc
--- /dev/null
+++ b/tests/ui/attributes/macro_export_on_decl_macro.stderr
@@ -0,0 +1,16 @@
+error: `#[macro_export]` has no effect on declarative macro definitions
+  --> $DIR/macro_export_on_decl_macro.rs:6:1
+   |
+LL | #[macro_export]
+   | ^^^^^^^^^^^^^^^
+   |
+   = note: declarative macros follow the same exporting rules as regular items
+note: the lint level is defined here
+  --> $DIR/macro_export_on_decl_macro.rs:4:9
+   |
+LL | #![deny(unused)]
+   |         ^^^^^^
+   = note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]`
+
+error: aborting due to previous error
+