Skip to content

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

@WaffleLapkin

Description

@WaffleLapkin

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

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

No branches or pull requests

Issue actions