Skip to content

Refactor the #[allow(dead_code)] propagation for impl items of traits - #161571

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
mu001999-contrib:dead-code-refactor
Aug 28, 2026
Merged

Refactor the #[allow(dead_code)] propagation for impl items of traits#161571
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
mu001999-contrib:dead-code-refactor

Conversation

@mu001999

@mu001999 mu001999 commented Aug 23, 2026

Copy link
Copy Markdown
Member

View all comments

Extracted from #157885.

This PR does the refactor and corrects the previous implementation.

The following will fail currently (play):

#![deny(dead_code)]
#![deny(unfulfilled_lint_expectations)]

#[allow(dead_code)]
pub trait Tr {
    fn foo(&self);
}

struct Foo;

impl Tr for Foo {
    fn foo(&self) {
        bar();
    }
}

#[expect(dead_code)]
fn bar() {}

fn main() {}

After this PR, we could handle the #[allow(dead_code)] propagation correctly, and should get perf improvement.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 23, 2026
@mu001999

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 23, 2026
Refactor the `#[allow(dead_code)]` propagation for impl items of traits
@rust-bors

rust-bors Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ef781c8 (ef781c8005ba42aaa03739a3effec6ddb8e82cbe)
Base parent: 2f54787 (2f54787b636028a19294176d0fb27794452e6608)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ef781c8): comparison URL.

Overall result: ✅ improvements - no action needed

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.

@bors rollup=never rustc-perf
@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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-1.3%, -0.2%] 35
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 9
All ❌✅ (primary) -0.5% [-1.3%, -0.2%] 35

Max RSS (memory usage)

Results (secondary 5.9%)

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

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

Cycles

Results (secondary 3.9%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.7% [2.7%, 7.2%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-3.5%, -3.5%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 470.877s -> 469.545s (-0.28%)
Artifact size: 400.19 MiB -> 400.97 MiB (0.19%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 23, 2026
@mu001999
mu001999 marked this pull request as ready for review August 23, 2026 06:51
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 23, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 23, 2026
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
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 75 candidates
  • Random selection from 18 candidates

@mu001999

Copy link
Copy Markdown
Member Author

@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 Aug 24, 2026
@mu001999
mu001999 force-pushed the dead-code-refactor branch from 477692e to d32f000 Compare August 24, 2026 05:31
@mu001999

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 24, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 24, 2026
Refactor the `#[allow(dead_code)]` propagation for impl items of traits
@rust-bors

rust-bors Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: e466d2a (e466d2ab296542be4a4e93a797980f81378d18a4)
Base parent: da51146 (da5114692c9ebe46b869488c5f34f92eb10b98c1)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e466d2a): 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 rustc-perf
@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)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 2
Improvements ✅
(primary)
-0.5% [-1.3%, -0.1%] 37
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 10
All ❌✅ (primary) -0.5% [-1.3%, -0.1%] 37

Max RSS (memory usage)

Results (secondary 7.7%)

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

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

Cycles

Results (primary -3.1%, secondary -3.7%)

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

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

Binary size

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

Bootstrap: 469.244s -> 471.227s (0.42%)
Artifact size: 400.19 MiB -> 400.33 MiB (0.03%)

@rustbot rustbot added the perf-regression Performance regression. label Aug 24, 2026
@mu001999
mu001999 force-pushed the dead-code-refactor branch from 59b316b to f9067f4 Compare August 28, 2026 00:33
@mu001999
mu001999 force-pushed the dead-code-refactor branch from f9067f4 to 93d03be Compare August 28, 2026 00:33
@rustbot

rustbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@chenyukang

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 93d03be has been approved by chenyukang

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 Aug 28, 2026
@mu001999

Copy link
Copy Markdown
Member Author

This PR has perf implication, so @bors rollup=never

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
…kang

Refactor the `#[allow(dead_code)]` propagation for impl items of traits



Extracted from #157885.

This PR does the refactor and corrects the previous implementation.

The following will fail currently ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=3279902b2d2e6b0fe75c5af565b1cddd)):
```rust
#![deny(dead_code)]
#![deny(unfulfilled_lint_expectations)]

#[allow(dead_code)]
pub trait Tr {
    fn foo(&self);
}

struct Foo;

impl Tr for Foo {
    fn foo(&self) {
        bar();
    }
}

#[expect(dead_code)]
fn bar() {}

fn main() {}
```

After this PR, we could handle the `#[allow(dead_code)]` propagation correctly, and should get perf improvement.
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-mingw-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 28, 2026
@rust-bors

rust-bors Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 62090b5 failed: CI. Failed job:

@mu001999

Copy link
Copy Markdown
Member Author
failures:

---- library\std\src\os\windows\process.rs - os::windows::process::CommandExt::spawn_with_attributes (line 317) stdout ----
Test executable failed (exit code: 101).

stdout:
Microsoft Windows [Version 10.0.26100.33296]
(c) Microsoft Corporation. All rights reserved.

D:\a\rust\rust\library\std>
stderr:

thread 'main' (3256) panicked at library\std\src\os\windows\process.rs:31:63:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- library\std\src\os\windows\process.rs - os::windows::process::CommandExt::spawn_with_attributes (line 317) stdout end ----

failures:
    library\std\src\os\windows\process.rs - os::windows::process::CommandExt::spawn_with_attributes (line 317)

test result: FAILED. 1261 passed; 1 failed; 177 ignored; 0 measured; 0 filtered out; finished in 144.40s

all doctests ran in 147.84s; merged doctests compilation took 3.05s
error: doctest failed, to rerun pass `-p std --doc`
Bootstrap failed while executing `test --stage 2 --skip=compiler --skip=src`
Currently active steps:
test::Crate { build_compiler: Compiler { stage: 2, host: x86_64-pc-windows-gnu, forced_compiler: false }, target: x86_64-pc-windows-gnu, mode: Std, crates: ["alloc", "alloctests", "compiler_builtins", "core", "coretests", "panic_abort", "panic_unwind", "proc_macro", "rustc-std-workspace-core", "std", "std_detect", "sysroot", "test", "unwind"] } at src\bootstrap\src\core\build_steps\test.rs:3523
Build completed unsuccessfully in 2:20:01
make: *** [Makefile:126: ci-mingw-x] Error 1
  local time: Fri Aug 28 07:56:07 CUT 2026
  network time: Fri, 28 Aug 2026 07:56:08 GMT
##[error]Process completed with exit code 2.

Seems suspicious

@bors retry

@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 Aug 28, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 28, 2026
@rust-bors

rust-bors Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: chenyukang
Duration: 3h 19m 45s
Pushing c42ac5f to main...

@rust-bors
rust-bors Bot merged commit c42ac5f into rust-lang:main Aug 28, 2026
14 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Aug 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing d0f2ef5 (parent) -> c42ac5f (this PR)

Test differences

Show 5 test diffs

Stage 1

  • [ui (polonius)] tests/ui/lint/dead-code/allow-dead-code-propagation-to-impls.rs: [missing] -> pass (J0)
  • [ui] tests/ui/lint/dead-code/allow-dead-code-propagation-to-impls.rs: [missing] -> pass (J1)

Stage 2

  • [ui] tests/ui/lint/dead-code/allow-dead-code-propagation-to-impls.rs: [missing] -> pass (J2)

Additionally, 2 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard c42ac5fd59628ea7e2f52af5944c2aaac3f0e7f6 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. i686-gnu-nopt-2: 1h 27m -> 2h 12m (+50.1%)
  2. i686-msvc-2: 1h 28m -> 2h 8m (+45.2%)
  3. x86_64-gnu-gcc-core-tests: 17m 41s -> 10m (-43.4%)
  4. dist-x86_64-netbsd: 1h 4m -> 1h 31m (+41.8%)
  5. x86_64-gnu-stdlib-semver-check: 18m 5s -> 11m 20s (-37.3%)
  6. x86_64-rust-for-linux: 59m 7s -> 37m 19s (-36.9%)
  7. dist-x86_64-llvm-mingw: 2h 7m -> 1h 25m (-32.9%)
  8. x86_64-gnu-llvm-21-3: 1h 11m -> 1h 34m (+32.8%)
  9. x86_64-mingw-1: 2h 16m -> 3h (+31.8%)
  10. i686-gnu-nopt-1: 2h 23m -> 1h 38m (-31.3%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (c42ac5f): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-1.3%, -0.1%] 32
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 8
All ❌✅ (primary) -0.5% [-1.3%, -0.1%] 32

Max RSS (memory usage)

Results (primary -2.0%)

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

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

Cycles

Results (primary -2.4%, secondary 3.3%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
-2.4% [-2.7%, -2.2%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.4% [-2.7%, -2.2%] 3

Binary size

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

Bootstrap: 475.629s -> 474.678s (-0.20%)
Artifact size: 402.76 MiB -> 402.79 MiB (0.01%)

@rustbot rustbot removed the perf-regression Performance regression. label Aug 28, 2026
@mu001999
mu001999 deleted the dead-code-refactor branch August 28, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. 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.

5 participants