Skip to content

Check assoc consts and tys later like assoc fns #143519

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mu001999
Copy link
Contributor

@mu001999 mu001999 commented Jul 6, 2025

This PR

  1. checks assoc consts and tys later like assoc fns
  2. marks assoc consts appear in poly-trait-ref live

For assoc consts, considering

#![deny(dead_code)]

trait Tr { // ERROR trait `Tr` is never used
    const I: Self;
}

struct Foo; //~ ERROR struct `Foo` is never constructed

impl Tr for Foo {
    const I: Self = Foo;
}

fn main() {}

Current this will produce unused I instead of unused Tr and Foo (play), because const I: Self = Foo; will be added into the worklist at first:

error: associated constant `I` is never used
 --> src/main.rs:4:11
  |
3 | trait Tr { // ERROR trait `Tr` is never used
  |       -- associated constant in this trait
4 |     const I: Self;
  |           ^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(dead_code)]
  |         ^^^^^^^^^

error: could not compile `playground` (bin "playground") due to 1 previous error

This also happens to assoc tys, see the new test

Fixes #126729

r? @petrochenkov

@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 Jul 6, 2025
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the dead-code/impl-items branch from 2c73999 to c90150b Compare July 6, 2025 09:06
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the dead-code/impl-items branch from c90150b to 4cf632b Compare July 6, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Associated constants used in equality constraints should be considered as used
4 participants