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

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Jul 17, 2025

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 such as

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.

Alternative mitigation options

Various mitigation options were considered during the compiler triage meeting, 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.

@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

The Miri subtree was changed

cc @rust-lang/miri

@compiler-errors
Copy link
Member

We reserve rustc_ attrs, should we just give it a name w/ rustc_ as a prefix rather than such a random name? 😸

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 17, 2025

We reserve rustc_ attrs, should we just give it a name w/ rustc_ as a prefix rather than such a random name? 😸

That would require feature(rustc_attrs) gate too, right? I suppose that might be okay? I don't recall exactly if rustc_* attributes have other name resolution differences 🤔

I could give that a try when I wake up.

@compiler-errors
Copy link
Member

compiler-errors commented Jul 17, 2025

That would require feature(rustc_attrs) gate too, right?

For the tests that utilize the feature, yes, but presumably nobody should be using this feature anyways with this placeholder name.

There's no special resolver behavior for rustc_ attrs afaict, it's just a better sign that "this is a reserved name".

@jieyouxu
Copy link
Member Author

Yeah good point. I'll make that change.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 17, 2025
@folkertdev
Copy link
Contributor

btw this feature is actually used in the wild, and has worked reliably for years. We're allowed to break nightly features of course, but yeah, the rustc_align approach seems better than such a long/weird name.

@bors

This comment was marked as resolved.

@jieyouxu
Copy link
Member Author

Changes since last review:

  • Don't use such a long weird name, just use #[rustc_align].
  • Adjusted tests to account for needing #![feature(rustc_attrs)], in addition to reblessing for attr name change.

@jieyouxu

This comment was marked as resolved.

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.
@jieyouxu
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants