Skip to content

Commit 2e83204

Browse files
jieyouxucuviper
authored andcommitted
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 69b71e4)
1 parent 43056c1 commit 2e83204

File tree

21 files changed

+126
-116
lines changed

21 files changed

+126
-116
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl Deprecation {
184184
pub enum AttributeKind {
185185
// tidy-alphabetical-start
186186
/// Represents `#[align(N)]`.
187+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
187188
Align { align: Align, span: Span },
188189

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

compiler/rustc_attr_parsing/src/attributes/repr.rs

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

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

279279
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
@@ -495,7 +495,8 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
495495
),
496496
ungated!(no_link, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
497497
ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, EncodeCrossCrate::No),
498-
gated!(align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(align)),
498+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
499+
gated!(rustc_align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)),
499500
ungated!(unsafe(Edition2024) export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
500501
ungated!(unsafe(Edition2024) link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
501502
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
@@ -48,6 +48,7 @@ pub struct CodegenFnAttrs {
4848
/// switching between multiple instruction sets.
4949
pub instruction_set: Option<InstructionSetAttr>,
5050
/// The `#[align(...)]` attribute. Determines the alignment of the function body.
51+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
5152
pub alignment: Option<Align>,
5253
/// The `#[patchable_function_entry(...)]` attribute. Indicates how many nops should be around
5354
/// the function entry.

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ fn emit_malformed_attribute(
289289
| sym::rustc_force_inline
290290
| sym::rustc_confusables
291291
| sym::repr
292-
| sym::align
292+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
293+
| sym::rustc_align
293294
| sym::deprecated
294295
| sym::optimize
295296
| sym::cold

compiler/rustc_passes/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ passes_abi_of =
1414
fn_abi_of({$fn_name}) = {$fn_abi}
1515
1616
passes_align_should_be_repr_align =
17-
`#[align(...)]` is not supported on {$item} items
17+
`#[rustc_align(...)]` is not supported on {$item} items
1818
.suggestion = use `#[repr(align(...))]` instead
1919
2020
passes_allow_incoherent_impl =
@@ -589,7 +589,7 @@ passes_repr_align_greater_than_target_max =
589589
590590
passes_repr_align_should_be_align =
591591
`#[repr(align(...))]` is not supported on {$item} items
592-
.help = use `#[align(...)]` instead
592+
.help = use `#[rustc_align(...)]` instead
593593
594594
passes_repr_conflicting =
595595
conflicting representation hints

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
662662
sym::naked,
663663
sym::instruction_set,
664664
sym::repr,
665-
sym::align,
665+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
666+
sym::rustc_align,
666667
sym::rustc_std_internal_symbol,
667668
// documentation
668669
sym::doc,
@@ -1996,6 +1997,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19961997
}
19971998

19981999
/// Checks if the `#[align]` attributes on `item` are valid.
2000+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
19992001
fn check_align(&self, span: Span, target: Target, align: Align, repr_span: Span) {
20002002
match target {
20012003
Target::Fn | Target::Method(_) => {}

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,8 @@ symbols! {
18061806
rust_out,
18071807
rustc,
18081808
rustc_abi,
1809+
// FIXME(#82232, #143834): temporary name to mitigate `#[align]` nameres ambiguity
1810+
rustc_align,
18091811
rustc_allocator,
18101812
rustc_allocator_zeroed,
18111813
rustc_allow_const_fn_unstable,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
//@compile-flags: -Zmin-function-alignment=8
2+
3+
// FIXME(rust-lang/rust#82232, rust-lang/rust#143834): temporarily renamed to mitigate `#[align]`
4+
// nameres ambiguity
5+
#![feature(rustc_attrs)]
26
#![feature(fn_align)]
37

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

6-
#[align(256)]
10+
#[rustc_align(256)]
711
fn foo() {}
812

9-
#[align(16)]
13+
#[rustc_align(16)]
1014
fn bar() {}
1115

12-
#[align(4)]
16+
#[rustc_align(4)]
1317
fn baz() {}
1418

1519
fn main() {

tests/codegen/align-fn.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
11
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
22

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

68
// CHECK: align 16
79
#[no_mangle]
8-
#[align(16)]
10+
#[rustc_align(16)]
911
pub fn fn_align() {}
1012

1113
pub struct A;
1214

1315
impl A {
1416
// CHECK: align 16
1517
#[no_mangle]
16-
#[align(16)]
18+
#[rustc_align(16)]
1719
pub fn method_align(self) {}
1820

1921
// CHECK: align 16
2022
#[no_mangle]
21-
#[align(16)]
23+
#[rustc_align(16)]
2224
pub fn associated_fn() {}
2325
}
2426

2527
trait T: Sized {
2628
fn trait_fn() {}
2729

2830
// CHECK: align 32
29-
#[align(32)]
31+
#[rustc_align(32)]
3032
fn trait_method(self) {}
3133
}
3234

3335
impl T for A {
3436
// CHECK: align 16
3537
#[no_mangle]
36-
#[align(16)]
38+
#[rustc_align(16)]
3739
fn trait_fn() {}
3840

3941
// CHECK: align 16
4042
#[no_mangle]
41-
#[align(16)]
43+
#[rustc_align(16)]
4244
fn trait_method(self) {}
4345
}
4446

@@ -51,20 +53,20 @@ pub fn foo() {
5153
// CHECK-LABEL: align_specified_twice_1
5254
// CHECK-SAME: align 64
5355
#[no_mangle]
54-
#[align(32)]
55-
#[align(64)]
56+
#[rustc_align(32)]
57+
#[rustc_align(64)]
5658
pub fn align_specified_twice_1() {}
5759

5860
// CHECK-LABEL: align_specified_twice_2
5961
// CHECK-SAME: align 128
6062
#[no_mangle]
61-
#[align(128)]
62-
#[align(32)]
63+
#[rustc_align(128)]
64+
#[rustc_align(32)]
6365
pub fn align_specified_twice_2() {}
6466

6567
// CHECK-LABEL: align_specified_twice_3
6668
// CHECK-SAME: align 256
6769
#[no_mangle]
68-
#[align(32)]
69-
#[align(256)]
70+
#[rustc_align(32)]
71+
#[rustc_align(256)]
7072
pub fn align_specified_twice_3() {}

0 commit comments

Comments
 (0)