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.
143 lines
3.3 KiB
Rust
143 lines
3.3 KiB
Rust
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 -Clink-dead-code
|
|
//@ edition: 2024
|
|
//@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
|
|
|
|
#![crate_type = "lib"]
|
|
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
|
|
#![feature(rustc_attrs)]
|
|
#![feature(fn_align)]
|
|
|
|
// CHECK: align 16
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(16)]
|
|
pub fn fn_align() {}
|
|
|
|
pub struct A;
|
|
|
|
impl A {
|
|
// CHECK: align 16
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(16)]
|
|
pub fn method_align(self) {}
|
|
|
|
// CHECK: align 16
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(16)]
|
|
pub fn associated_fn() {}
|
|
}
|
|
|
|
trait T: Sized {
|
|
fn trait_fn() {}
|
|
|
|
fn trait_method(self) {}
|
|
|
|
#[rustc_align(8)]
|
|
fn trait_method_inherit_low(self);
|
|
|
|
#[rustc_align(32)]
|
|
fn trait_method_inherit_high(self);
|
|
|
|
#[rustc_align(32)]
|
|
fn trait_method_inherit_default(self) {}
|
|
|
|
#[rustc_align(4)]
|
|
#[rustc_align(128)]
|
|
#[rustc_align(8)]
|
|
fn inherit_highest(self) {}
|
|
}
|
|
|
|
impl T for A {
|
|
// CHECK-LABEL: trait_fn
|
|
// CHECK-SAME: align 16
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(16)]
|
|
fn trait_fn() {}
|
|
|
|
// CHECK-LABEL: trait_method
|
|
// CHECK-SAME: align 16
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(16)]
|
|
fn trait_method(self) {}
|
|
|
|
// The prototype's align is ignored because the align here is higher.
|
|
// CHECK-LABEL: trait_method_inherit_low
|
|
// CHECK-SAME: align 16
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(16)]
|
|
fn trait_method_inherit_low(self) {}
|
|
|
|
// The prototype's align is used because it is higher.
|
|
// CHECK-LABEL: trait_method_inherit_high
|
|
// CHECK-SAME: align 32
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(16)]
|
|
fn trait_method_inherit_high(self) {}
|
|
|
|
// The prototype's align inherited.
|
|
// CHECK-LABEL: trait_method_inherit_default
|
|
// CHECK-SAME: align 32
|
|
#[unsafe(no_mangle)]
|
|
fn trait_method_inherit_default(self) {}
|
|
|
|
// The prototype's highest align inherited.
|
|
// CHECK-LABEL: inherit_highest
|
|
// CHECK-SAME: align 128
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(32)]
|
|
#[rustc_align(64)]
|
|
fn inherit_highest(self) {}
|
|
}
|
|
|
|
trait HasDefaultImpl: Sized {
|
|
// CHECK-LABEL: inherit_from_default_method
|
|
// CHECK-LABEL: inherit_from_default_method
|
|
// CHECK-SAME: align 32
|
|
#[rustc_align(32)]
|
|
fn inherit_from_default_method(self) {}
|
|
}
|
|
|
|
pub struct InstantiateDefaultMethods;
|
|
|
|
impl HasDefaultImpl for InstantiateDefaultMethods {}
|
|
|
|
// CHECK-LABEL: align_specified_twice_1
|
|
// CHECK-SAME: align 64
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(32)]
|
|
#[rustc_align(64)]
|
|
pub fn align_specified_twice_1() {}
|
|
|
|
// CHECK-LABEL: align_specified_twice_2
|
|
// CHECK-SAME: align 128
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(128)]
|
|
#[rustc_align(32)]
|
|
pub fn align_specified_twice_2() {}
|
|
|
|
// CHECK-LABEL: align_specified_twice_3
|
|
// CHECK-SAME: align 256
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(32)]
|
|
#[rustc_align(256)]
|
|
pub fn align_specified_twice_3() {}
|
|
|
|
const _: () = {
|
|
// CHECK-LABEL: align_unmangled
|
|
// CHECK-SAME: align 256
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(32)]
|
|
#[rustc_align(256)]
|
|
extern "C" fn align_unmangled() {}
|
|
};
|
|
|
|
unsafe extern "C" {
|
|
#[rustc_align(256)]
|
|
fn align_unmangled();
|
|
}
|
|
|
|
// FIXME also check `gen` et al
|
|
// CHECK-LABEL: async_align
|
|
// CHECK-SAME: align 64
|
|
#[unsafe(no_mangle)]
|
|
#[rustc_align(64)]
|
|
pub async fn async_align() {}
|