Skip to content

dead_code warning not emitted for unused associated constant #114730

Closed

Description

Code

I tried this code:

struct Foo(u16);

pub fn use_foo() {
    let _ = Foo(0);
}

impl Foo {
    pub const BAR: Self = Self(123);
}

impl PartialEq<Foo> for u16 {
    fn eq(&self, other: &Foo) -> bool {
        *self == other.0
    }
}

I expected to see this happen: I expected to see a dead_code warning for Foo::BAR.

Instead, this happened: No warning is emitted.

Version it worked on

It most recently worked on: Rust 1.70

Version with regression

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5

Backtrace

N/A

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions