rust/compiler/rustc_middle/src
许杰友 Jieyou Xu (Joe) ef4a7fb1b7
Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU
Mitigate `#[align]` name resolution ambiguity regression with a rename

Mitigates beta regression rust-lang/rust#143834 after a beta backport.

### Background on the beta regression

The name resolution regression arises due to rust-lang/rust#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](https://github.com/rust-lang/rust/issues/143834#issuecomment-3084415277), 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.
2025-07-22 00:54:28 +08:00
..
dep_graph Reuse metadata file from work products. 2025-07-04 14:02:17 +00:00
hir parse const trait Trait 2025-07-17 18:06:26 +08:00
hooks Move naked fn checks to hir_typeck 2025-05-30 16:08:44 +00:00
infer Add alias for ArgOutlivesPredicate 2025-07-15 16:02:26 +00:00
middle Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU 2025-07-22 00:54:28 +08:00
mir Rollup merge of #142673 - oli-obk:uninit-read-mem, r=RalfJung 2025-07-18 19:14:43 +02:00
query Auto merge of #143845 - cjgillot:stability-query, r=jieyouxu 2025-07-18 16:27:59 +00:00
thir loop match: run exhaustiveness check 2025-07-01 15:53:50 +02:00
traits Auto merge of #142911 - mejrs:unsized, r=compiler-errors 2025-07-11 05:27:32 +00:00
ty Rollup merge of #144216 - Nadrieril:revert-pin-hack, r=compiler-errors 2025-07-20 23:11:22 -04:00
util Remove attribute #[rustc_error] 2025-03-30 01:32:21 +03:00
arena.rs Define datastructures for #[cfg] attribute, move StrippedCfgItem 2025-07-15 09:01:00 +02:00
error.rs const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns 2025-06-26 18:09:47 +02:00
lib.rs Update cfg(bootstrap) 2025-07-01 10:55:49 -07:00
lint.rs decouple "reporting in deps" from future incompatibility reason 2025-06-03 10:49:22 +02:00
macros.rs Fold visit into ty 2025-03-15 06:34:36 +00:00
metadata.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
tests.rs Give an item related to issue 27438 a more meaningful name 2024-04-30 22:27:19 +02:00
thir.rs loop match: run exhaustiveness check 2025-07-01 15:53:50 +02:00
values.rs Use search_for_cycle_permutation to look for variances_of 2025-04-27 09:38:18 +02:00