Skip to content

Terse diagnostic for an associated function shadowed by a variant #142263

Closed
@WaffleLapkin

Description

@WaffleLapkin
Member

Code

enum E {
   V(),
}

impl E {
    #[expect(non_snake_case)]
    fn V() {}
}

fn main() {
    let _: E = E::V();
}

Current output

warning: associated function `V` is never used
 --> src/main.rs:7:8
  |
5 | impl E {
  | ------ associated function in this implementation
6 |     #[expect(non_snake_case)]
7 |     fn V() {}
  |        ^
  |
  = note: `#[warn(dead_code)]` on by default

Desired output

warning: associated function `V` is never used
 --> src/main.rs:7:8
  |
5 | impl E {
  | ------ associated function in this implementation
6 |     #[expect(non_snake_case)]
7 |     fn V() {}
  |        ^
  |
  = note: `#[warn(dead_code)]` on by default
  = note: this function is shadowed by the `E::V` variant and can't be called

Rationale and extra context

Tuple variants always shadow methods. If a method has the same name as a variant it is uncallable.

Rust Version

1.87.0

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
on Jun 9, 2025
added 2 commits that reference this issue on Jun 12, 2025

Rollup merge of rust-lang#142406 - jdonszelmann:dead-code-enum-varian…

f01af65

Rollup merge of rust-lang#142406 - jdonszelmann:dead-code-enum-varian…

7cd6944
added a commit that references this issue on Jun 13, 2025
7e50ae8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @jdonszelmann@WaffleLapkin

    Issue actions

      Terse diagnostic for an associated function shadowed by a variant · Issue #142263 · rust-lang/rust