Skip to content

Commit e460fa9

Browse files
committed
Auto merge of #141407 - mu001999-contrib:dead-code/refactor, r=<try>
Refactor the two-phase check for impls and impl items Refactor the two-phase dead code check to make the logic clearer and simpler: 1. adding assoc fn and impl into `unsolved_items` directly during the initial construction of the worklist 2. converge the logic of checking whether assoc fn and impl are used to `item_should_be_checked`, and the item is considered used only when its corresponding trait and Self adt are used This PR only refactors as much as possible to avoid affecting the original functions. However, due to the adjustment of the order of checks, the test results are slightly different, but overall, there is no regression problem Extracted from #128637. r? petrochenkov try-job: dist-aarch64-linux
2 parents 77101fe + 419897c commit e460fa9

File tree

7 files changed

+131
-133
lines changed

7 files changed

+131
-133
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ rustc_queries! {
11371137
/// their respective impl (i.e., part of the derive macro)
11381138
query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
11391139
LocalDefIdSet,
1140-
LocalDefIdMap<Vec<(DefId, DefId)>>
1140+
LocalDefIdMap<FxIndexSet<(DefId, DefId)>>
11411141
) {
11421142
arena_cache
11431143
desc { "finding live symbols in crate" }

compiler/rustc_passes/src/dead.rs

Lines changed: 120 additions & 130 deletions
Large diffs are not rendered by default.

src/bootstrap/src/utils/exec.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,19 @@ impl Default for CommandOutput {
332332

333333
/// Helper trait to format both Command and BootstrapCommand as a short execution line,
334334
/// without all the other details (e.g. environment variables).
335+
#[cfg(feature = "tracing")]
335336
pub trait FormatShortCmd {
336337
fn format_short_cmd(&self) -> String;
337338
}
338339

340+
#[cfg(feature = "tracing")]
339341
impl FormatShortCmd for BootstrapCommand {
340342
fn format_short_cmd(&self) -> String {
341343
self.command.format_short_cmd()
342344
}
343345
}
344346

347+
#[cfg(feature = "tracing")]
345348
impl FormatShortCmd for Command {
346349
fn format_short_cmd(&self) -> String {
347350
let program = Path::new(self.get_program());

tests/ui/derives/clone-debug-dead-code.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LL | struct D { f: () }
4040
| |
4141
| field in this struct
4242
|
43-
= note: `D` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
43+
= note: `D` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis
4444

4545
error: field `f` is never read
4646
--> $DIR/clone-debug-dead-code.rs:21:12

tests/ui/deriving/deriving-in-macro.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//@ run-pass
1+
//@ check-pass
22
#![allow(non_camel_case_types)]
3+
#![allow(dead_code)]
34

45
macro_rules! define_vec {
56
() => (

tests/ui/lint/dead-code/issue-41883.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ error: struct `UnusedStruct` is never constructed
2929
|
3030
LL | struct UnusedStruct;
3131
| ^^^^^^^^^^^^
32+
|
33+
= note: `UnusedStruct` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
3234

3335
error: aborting due to 4 previous errors
3436

tests/ui/lint/dead-code/multiple-dead-codes-in-the-same-struct.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ warning: struct `Foo` is never constructed
5656
|
5757
LL | struct Foo(usize, #[allow(unused)] usize);
5858
| ^^^
59+
|
60+
= note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
5961

6062
error: aborting due to 2 previous errors; 2 warnings emitted
6163

0 commit comments

Comments
 (0)