diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-10-02 10:27:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-02 10:27:49 +0200 |
| commit | ac7beab527861103dd1e1515d534f87956786554 (patch) | |
| tree | 52d7ecb9c0fd9d077a7a7a897d052734e2629cb7 /compiler/rustc_attr_parsing/src | |
| parent | 92aac1bdf61642cfc99498ca86e663cf53d2039e (diff) | |
| parent | 4fc0a0d42a66e9b248fa527f7f063ec7226803dd (diff) | |
| download | rust-ac7beab527861103dd1e1515d534f87956786554.tar.gz rust-ac7beab527861103dd1e1515d534f87956786554.zip | |
Rollup merge of #146535 - joshtriplett:mbe-unsafe-attr, r=petrochenkov
mbe: Implement `unsafe` attribute rules This implements `unsafe attr` rules for declarative `macro_rules!` attributes, as specified in [RFC 3697](https://github.com/rust-lang/rfcs/pull/3697). An invocation of an attribute that uses an `unsafe attr` rule requires the `unsafe(attr(...))` syntax. An invocation of an attribute that uses an ordinary `attr` rule must *not* use the `unsafe(attr(...))` syntax. `unsafe` is only supported on an `attr` rule, not any other kind of `macro_rules!` rule. Tracking issue for `macro_rules!` attributes: https://github.com/rust-lang/rust/issues/143547
Diffstat (limited to 'compiler/rustc_attr_parsing/src')
| -rw-r--r-- | compiler/rustc_attr_parsing/src/validate_attr.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/compiler/rustc_attr_parsing/src/validate_attr.rs b/compiler/rustc_attr_parsing/src/validate_attr.rs index 7a7624893bd..927417f89f8 100644 --- a/compiler/rustc_attr_parsing/src/validate_attr.rs +++ b/compiler/rustc_attr_parsing/src/validate_attr.rs @@ -207,10 +207,9 @@ pub fn check_attribute_safety( } } - // - Normal builtin attribute, or any non-builtin attribute - // - All non-builtin attributes are currently considered safe; writing `#[unsafe(..)]` is - // not permitted on non-builtin attributes or normal builtin attributes - (Some(AttributeSafety::Normal) | None, Safety::Unsafe(unsafe_span)) => { + // - Normal builtin attribute + // - Writing `#[unsafe(..)]` is not permitted on normal builtin attributes + (Some(AttributeSafety::Normal), Safety::Unsafe(unsafe_span)) => { psess.dcx().emit_err(errors::InvalidAttrUnsafe { span: unsafe_span, name: attr_item.path.clone(), @@ -224,9 +223,8 @@ pub fn check_attribute_safety( } // - Non-builtin attribute - // - No explicit `#[unsafe(..)]` written. - (None, Safety::Default) => { - // OK + (None, Safety::Unsafe(_) | Safety::Default) => { + // OK (not checked here) } ( |
