Skip to content

Mitigate #[align] name resolution ambiguity regression with a rename #144080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ pub enum CfgEntry {
pub enum AttributeKind {
// tidy-alphabetical-start
/// Represents `#[align(N)]`.
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
Align { align: Align, span: Span },

/// Represents `#[rustc_allow_const_fn_unstable]`.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
sym::instruction_set,
sym::repr,
sym::rustc_std_internal_symbol,
sym::align,
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
sym::rustc_align,
// obviously compatible with self
sym::naked,
// documentation
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn parse_alignment(node: &LitKind) -> Result<Align, &'static str> {
pub(crate) struct AlignParser(Option<(Align, Span)>);

impl AlignParser {
const PATH: &'static [Symbol] = &[sym::align];
const PATH: &'static [Symbol] = &[sym::rustc_align];
const TEMPLATE: AttributeTemplate = template!(List: "<alignment in bytes>");

fn parse<'c, S: Stage>(
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
ungated!(no_link, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, EncodeCrossCrate::No),
gated!(align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(align)),
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
gated!(rustc_align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)),
ungated!(unsafe(Edition2024) export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
ungated!(unsafe(Edition2024) link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
ungated!(unsafe(Edition2024) no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct CodegenFnAttrs {
/// switching between multiple instruction sets.
pub instruction_set: Option<InstructionSetAttr>,
/// The `#[align(...)]` attribute. Determines the alignment of the function body.
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
pub alignment: Option<Align>,
/// The `#[patchable_function_entry(...)]` attribute. Indicates how many nops should be around
/// the function entry.
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ pub fn check_builtin_meta_item(
| sym::rustc_paren_sugar
| sym::type_const
| sym::repr
| sym::align
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres
// ambiguity
| sym::rustc_align
| sym::deprecated
| sym::optimize
| sym::pointee
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ passes_abi_of =
fn_abi_of({$fn_name}) = {$fn_abi}
passes_align_attr_application =
`#[align(...)]` should be applied to a function item
`#[rustc_align(...)]` should be applied to a function item
.label = not a function item
passes_align_on_fields =
attribute should be applied to a function or method
.warn = {-passes_previously_accepted}
passes_align_should_be_repr_align =
`#[align(...)]` is not supported on {$item} items
`#[rustc_align(...)]` is not supported on {$item} items
.suggestion = use `#[repr(align(...))]` instead
passes_allow_incoherent_impl =
Expand Down Expand Up @@ -604,7 +604,7 @@ passes_repr_align_greater_than_target_max =
passes_repr_align_should_be_align =
`#[repr(align(...))]` is not supported on {$item} items
.help = use `#[align(...)]` instead
.help = use `#[rustc_align(...)]` instead
passes_repr_conflicting =
conflicting representation hints
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}

/// Checks if the `#[align]` attributes on `item` are valid.
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
fn check_align(
&self,
span: Span,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ symbols! {
rust_out,
rustc,
rustc_abi,
// FIXME(#82232, #143834): temporary name to mitigate `#[align]` nameres ambiguity
rustc_align,
rustc_allocator,
rustc_allocator_zeroed,
rustc_allow_const_fn_unstable,
Expand Down
10 changes: 7 additions & 3 deletions src/tools/miri/tests/pass/fn_align.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
//@compile-flags: -Zmin-function-alignment=8

// FIXME(rust-lang/rust#82232, rust-lang/rust#143834): temporarily renamed to mitigate `#[align]`
// nameres ambiguity
#![feature(rustc_attrs)]
#![feature(fn_align)]

// When a function uses `align(N)`, the function address should be a multiple of `N`.

#[align(256)]
#[rustc_align(256)]
fn foo() {}

#[align(16)]
#[rustc_align(16)]
fn bar() {}

#[align(4)]
#[rustc_align(4)]
fn baz() {}

fn main() {
Expand Down
54 changes: 28 additions & 26 deletions tests/codegen/align-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
//@ 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)]
#[align(16)]
#[rustc_align(16)]
pub fn fn_align() {}

pub struct A;

impl A {
// CHECK: align 16
#[unsafe(no_mangle)]
#[align(16)]
#[rustc_align(16)]
pub fn method_align(self) {}

// CHECK: align 16
#[unsafe(no_mangle)]
#[align(16)]
#[rustc_align(16)]
pub fn associated_fn() {}
}

Expand All @@ -29,46 +31,46 @@ trait T: Sized {

fn trait_method(self) {}

#[align(8)]
#[rustc_align(8)]
fn trait_method_inherit_low(self);

#[align(32)]
#[rustc_align(32)]
fn trait_method_inherit_high(self);

#[align(32)]
#[rustc_align(32)]
fn trait_method_inherit_default(self) {}

#[align(4)]
#[align(128)]
#[align(8)]
#[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)]
#[align(16)]
#[rustc_align(16)]
fn trait_fn() {}

// CHECK-LABEL: trait_method
// CHECK-SAME: align 16
#[unsafe(no_mangle)]
#[align(16)]
#[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)]
#[align(16)]
#[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)]
#[align(16)]
#[rustc_align(16)]
fn trait_method_inherit_high(self) {}

// The prototype's align inherited.
Expand All @@ -81,16 +83,16 @@ impl T for A {
// CHECK-LABEL: inherit_highest
// CHECK-SAME: align 128
#[unsafe(no_mangle)]
#[align(32)]
#[align(64)]
#[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
#[align(32)]
#[rustc_align(32)]
fn inherit_from_default_method(self) {}
}

Expand All @@ -101,41 +103,41 @@ impl HasDefaultImpl for InstantiateDefaultMethods {}
// CHECK-LABEL: align_specified_twice_1
// CHECK-SAME: align 64
#[unsafe(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
#[unsafe(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
#[unsafe(no_mangle)]
#[align(32)]
#[align(256)]
#[rustc_align(32)]
#[rustc_align(256)]
pub fn align_specified_twice_3() {}

const _: () = {
// CHECK-LABEL: align_unmangled
// CHECK-SAME: align 256
#[unsafe(no_mangle)]
#[align(32)]
#[align(256)]
#[rustc_align(32)]
#[rustc_align(256)]
extern "C" fn align_unmangled() {}
};

unsafe extern "C" {
#[align(256)]
#[rustc_align(256)]
fn align_unmangled();
}

// FIXME also check `gen` et al
// CHECK-LABEL: async_align
// CHECK-SAME: align 64
#[unsafe(no_mangle)]
#[align(64)]
#[rustc_align(64)]
pub async fn async_align() {}
6 changes: 4 additions & 2 deletions tests/codegen/min-function-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//@ 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)]

// Functions without explicit alignment use the global minimum.
Expand All @@ -21,7 +23,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
Expand All @@ -30,7 +32,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
Expand Down
5 changes: 4 additions & 1 deletion tests/codegen/naked-fn/aligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
//@ 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)]

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() {
Expand Down
6 changes: 4 additions & 2 deletions tests/codegen/naked-fn/min-function-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//@ ignore-arm no "ret" mnemonic
//@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)

// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
#![feature(rustc_attrs)]
#![feature(fn_align)]
#![crate_type = "lib"]

Expand All @@ -17,15 +19,15 @@ 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")
}

// CHECK: .balign 32
#[no_mangle]
#[align(32)]
#[rustc_align(32)]
#[unsafe(naked)]
pub extern "C" fn naked_higher_align() {
core::arch::naked_asm!("ret")
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/asm/naked-with-invalid-repr-attr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//@ needs-asm-support

// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
#![feature(rustc_attrs)]
#![feature(fn_align)]

#![crate_type = "lib"]
use std::arch::naked_asm;

Expand All @@ -21,7 +25,7 @@ extern "C" fn example2() {

#[repr(C)]
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
#[align(16)]
#[rustc_align(16)]
#[unsafe(naked)]
extern "C" fn example3() {
//~^ NOTE not a struct, enum, or union
Expand Down
Loading
Loading