-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
#[derive(Debug)]
enum Number {
One,
Two,
}
impl Number {
pub const Uno: Number = Number::One;
pub const Two: Number = Number::One;
}
fn main() {
eprintln!("{:?}", Number::Uno);
eprintln!("{:?}", Number::Two);
}Current output
warning: associated constant `Two` is never used
--> src/main.rs:9:15
|
7 | impl Number {
| ----------- associated constant in this implementation
8 | pub const Uno: Number = Number::One;
9 | pub const Two: Number = Number::One;
| ^^^
|
= note: `#[warn(dead_code)]` on by default
warning: associated constant `Uno` should have an upper case name
[...]
warning: associated constant `Two` should have an upper case name
[...]
One
TwoDesired output
error: associated constant `Two` conflicts with enum value `Number::Two`
--> src/main.rs:9:15
|
7 | impl Number {
| ----------- associated constant in this implementation
8 | pub const Uno: Number = Number::One;
9 | pub const Two: Number = Number::One;Rationale and extra context
Maybe this isn't a bug, and I just don't understand the purpose for this behavior. It seems to me the associated constant cannot be constructed, and the compiler should produce a specific error or at least a warning for it.
I imagine the current consensus might be that the warning:
warning: associated constant `Two` should have an upper case name
--> src/main.rs:9:15
|
9 | pub const Two: Number = Number::One;
| ^^^ help: convert the identifier to upper case (notice the capitalization): `TWO`
Would constitute an answer to the problem we see here, but it also doesn't specifically mention that the two identifiers are conflicting.
Other cases
No response
Rust Version
$ rustc --version --verbose
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.