Skip to content

Fix #[expect(dead_code)] liveness propagation#154377

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
mu001999-contrib:fix/dead-code
Apr 21, 2026
Merged

Fix #[expect(dead_code)] liveness propagation#154377
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
mu001999-contrib:fix/dead-code

Conversation

@mu001999
Copy link
Copy Markdown
Member

Fixes #154324
Fixes #152370 (cc @eggyal)

Previously, when traversing from a ComesFromAllowExpect::Yes item (i.e., with #[allow(dead_code)] or #[expect(dead_code)]), other ComesFromAllowExpect::Yes items reached during propagation would be updated to ComesFromAllowExpect::No and inserted into live_symbols. That caused dead_code lint couldn't be emitted correctly.

After this PR, ComesFromAllowExpect::Yes items no longer incorrectly update other ComesFromAllowExpect::Yes items during propagation or mark them live by mistake, then dead_code lint could behave as expected.

@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 Mar 25, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 25, 2026

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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 69 candidates
  • Random selection from 12 candidates

@mu001999
Copy link
Copy Markdown
Member Author

@rustbot author

I realized that this would fail during secondary propagation. This still needs to be revised a bit.

@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 Mar 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 26, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@mu001999
Copy link
Copy Markdown
Member Author

mu001999 commented Apr 7, 2026

oops, forgot to update the label

@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 Apr 7, 2026
Comment thread compiler/rustc_passes/src/dead.rs
@joshtriplett
Copy link
Copy Markdown
Member

See #152370 (comment) .

@joshtriplett
Copy link
Copy Markdown
Member

Test cases look good here.

@mu001999

This comment was marked as outdated.

@rustbot

This comment was marked as outdated.

@mu001999
Copy link
Copy Markdown
Member Author

@rustbot reroll

@rustbot rustbot assigned eholk and unassigned TaKO8Ki Apr 21, 2026
Copy link
Copy Markdown
Member

@TaKO8Ki TaKO8Ki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I overlooked this pr.

View changes since this review

@TaKO8Ki
Copy link
Copy Markdown
Member

TaKO8Ki commented Apr 21, 2026

r? TaKO8Ki @bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 21, 2026

📌 Commit faa7966 has been approved by TaKO8Ki

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 Apr 21, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 21, 2026
…TaKO8Ki

Fix `#[expect(dead_code)]` liveness propagation

Fixes rust-lang#154324
Fixes rust-lang#152370 (cc @eggyal)

Previously, when traversing from a `ComesFromAllowExpect::Yes` item (i.e., with `#[allow(dead_code)]` or `#[expect(dead_code)]`), other `ComesFromAllowExpect::Yes` items reached during propagation would be updated to `ComesFromAllowExpect::No` and inserted into `live_symbols`. That caused `dead_code` lint couldn't be emitted correctly.

After this PR, `ComesFromAllowExpect::Yes` items no longer incorrectly update other `ComesFromAllowExpect::Yes` items during propagation or mark them live by mistake, then `dead_code` lint could behave as expected.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 21, 2026
…TaKO8Ki

Fix `#[expect(dead_code)]` liveness propagation

Fixes rust-lang#154324
Fixes rust-lang#152370 (cc @eggyal)

Previously, when traversing from a `ComesFromAllowExpect::Yes` item (i.e., with `#[allow(dead_code)]` or `#[expect(dead_code)]`), other `ComesFromAllowExpect::Yes` items reached during propagation would be updated to `ComesFromAllowExpect::No` and inserted into `live_symbols`. That caused `dead_code` lint couldn't be emitted correctly.

After this PR, `ComesFromAllowExpect::Yes` items no longer incorrectly update other `ComesFromAllowExpect::Yes` items during propagation or mark them live by mistake, then `dead_code` lint could behave as expected.
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 21, 2026
…TaKO8Ki

Fix `#[expect(dead_code)]` liveness propagation

Fixes rust-lang#154324
Fixes rust-lang#152370 (cc @eggyal)

Previously, when traversing from a `ComesFromAllowExpect::Yes` item (i.e., with `#[allow(dead_code)]` or `#[expect(dead_code)]`), other `ComesFromAllowExpect::Yes` items reached during propagation would be updated to `ComesFromAllowExpect::No` and inserted into `live_symbols`. That caused `dead_code` lint couldn't be emitted correctly.

After this PR, `ComesFromAllowExpect::Yes` items no longer incorrectly update other `ComesFromAllowExpect::Yes` items during propagation or mark them live by mistake, then `dead_code` lint could behave as expected.
rust-bors Bot pushed a commit that referenced this pull request Apr 21, 2026
Rollup of 6 pull requests

Successful merges:

 - #155028 (tests: add whitespace tests for vertical tab behavior)
 - #155582 (Rewrite `FlatMapInPlace`.)
 - #151194 (Fix wrong suggestion for returning async closure)
 - #154377 (Fix `#[expect(dead_code)]` liveness propagation)
 - #155572 (Move diagnostic attribute target checks from check_attr)
 - #155586 (Ensure we don't feed owners from ast lowering if we ever make that query tracked)
@rust-bors rust-bors Bot merged commit 3b4c179 into rust-lang:main Apr 21, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 21, 2026
rust-timer added a commit that referenced this pull request Apr 21, 2026
Rollup merge of #154377 - mu001999-contrib:fix/dead-code, r=TaKO8Ki

Fix `#[expect(dead_code)]` liveness propagation

Fixes #154324
Fixes #152370 (cc @eggyal)

Previously, when traversing from a `ComesFromAllowExpect::Yes` item (i.e., with `#[allow(dead_code)]` or `#[expect(dead_code)]`), other `ComesFromAllowExpect::Yes` items reached during propagation would be updated to `ComesFromAllowExpect::No` and inserted into `live_symbols`. That caused `dead_code` lint couldn't be emitted correctly.

After this PR, `ComesFromAllowExpect::Yes` items no longer incorrectly update other `ComesFromAllowExpect::Yes` items during propagation or mark them live by mistake, then `dead_code` lint could behave as expected.
@mu001999 mu001999 deleted the fix/dead-code branch April 22, 2026 14:47
@Mark-Simulacrum
Copy link
Copy Markdown
Member

@rust-timer build 40d0e95

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (40d0e95): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.0% [0.3%, 2.1%] 14
Regressions ❌
(secondary)
0.7% [0.6%, 0.7%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 3
All ❌✅ (primary) 1.0% [0.3%, 2.1%] 14

Max RSS (memory usage)

Results (primary 0.1%, secondary 3.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
-2.0% [-2.0%, -2.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-2.0%, 2.3%] 2

Cycles

Results (primary 2.8%, secondary 5.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.8% [2.8%, 2.8%] 1
Regressions ❌
(secondary)
5.6% [5.6%, 5.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.8% [2.8%, 2.8%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 492.256s -> 491.986s (-0.05%)
Artifact size: 394.33 MiB -> 394.36 MiB (0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Apr 27, 2026
@Mark-Simulacrum
Copy link
Copy Markdown
Member

Looks like this caused some regressions, including outside incremental scenarios. I think since it's a correctness fix it's probably acceptable, marking as triaged. I suspect most of the regressions are predominantly just in instruction count based on the changes -- since we're moving slightly larger structs around that'll take a few extra instructions -- but that shouldn't take meaningfully more wall time, which aligns with minimal cycle count changes.

@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

Projects

None yet

8 participants