Closed
Description
User Story
As a rust newbie, I don't know which one is recommended.
-
or
impl FooEnum
-
or
impl FooEnumWrapperStruct
So, I check doc
https://doc.rust-lang.org/stable/rust-by-example/custom_types/enum/testcase_linked_list.html
Found
- official doc example use
impl FooEnum
, notimpl FooEnumWrapperStruct
Curiously, I tried this code:
enum Foo {
A,
B,
C,
}
impl Foo {
pub const A: u8 = 42;
pub const Z: u8 = 42;
}
fn main() {
assert_eq!(Foo::A as u8, 0);
assert_eq!(Foo::B as u8, 1);
assert_eq!(Foo::C as u8, 2);
assert_eq!(Foo::Z as u8, 42);
}
I expected to see this happen:
-
or same name is treated invalid: compile failure,
pub const A
conflicts withFoo:A
-
or same name is treated valid: there should be
core::get_enum_impl_pub_const(Foo, "A")
equals to 42
Instead, this happened:
warning: associated constant `A` is never used
--> path/to/reproduce.rs:8:15
|
7 | impl Foo {
| -------- associated constant in this implementation
8 | pub const A: u8 = 42;
| ^
|
= note: `#[warn(dead_code)]` on by default
Meta
rustc --version --verbose
:
1.73.0
Backtrace
<backtrace>