Skip to content

Commit ea0e00c

Browse files
committed
mbe: Add tests for unsafe attr invocation
1 parent 05c5b87 commit ea0e00c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

tests/ui/macros/macro-rules-attr-error.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,22 @@ macro_rules! forward_referenced_attr {
5050
macro_rules! cyclic_attr {
5151
attr() {} => {}
5252
}
53+
54+
macro_rules! attr_with_safety {
55+
unsafe attr() { struct RequiresUnsafe; } => {};
56+
attr() { struct SafeInvocation; } => {};
57+
}
58+
59+
#[attr_with_safety]
60+
struct SafeInvocation;
61+
62+
//~v ERROR: unnecessary `unsafe` on safe attribute invocation
63+
#[unsafe(attr_with_safety)]
64+
struct SafeInvocation;
65+
66+
//~v ERROR: unsafe attribute invocation requires `unsafe`
67+
#[attr_with_safety]
68+
struct RequiresUnsafe;
69+
70+
#[unsafe(attr_with_safety)]
71+
struct RequiresUnsafe;

tests/ui/macros/macro-rules-attr-error.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ LL | #[local_attr]
99
|
1010
= note: this error originates in the attribute macro `local_attr` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

12+
error: unnecessary `unsafe` on safe attribute invocation
13+
--> $DIR/macro-rules-attr-error.rs:63:3
14+
|
15+
LL | #[unsafe(attr_with_safety)]
16+
| ^^^^^^
17+
18+
error: unsafe attribute invocation requires `unsafe`
19+
--> $DIR/macro-rules-attr-error.rs:67:1
20+
|
21+
LL | #[attr_with_safety]
22+
| ^^^^^^^^^^^^^^^^^^^
23+
1224
error: cannot find macro `local_attr` in this scope
1325
--> $DIR/macro-rules-attr-error.rs:27:5
1426
|
@@ -59,5 +71,5 @@ note: a macro with the same name exists, but it appears later
5971
LL | macro_rules! cyclic_attr {
6072
| ^^^^^^^^^^^
6173

62-
error: aborting due to 6 previous errors
74+
error: aborting due to 8 previous errors
6375

0 commit comments

Comments
 (0)