about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-04-14 21:55:39 +0200
committerGitHub <noreply@github.com>2025-04-14 21:55:39 +0200
commit1bceed826e9a8452716cb8aaa78b98f2aa669dfc (patch)
treedc78d7bc99b50b72104b3537d25107351dc894a9 /compiler/rustc_parse/src
parent6b3531e915179bf52962881bdb0f7ac7de293031 (diff)
parentcb22c1d5e949b64aafb99994befde4bd25a421e9 (diff)
downloadrust-1bceed826e9a8452716cb8aaa78b98f2aa669dfc.tar.gz
rust-1bceed826e9a8452716cb8aaa78b98f2aa669dfc.zip
Rollup merge of #139797 - folkertdev:naked-allow-unsafe, r=tgross35
Allow (but don't require) `#[unsafe(naked)]` so that `compiler-builtins` can upgrade to it

tracking issue: https://github.com/rust-lang/rust/issues/138997

Per https://github.com/rust-lang/rust/pull/134213#issuecomment-2755984503, we want to make the `#[naked]` attribute an unsafe attribute. Making that change runs into a cyclic dependency with `compiler-builtins` which uses `#[naked]`, where `rustc` needs an updated `compiler-builtins` and vice versa.

So based on https://github.com/rust-lang/rust/pull/139753 and [#t-compiler/help > updating &#96;compiler-builtins&#96; and &#96;rustc&#96;](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/updating.20.60compiler-builtins.60.20and.20.60rustc.60), this PR allows, but does not require `#[unsafe(naked)]`, and makes that change for some of the tests to check that both `#[naked]` and `#[unsafe(naked)]` are accepted.

Then we can upgrade and synchronize `compiler-builtins`, and then make `#[naked]` (without `unsafe`) invalid.

r? `@traviscross` (or someone from t-compiler if you're faster and this look allright)
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/validate_attr.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs
index 6a1c2af48ed..b518fca7a65 100644
--- a/compiler/rustc_parse/src/validate_attr.rs
+++ b/compiler/rustc_parse/src/validate_attr.rs
@@ -194,6 +194,12 @@ pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr:
             }
         }
     } else if let Safety::Unsafe(unsafe_span) = attr_item.unsafety {
+        // Allow (but don't require) `#[unsafe(naked)]` so that compiler-builtins can upgrade to it.
+        // FIXME(#139797): remove this special case when compiler-builtins has upgraded.
+        if attr.has_name(sym::naked) {
+            return;
+        }
+
         psess.dcx().emit_err(errors::InvalidAttrUnsafe {
             span: unsafe_span,
             name: attr_item.path.clone(),