mbe: Add tests for unsafe attr invocation

This commit is contained in:
Josh Triplett 2025-09-14 16:28:50 +08:00
parent 05c5b87797
commit ea0e00c573
2 changed files with 32 additions and 1 deletions

View file

@ -50,3 +50,22 @@ macro_rules! forward_referenced_attr {
macro_rules! cyclic_attr {
attr() {} => {}
}
macro_rules! attr_with_safety {
unsafe attr() { struct RequiresUnsafe; } => {};
attr() { struct SafeInvocation; } => {};
}
#[attr_with_safety]
struct SafeInvocation;
//~v ERROR: unnecessary `unsafe` on safe attribute invocation
#[unsafe(attr_with_safety)]
struct SafeInvocation;
//~v ERROR: unsafe attribute invocation requires `unsafe`
#[attr_with_safety]
struct RequiresUnsafe;
#[unsafe(attr_with_safety)]
struct RequiresUnsafe;

View file

@ -9,6 +9,18 @@ LL | #[local_attr]
|
= note: this error originates in the attribute macro `local_attr` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unnecessary `unsafe` on safe attribute invocation
--> $DIR/macro-rules-attr-error.rs:63:3
|
LL | #[unsafe(attr_with_safety)]
| ^^^^^^
error: unsafe attribute invocation requires `unsafe`
--> $DIR/macro-rules-attr-error.rs:67:1
|
LL | #[attr_with_safety]
| ^^^^^^^^^^^^^^^^^^^
error: cannot find macro `local_attr` in this scope
--> $DIR/macro-rules-attr-error.rs:27:5
|
@ -59,5 +71,5 @@ note: a macro with the same name exists, but it appears later
LL | macro_rules! cyclic_attr {
| ^^^^^^^^^^^
error: aborting due to 6 previous errors
error: aborting due to 8 previous errors