Skip to content

Commit 5d3f28a

Browse files
committed
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.
1 parent b2e94bf commit 5d3f28a

25 files changed

+269
-255
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub enum CfgEntry {
234234
pub enum AttributeKind {
235235
// tidy-alphabetical-start
236236
/// Represents `#[align(N)]`.
237+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
237238
Align { align: Align, span: Span },
238239

239240
/// Represents `#[rustc_allow_const_fn_unstable]`.

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
177177
sym::instruction_set,
178178
sym::repr,
179179
sym::rustc_std_internal_symbol,
180-
sym::align,
180+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
181+
sym::rustc_align,
181182
// obviously compatible with self
182183
sym::naked,
183184
// documentation

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn parse_alignment(node: &LitKind) -> Result<Align, &'static str> {
274274
pub(crate) struct AlignParser(Option<(Align, Span)>);
275275

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

280280
fn parse<'c, S: Stage>(

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
490490
),
491491
ungated!(no_link, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
492492
ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, EncodeCrossCrate::No),
493-
gated!(align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(align)),
493+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
494+
gated!(rustc_align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)),
494495
ungated!(unsafe(Edition2024) export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
495496
ungated!(unsafe(Edition2024) link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
496497
ungated!(unsafe(Edition2024) no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub struct CodegenFnAttrs {
7070
/// switching between multiple instruction sets.
7171
pub instruction_set: Option<InstructionSetAttr>,
7272
/// The `#[align(...)]` attribute. Determines the alignment of the function body.
73+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
7374
pub alignment: Option<Align>,
7475
/// The `#[patchable_function_entry(...)]` attribute. Indicates how many nops should be around
7576
/// the function entry.

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ pub fn check_builtin_meta_item(
294294
| sym::rustc_paren_sugar
295295
| sym::type_const
296296
| sym::repr
297-
| sym::align
297+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres
298+
// ambiguity
299+
| sym::rustc_align
298300
| sym::deprecated
299301
| sym::optimize
300302
| sym::pointee

compiler/rustc_passes/messages.ftl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ passes_abi_of =
1414
fn_abi_of({$fn_name}) = {$fn_abi}
1515
1616
passes_align_attr_application =
17-
`#[align(...)]` should be applied to a function item
17+
`#[rustc_align(...)]` should be applied to a function item
1818
.label = not a function item
1919
2020
passes_align_on_fields =
2121
attribute should be applied to a function or method
2222
.warn = {-passes_previously_accepted}
2323
2424
passes_align_should_be_repr_align =
25-
`#[align(...)]` is not supported on {$item} items
25+
`#[rustc_align(...)]` is not supported on {$item} items
2626
.suggestion = use `#[repr(align(...))]` instead
2727
2828
passes_allow_incoherent_impl =
@@ -604,7 +604,7 @@ passes_repr_align_greater_than_target_max =
604604
605605
passes_repr_align_should_be_align =
606606
`#[repr(align(...))]` is not supported on {$item} items
607-
.help = use `#[align(...)]` instead
607+
.help = use `#[rustc_align(...)]` instead
608608
609609
passes_repr_conflicting =
610610
conflicting representation hints

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19571957
}
19581958

19591959
/// Checks if the `#[align]` attributes on `item` are valid.
1960+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
19601961
fn check_align(
19611962
&self,
19621963
span: Span,

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,8 @@ symbols! {
18091809
rust_out,
18101810
rustc,
18111811
rustc_abi,
1812+
// FIXME(#82232, #143834): temporary name to mitigate `#[align]` nameres ambiguity
1813+
rustc_align,
18121814
rustc_allocator,
18131815
rustc_allocator_zeroed,
18141816
rustc_allow_const_fn_unstable,

src/tools/miri/tests/pass/fn_align.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
//@compile-flags: -Zmin-function-alignment=8
22
#![feature(fn_align)]
33

4+
// FIXME(rust-lang/rust#82232, rust-lang/rust#143834): temporarily renamed to mitigate `#[align]`
5+
// nameres ambiguity
6+
47
// When a function uses `align(N)`, the function address should be a multiple of `N`.
58

6-
#[align(256)]
9+
#[xxxxx_temp_mitigation_rename_of_align_xxxxx(256)]
710
fn foo() {}
811

9-
#[align(16)]
12+
#[xxxxx_temp_mitigation_rename_of_align_xxxxx(16)]
1013
fn bar() {}
1114

12-
#[align(4)]
15+
#[xxxxx_temp_mitigation_rename_of_align_xxxxx(4)]
1316
fn baz() {}
1417

1518
fn main() {

0 commit comments

Comments
 (0)