about summary refs log tree commit diff
path: root/compiler/rustc_attr_parsing/src/attributes
AgeCommit message (Collapse)AuthorLines
2025-07-22Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU许杰友 Jieyou Xu (Joe)-2/+3
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-19Mitigate `#[align]` name resolution ambiguity regression with a renameJieyou Xu-2/+3
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.
2025-07-18Auto merge of #143845 - cjgillot:stability-query, r=jieyouxubors-4/+4
Split-up stability_index query This PR aims to move deprecation and stability processing away from the monolithic `stability_index` query, and directly implement `lookup_{deprecation,stability,body_stability,const_stability}` queries. The basic idea is to: - move per-attribute sanity checks into `check_attr.rs`; - move attribute compatibility checks into the `MissingStabilityAnnotations` visitor; - progressively dismantle the `Annotator` visitor and the `stability_index` query. The first commit contains functional change, and now warns when `#[automatically_derived]` is applied on a non-trait impl block. The other commits should not change visible behaviour. Perf in https://github.com/rust-lang/rust/pull/143845#issuecomment-3066308630 shows small but consistent improvement, except for unused-warnings case. That case being a stress test, I'm leaning towards accepting the regression. This PR changes `check_attr`, so has a high conflict rate on that file. This should not cause issues for review.
2025-07-18Rollup merge of #143891 - scrabsha:push-xxtttopqoprr, r=jdonszelmannMatthias Krüger-1/+40
Port `#[coverage]` to the new attribute system r? ``````@jdonszelmann``````
2025-07-17Include ErrorGuaranteed in StableSince::Err.Camille GILLOT-4/+4
2025-07-17Auto merge of #143879 - fee1-dead-contrib:push-lrlpoouyqqry, r=fmeasebors-0/+1
parse `const trait Trait` r? oli-obk or anyone from project-const-traits cc `@rust-lang/project-const-traits`
2025-07-17parse `const trait Trait`Deadbeef-0/+1
2025-07-17Rollup merge of #143984 - JonathanBrouwer:fix-feature-gate-ice, r=UrgauMatthias Krüger-23/+30
Fix ice for feature-gated `cfg` attributes applied to the crate This PR fixes two fixes: 1. When a feature gated option of the `cfg` attribute is applied to the crate, an ICE would occur because features are not yet available at that stage. This is fixed by ignoring the feature gate at that point, the attribute will later be re-checked (this was already done) when the feature gate is available. Fixes https://github.com/rust-lang/rust/issues/143977 2. Errors and lints on the `cfg` attribute applied to the crate would be produced twice, because of the re-checking. This is fixed by not producing any errors and lints during the first run. The added regression test checks both problems. r? ``@jdonszelmann``
2025-07-17Auto merge of #140399 - tiif:unstable_impl, r=lcnr,BoxyUwUbors-0/+30
Implement unstable trait impl This PR allows marking impls of stable trait with stable type as unstable. ## Approach In std/core, an impl can be marked as unstable by annotating it with ``#[unstable_feature_bound(feat_name)]``. This will add a ``ClauseKind::Unstable_Feature(feat_name)`` to the list of predicates in ``predicates_of`` . When an unstable impl's function is called, we will first iterate through all the goals in ``param_env`` to check if there is any ``ClauseKind::UnstableFeature(feat_name)`` in ``param_env``. The existence of ``ClauseKind::Unstable_Feature(feat_name)`` in ``param_env`` means an``#[unstable_feature_bound(feat_name)]`` is present at the call site of the function, so we allow the check to succeed in this case. If ``ClauseKind::UnstableFeature(feat_name)`` does not exist in ``param_env``, we will still allow the check to succeed for either of the cases below: 1. The feature is enabled through ``#[feature(feat_name)]`` outside of std / core. 2. We are in codegen because we may be monomorphizing a body from an upstream crate which had an unstable feature enabled that the downstream crate do not. For the rest of the case, it will fail with ambiguity. ## Limitation In this PR, we do not support: 1. using items that need ``#[unstable_feature_bound]`` within stable APIs 2. annotate main function with ``#[unstable_feature_bound]`` 3. annotate ``#[unstable_feature_bound]`` on items other than free function and impl ## Acknowledgement The design and mentoring are done by `@BoxyUwU`
2025-07-16Port `#[coverage]` to the new attribute systemSasha Pourcelot-1/+40
2025-07-15Fix ice for feature-gated cfg attributes applied to the crateJonathan Brouwer-23/+30
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-15Lint against having both #[unstable_feature_bound] and #[stable] on the same ↵tiif-0/+10
item
2025-07-15Setup unstable feature bound attributetiif-0/+20
2025-07-15Auto merge of #143958 - samueltardieu:rollup-lh1s143, r=samueltardieubors-0/+7
Rollup of 13 pull requests Successful merges: - rust-lang/rust#142301 (tests: Fix duplicated-path-in-error fail with musl) - rust-lang/rust#143630 (Drop `./x suggest`) - rust-lang/rust#143736 (Give all bytes of TypeId provenance) - rust-lang/rust#143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler) - rust-lang/rust#143837 (Adjust `run_make_support::symbols` helpers) - rust-lang/rust#143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - rust-lang/rust#143905 (Recover and suggest to use `;` to construct array type) - rust-lang/rust#143907 (core: make `str::split_at_unchecked()` inline) - rust-lang/rust#143910 (Add experimental `backtrace-trace-only` std feature) - rust-lang/rust#143927 (Preserve constness in trait objects up to hir ty lowering) - rust-lang/rust#143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself) - rust-lang/rust#143938 (Update books) - rust-lang/rust#143941 (update `cfg_select!` documentation) Failed merges: - rust-lang/rust#143926 (Remove deprecated fields in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-15Define attribute parser & config evaluatorJonathan Brouwer-210/+254
2025-07-15Move `cfg` -> `cfg_old`Jonathan Brouwer-0/+248
2025-07-14Port `#[pointee]` to the new attribute parsing infrastructureJonathan Brouwer-0/+7
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-14Rollup merge of #143855 - JonathanBrouwer:omit_gdb_pretty_printer_section, ↵Samuel Tardieu-0/+8
r=jdonszelmann Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing Ports `#[omit_gdb_pretty_printer_section]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163 r? ```@jdonszelmann```
2025-07-14Rollup merge of #143217 - Periodic1911:link-ordinal, r=jdonszelmannJakub Beránek-32/+41
Port #[link_ordinal] to the new attribute parsing infrastructure Ports link_ordinal to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197
2025-07-13Port `#[link_ordinal]` to the new attribute parsing infrastructure.Anne Stijns-32/+41
2025-07-12Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing ↵Jonathan Brouwer-0/+8
infrastructure Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-12Port `#[automatically_derived]` to the new attribute parsing infrastructureJonathan Brouwer-0/+7
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-11Rollup merge of #143403 - GrigorenkoPV:attributes/traits, r=jdonszelmannMatthias Krüger-3/+96
Port several trait/coherence-related attributes the new attribute system Part of rust-lang/rust#131229 This ports: - `#[const_trait]` - `#[rustc_deny_explicit_impl]` - `#[rustc_do_not_implement_via_object]` - `#[rustc_coinductive]` - `#[type_const]` - `#[rustc_specialization_trait]` - `#[rustc_unsafe_specialization_marker]` - `#[marker]` - `#[fundamental]` - `#[rustc_paren_sugar]` - `#[rustc_allow_incoherent_impl]` - `#[rustc_coherence_is_core]` This also changes `#[marker]` to error on duplicates instead of warning. cc rust-lang/rust#142838, but I don't think it matters too much, since it's unstable. r? ``@oli-obk``
2025-07-09Use "Innermost" & "Outermost" terminology for `AttributeOrder`Pavel Grigorenko-42/+29
2025-07-09Port `#[rustc_coherence_is_core]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[rustc_allow_incoherent_impl]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Reorder attribute parsers in `traits.rs`Pavel Grigorenko-28/+35
2025-07-09Port `#[rustc_paren_sugar]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[fundamental]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[marker]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[rustc_unsafe_specialization_marker]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[rustc_specialization_trait]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[type_const]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[rustc_coinductive]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[rustc_do_not_implement_via_object]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[rustc_deny_explicit_impl]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-09Port `#[const_trait]` to the new attribute systemPavel Grigorenko-2/+11
2025-07-08Rollup merge of #143603 - Periodic1911:clarify_keepfistlast, r=compiler-errorsMatthias Krüger-1/+15
Clarify the meaning of `AttributeOrder::KeepFirst` and `AttributeOrder::KeepLast` Clarify the meaning of `KeepLast` and `KeepFirst` for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 Just a minor clarification, but me and ``@JonathanBrouwer`` have confused these two a few times so I think it's warranted. r? ``@oli-obk`` cc ``@JonathanBrouwer``
2025-07-08Rollup merge of #143593 - mejrs:dummy, r=jdonszelmannMatthias Krüger-0/+20
Port #[rustc_dummy] r? ``@jdonszelmann``
2025-07-07Clarify the meaning of `AttributeOrder::KeepFirst` and ↵Anne Stijns-1/+15
`AttributeOrder::KeepLast`
2025-07-07Port #[rustc_dummy]mejrs-0/+20
2025-07-07Port `#[rustc_std_internal_symbol]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-07Port `#[ffi_pure]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-07Port `#[ffi_const]` to the new attribute systemPavel Grigorenko-0/+7
2025-07-07Port `#[export_stable]` to the new attribute systemPavel Grigorenko-2/+11
2025-07-06Port `#[path]` to the new attribute parsing infrastructureJonathan Brouwer-0/+30
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-06Rewrite empty attribute lintJonathan Brouwer-3/+8
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-05Port `#[ignore]` to the new attribute parsing infrastructureJonathan Brouwer-0/+47
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-04Port `#[non_exhaustive]` to the new attribute parsing infrastructureJonathan Brouwer-0/+14
2025-07-04Rollup merge of #143400 - GrigorenkoPV:attributes/lints, r=jdonszelmannMatthias Krüger-0/+7
Port `#[rustc_pass_by_value]` to the new attribute system Part of rust-lang/rust#131229 r? `@oli-obk`