Skip to content

Commit 1d94b88

Browse files
authored
Unrolled build for #141407
Rollup merge of #141407 - mu001999-contrib:dead-code/refactor, r=petrochenkov 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 Fixes #127911 Fixes #128839 Extracted from #128637. r? petrochenkov try-job: dist-aarch64-linux
2 parents 1c0849d + 6eb6010 commit 1d94b88

File tree

9 files changed

+181
-133
lines changed

9 files changed

+181
-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
() => (
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ check-pass
2+
3+
#![deny(dead_code)]
4+
5+
struct T<X>(X);
6+
7+
type A<X> = T<X>;
8+
9+
trait Tr {
10+
fn foo();
11+
}
12+
13+
impl<X> Tr for T<A<X>> {
14+
fn foo() {}
15+
}
16+
17+
fn main() {
18+
T::<T<()>>::foo();
19+
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ check-pass
2+
3+
#![deny(dead_code)]
4+
5+
trait UInt: Copy + From<u8> {}
6+
7+
impl UInt for u16 {}
8+
9+
trait Int: Copy {
10+
type Unsigned: UInt;
11+
12+
fn as_unsigned(self) -> Self::Unsigned;
13+
}
14+
15+
impl Int for i16 {
16+
type Unsigned = u16;
17+
18+
fn as_unsigned(self) -> u16 {
19+
self as _
20+
}
21+
}
22+
23+
fn priv_func<T: Int>(x: u8, y: T) -> (T::Unsigned, T::Unsigned) {
24+
(T::Unsigned::from(x), y.as_unsigned())
25+
}
26+
27+
pub fn pub_func(x: u8, y: i16) -> (u16, u16) {
28+
priv_func(x, y)
29+
}
30+
31+
fn main() {}

0 commit comments

Comments
 (0)