From 9aee0aa453a83f8bee6dc32037e0389f3a9188fe Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Sat, 3 May 2025 19:10:43 +0200 Subject: [PATCH] allow `#[rustfmt::skip]` in combination with `#[naked]` --- compiler/rustc_passes/src/check_attr.rs | 4 +++- tests/ui/asm/naked-functions.rs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index f04b167889f19..e5b20901c0c26 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -683,7 +683,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - if !other_attr.has_any_name(ALLOW_LIST) { + if !other_attr.has_any_name(ALLOW_LIST) + && !matches!(other_attr.path().as_slice(), [sym::rustfmt, ..]) + { let path = other_attr.path(); let path: Vec<_> = path.iter().map(|s| s.as_str()).collect(); let other_attr_name = path.join("::"); diff --git a/tests/ui/asm/naked-functions.rs b/tests/ui/asm/naked-functions.rs index cb5fde9a80b81..a6f41698b4117 100644 --- a/tests/ui/asm/naked-functions.rs +++ b/tests/ui/asm/naked-functions.rs @@ -231,3 +231,9 @@ pub extern "C" fn compatible_linkage() { pub extern "C" fn rustc_std_internal_symbol() { naked_asm!("", options(raw)); } + +#[rustfmt::skip] +#[unsafe(naked)] +pub extern "C" fn rustfmt_skip() { + naked_asm!("", options(raw)); +}