Skip to content

Refactor the two-phase check for impls and impl items #141407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ rustc_queries! {
/// their respective impl (i.e., part of the derive macro)
query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
LocalDefIdSet,
LocalDefIdMap<Vec<(DefId, DefId)>>
LocalDefIdMap<FxIndexSet<(DefId, DefId)>>
) {
arena_cache
desc { "finding live symbols in crate" }
Expand Down
250 changes: 120 additions & 130 deletions compiler/rustc_passes/src/dead.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,19 @@ impl Default for CommandOutput {

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

#[cfg(feature = "tracing")]
impl FormatShortCmd for BootstrapCommand {
fn format_short_cmd(&self) -> String {
self.command.format_short_cmd()
}
}

#[cfg(feature = "tracing")]
impl FormatShortCmd for Command {
fn format_short_cmd(&self) -> String {
let program = Path::new(self.get_program());
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/derives/clone-debug-dead-code.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LL | struct D { f: () }
| |
| field in this struct
|
= note: `D` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
= note: `D` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis

error: field `f` is never read
--> $DIR/clone-debug-dead-code.rs:21:12
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/deriving/deriving-in-macro.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
//@ check-pass
#![allow(non_camel_case_types)]
#![allow(dead_code)]

macro_rules! define_vec {
() => (
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/lint/dead-code/alias-type-used-as-generic-arg-in-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ check-pass

#![deny(dead_code)]

struct T<X>(X);

type A<X> = T<X>;

trait Tr {
fn foo();
}

impl<X> Tr for T<A<X>> {
fn foo() {}
}

fn main() {
T::<T<()>>::foo();
}
2 changes: 2 additions & 0 deletions tests/ui/lint/dead-code/issue-41883.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ error: struct `UnusedStruct` is never constructed
|
LL | struct UnusedStruct;
| ^^^^^^^^^^^^
|
= note: `UnusedStruct` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

error: aborting due to 4 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ warning: struct `Foo` is never constructed
|
LL | struct Foo(usize, #[allow(unused)] usize);
| ^^^
|
= note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

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

31 changes: 31 additions & 0 deletions tests/ui/lint/dead-code/trait-only-used-as-type-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//@ check-pass

#![deny(dead_code)]

trait UInt: Copy + From<u8> {}

impl UInt for u16 {}

trait Int: Copy {
type Unsigned: UInt;

fn as_unsigned(self) -> Self::Unsigned;
}

impl Int for i16 {
type Unsigned = u16;

fn as_unsigned(self) -> u16 {
self as _
}
}

fn priv_func<T: Int>(x: u8, y: T) -> (T::Unsigned, T::Unsigned) {
(T::Unsigned::from(x), y.as_unsigned())
}

pub fn pub_func(x: u8, y: i16) -> (u16, u16) {
priv_func(x, y)
}

fn main() {}
Loading