From ea0e00c5738f56970ad3ed3cc3d27c19715cd9ea Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 14 Sep 2025 16:28:50 +0800 Subject: mbe: Add tests for `unsafe` attr invocation --- tests/ui/macros/macro-rules-attr-error.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/ui/macros/macro-rules-attr-error.rs') diff --git a/tests/ui/macros/macro-rules-attr-error.rs b/tests/ui/macros/macro-rules-attr-error.rs index 81eadb6692f..60290b883cb 100644 --- a/tests/ui/macros/macro-rules-attr-error.rs +++ b/tests/ui/macros/macro-rules-attr-error.rs @@ -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; -- cgit 1.4.1-3-g733a5