Skip to content

Commit f14a512

Browse files
authored
Unrolled build for #144080
Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU Mitigate `#[align]` name resolution ambiguity regression with a rename Mitigates beta regression #143834 after a beta backport. ### Background on the beta regression The name resolution regression arises due to #142507 adding a new feature-gated built-in attribute named `#[align]`. However, unfortunately even [introducing new feature-gated unstable built-in attributes can break user code](https://www.github.com/rust-lang/rust/issues/134963) such as ```rs macro_rules! align { () => { /* .. */ }; } pub(crate) use align; // `use` here becomes ambiguous ``` ### Mitigation approach This PR renames `#[align]` to `#[rustc_align]` to mitigate the beta regression by: 1. Undoing the introduction of a new built-in attribute with a common name, i.e. `#[align]`. 2. Renaming `#[align]` to `#[rustc_align]`. The renamed attribute being `rustc_align` will not introduce new stable breakages, as attributes beginning with `rustc` are reserved and perma-unstable. This does mean existing nightly code using `fn_align` feature will additionally need to specify `#![feature(rustc_attrs)]`. This PR is very much a short-term mitigation to alleviate time pressure from having to fully fix the current limitation of inevitable name resolution regressions that would arise from adding any built-in attributes. Long-term solutions are discussed in [#t-lang > namespacing macro attrs to reduce conflicts with new adds](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/namespacing.20macro.20attrs.20to.20reduce.20conflicts.20with.20new.20adds/with/529249622). ### Alternative mitigation options [Various mitigation options were considered during the compiler triage meeting](#143834 (comment)), and those consideration are partly reproduced here: - Reverting the PR doesn't seem very minimal/trivial, and carries risks of its own. - Rename to a less-common but aim-to-stabilization name is itself not safe nor convenient, because (1) that risks introducing new regressions (i.e. ambiguity against the new name), and (2) lang would have to FCP the new name hastily for the mitigation to land timely and have a chance to be backported. This also makes the path towards stabilization annoying. - Rename the attribute to a rustc attribute, which will be perma-unstable and does not cause new ambiguities in stable code. - This alleviates the time pressure to address *this* regression, or for lang to have to rush an FCP for some new name that can still break user code. - This avoids backing out a whole implementation. ### Review advice This PR is best reviewed commit-by-commit. - Commit 1 adds a test `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` which demonstrates the current name resolution regression re. `align`. This test fails against current master. - Commit 2 carries out the renames and test reblesses. Notably, commit 2 will cause `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` to change from fail (nameres regression) to pass. This PR, if the approach still seems acceptable, will need a beta-backport to address the beta regression.
2 parents 3f9f20f + 69b71e4 commit f14a512

File tree

24 files changed

+285
-227
lines changed

24 files changed

+285
-227
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 =
@@ -605,7 +605,7 @@ passes_repr_align_greater_than_target_max =
605605
606606
passes_repr_align_should_be_align =
607607
`#[repr(align(...))]` is not supported on {$item} items
608-
.help = use `#[align(...)]` instead
608+
.help = use `#[rustc_align(...)]` instead
609609
610610
passes_repr_conflicting =
611611
conflicting representation hints

compiler/rustc_passes/src/check_attr.rs

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

19721972
/// Checks if the `#[align]` attributes on `item` are valid.
1973+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
19731974
fn check_align(
19741975
&self,
19751976
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: 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() {

0 commit comments

Comments
 (0)