Skip to content

Also duplicate #[expect] attribute in #[derive]-ed code#152289

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Urgau:expect-in-derive-150553
Feb 7, 2026
Merged

Also duplicate #[expect] attribute in #[derive]-ed code#152289
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Urgau:expect-in-derive-150553

Conversation

@Urgau
Copy link
Member

@Urgau Urgau commented Feb 7, 2026

This PR updates our derive logic to also duplicate any #[expect] attribute in the #[derive]-ed code, as we already do for all the other lint attribute (#[allow], #[warn], #[deny], ...).

The original and duplicated attribute share the same attribute id, which due to the way check_expectations is implemented makes the expectation fulfilled if the lint is either trigger in the original code or the derived code.

This was discussed by T-lang in #150553 (comment).

cc @rust-lang/lang-ops (in case you want to do an FCP)
Fixes #150553

@rustbot rustbot added 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 Feb 7, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 21 candidates
  • Random selection from 12 candidates

@jdonszelmann
Copy link
Contributor

@bors r+ rollup
cc @Bryntet you might care about this one

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 7, 2026

📌 Commit 2407f47 has been approved by jdonszelmann

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 7, 2026
@Bryntet
Copy link
Contributor

Bryntet commented Feb 7, 2026

Cool! Thanks for the cc :)

rust-bors bot pushed a commit that referenced this pull request Feb 7, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #149960 (add `unreachable_cfg_select_predicates` lint)
 - #152168 (Port `rustc_intrinsic_const_stable_indirect` and `rustc_intrinsic` to the new attribute parser)
 - #152289 (Also duplicate `#[expect]` attribute in `#[derive]`-ed code)
@rust-bors rust-bors bot merged commit fced230 into rust-lang:main Feb 7, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Feb 7, 2026
Rollup merge of #152289 - Urgau:expect-in-derive-150553, r=jdonszelmann

Also duplicate `#[expect]` attribute in `#[derive]`-ed code

This PR updates our derive logic to also duplicate any `#[expect]` attribute in the `#[derive]`-ed code, as we already do for all the other lint attribute (`#[allow]`, `#[warn]`, `#[deny]`, ...).

The original and duplicated attribute share the same attribute id, which due to the way [`check_expectations`](https://github.com/rust-lang/rust/blob/56aaf58ec02b6ac974e8364269fbb33a8a806e28/compiler/rustc_lint/src/expect.rs#L28-L46) is implemented makes the expectation fulfilled if the lint is either trigger in the original code or the derived code.

This was discussed by T-lang in #150553 (comment).

cc @rust-lang/lang-ops (in case you want to do an FCP)
Fixes #150553
@rustbot rustbot added this to the 1.95.0 milestone Feb 7, 2026
@traviscross traviscross added T-lang Relevant to the language team I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels Feb 7, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 26, 2026
 Revert "Also duplicate `#[expect]` attribute in `#[derive]`-ed code"

Turns out rust-lang#152289 doesn't work, not because cloning an attribute doesn't keep the same attribute id, but because `#[cfg]` and `#[cfg_attr]` [re-parse items from scratch](https://github.com/rust-lang/rust/blob/859951e3c7c9d0322c39bad49221937455bdffcd/compiler/rustc_builtin_macros/src/cfg_eval.rs#L100-L109) bypassing any cloning on AST and forcing the creation of new attribute IDs. 😕

Fixes rust-lang#153036
Fixes rust-lang#152401
Reopens rust-lang#150553
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 26, 2026
 Revert "Also duplicate `#[expect]` attribute in `#[derive]`-ed code"

Turns out rust-lang#152289 doesn't work, not because cloning an attribute doesn't keep the same attribute id, but because `#[cfg]` and `#[cfg_attr]` [re-parse items from scratch](https://github.com/rust-lang/rust/blob/859951e3c7c9d0322c39bad49221937455bdffcd/compiler/rustc_builtin_macros/src/cfg_eval.rs#L100-L109) bypassing any cloning on AST and forcing the creation of new attribute IDs. 😕

Fixes rust-lang#153036
Fixes rust-lang#152401
Reopens rust-lang#150553
rust-timer added a commit that referenced this pull request Feb 26, 2026
Rollup merge of #153055 - Urgau:revert-152289, r=jdonszelmann

 Revert "Also duplicate `#[expect]` attribute in `#[derive]`-ed code"

Turns out #152289 doesn't work, not because cloning an attribute doesn't keep the same attribute id, but because `#[cfg]` and `#[cfg_attr]` [re-parse items from scratch](https://github.com/rust-lang/rust/blob/859951e3c7c9d0322c39bad49221937455bdffcd/compiler/rustc_builtin_macros/src/cfg_eval.rs#L100-L109) bypassing any cloning on AST and forcing the creation of new attribute IDs. 😕

Fixes #153036
Fixes #152401
Reopens #150553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[expect(redundant_lifetimes)] doesn't work when #[derive(Debug)] is present

5 participants