summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2025-07-18 00:10:46 +0800
committerJosh Stone <jistone@redhat.com>2025-07-24 11:02:01 -0700
commit2e832047c6bf348ba44fd57b21bada846d62f156 (patch)
tree2239e5eb288c561ba48135ba5ed537b743b51e9d /tests/codegen
parent43056c1614241ed06597a79b5e8f6464e6c8e11d (diff)
downloadrust-2e832047c6bf348ba44fd57b21bada846d62f156.tar.gz
rust-2e832047c6bf348ba44fd57b21bada846d62f156.zip
Mitigate `#[align]` name resolution ambiguity regression with a rename
From `#[align]` -> `#[rustc_align]`. Attributes starting with `rustc`
are always perma-unstable and feature-gated by `feature(rustc_attrs)`.

See regression RUST-143834.

For the underlying problem where even introducing new feature-gated
unstable built-in attributes can break user code such as

```rs
macro_rules! align {
    () => {
        /* .. */
    };
}

pub(crate) use align; // `use` here becomes ambiguous
```

refer to RUST-134963.

Since the `#[align]` attribute is still feature-gated by
`feature(fn_align)`, we can rename it as a mitigation. Note that
`#[rustc_align]` will obviously mean that current unstable user code
using `feature(fn_aling)` will need additionally `feature(rustc_attrs)`,
but this is a short-term mitigation to buy time, and is expected to be
changed to a better name with less collision potential.

See
<https://rust-lang.zulipchat.com/#narrow/channel/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202025-07-17/near/529290371>
where mitigation options were considered.

(cherry picked from commit 69b71e44107b4905ec7ad84ccb3edf4f14b3df69)
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/align-fn.rs26
-rw-r--r--tests/codegen/min-function-alignment.rs6
-rw-r--r--tests/codegen/naked-fn/aligned.rs5
-rw-r--r--tests/codegen/naked-fn/min-function-alignment.rs6
4 files changed, 26 insertions, 17 deletions
diff --git a/tests/codegen/align-fn.rs b/tests/codegen/align-fn.rs
index 267da060240..f30b63f96d5 100644
--- a/tests/codegen/align-fn.rs
+++ b/tests/codegen/align-fn.rs
@@ -1,11 +1,13 @@
 //@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
 
 #![crate_type = "lib"]
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
 
 // CHECK: align 16
 #[no_mangle]
-#[align(16)]
+#[rustc_align(16)]
 pub fn fn_align() {}
 
 pub struct A;
@@ -13,12 +15,12 @@ pub struct A;
 impl A {
     // CHECK: align 16
     #[no_mangle]
-    #[align(16)]
+    #[rustc_align(16)]
     pub fn method_align(self) {}
 
     // CHECK: align 16
     #[no_mangle]
-    #[align(16)]
+    #[rustc_align(16)]
     pub fn associated_fn() {}
 }
 
@@ -26,19 +28,19 @@ trait T: Sized {
     fn trait_fn() {}
 
     // CHECK: align 32
-    #[align(32)]
+    #[rustc_align(32)]
     fn trait_method(self) {}
 }
 
 impl T for A {
     // CHECK: align 16
     #[no_mangle]
-    #[align(16)]
+    #[rustc_align(16)]
     fn trait_fn() {}
 
     // CHECK: align 16
     #[no_mangle]
-    #[align(16)]
+    #[rustc_align(16)]
     fn trait_method(self) {}
 }
 
@@ -51,20 +53,20 @@ pub fn foo() {
 // CHECK-LABEL: align_specified_twice_1
 // CHECK-SAME: align 64
 #[no_mangle]
-#[align(32)]
-#[align(64)]
+#[rustc_align(32)]
+#[rustc_align(64)]
 pub fn align_specified_twice_1() {}
 
 // CHECK-LABEL: align_specified_twice_2
 // CHECK-SAME: align 128
 #[no_mangle]
-#[align(128)]
-#[align(32)]
+#[rustc_align(128)]
+#[rustc_align(32)]
 pub fn align_specified_twice_2() {}
 
 // CHECK-LABEL: align_specified_twice_3
 // CHECK-SAME: align 256
 #[no_mangle]
-#[align(32)]
-#[align(256)]
+#[rustc_align(32)]
+#[rustc_align(256)]
 pub fn align_specified_twice_3() {}
diff --git a/tests/codegen/min-function-alignment.rs b/tests/codegen/min-function-alignment.rs
index 75f845572a4..8ae2614e23e 100644
--- a/tests/codegen/min-function-alignment.rs
+++ b/tests/codegen/min-function-alignment.rs
@@ -4,6 +4,8 @@
 //@ [align1024] compile-flags: -Zmin-function-alignment=1024
 
 #![crate_type = "lib"]
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
 
 // functions without explicit alignment use the global minimum
@@ -18,7 +20,7 @@ pub fn no_explicit_align() {}
 // align16: align 16
 // align1024: align 1024
 #[no_mangle]
-#[align(8)]
+#[rustc_align(8)]
 pub fn lower_align() {}
 
 // the higher value of min-function-alignment and the align attribute wins out
@@ -27,7 +29,7 @@ pub fn lower_align() {}
 // align16: align 32
 // align1024: align 1024
 #[no_mangle]
-#[align(32)]
+#[rustc_align(32)]
 pub fn higher_align() {}
 
 // cold functions follow the same rules as other functions
diff --git a/tests/codegen/naked-fn/aligned.rs b/tests/codegen/naked-fn/aligned.rs
index f9fce8e5a5d..5b542043718 100644
--- a/tests/codegen/naked-fn/aligned.rs
+++ b/tests/codegen/naked-fn/aligned.rs
@@ -3,12 +3,15 @@
 //@ ignore-arm no "ret" mnemonic
 
 #![crate_type = "lib"]
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
+
 use std::arch::naked_asm;
 
 // CHECK: .balign 16
 // CHECK-LABEL: naked_empty:
-#[align(16)]
+#[rustc_align(16)]
 #[no_mangle]
 #[unsafe(naked)]
 pub extern "C" fn naked_empty() {
diff --git a/tests/codegen/naked-fn/min-function-alignment.rs b/tests/codegen/naked-fn/min-function-alignment.rs
index 59554c1cae5..2db5b73cba4 100644
--- a/tests/codegen/naked-fn/min-function-alignment.rs
+++ b/tests/codegen/naked-fn/min-function-alignment.rs
@@ -2,6 +2,8 @@
 //@ needs-asm-support
 //@ ignore-arm no "ret" mnemonic
 
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
 #![crate_type = "lib"]
 
@@ -16,7 +18,7 @@ pub extern "C" fn naked_no_explicit_align() {
 
 // CHECK: .balign 16
 #[no_mangle]
-#[align(8)]
+#[rustc_align(8)]
 #[unsafe(naked)]
 pub extern "C" fn naked_lower_align() {
     core::arch::naked_asm!("ret")
@@ -24,7 +26,7 @@ pub extern "C" fn naked_lower_align() {
 
 // CHECK: .balign 32
 #[no_mangle]
-#[align(32)]
+#[rustc_align(32)]
 #[unsafe(naked)]
 pub extern "C" fn naked_higher_align() {
     core::arch::naked_asm!("ret")