No warning for an associated constant always hidden by an enum variant (original) (raw)

To my great surprise, this compiles fine, with no warnings:

pub enum Foo { A(i32), } impl Foo { pub const A: Self = Foo::A(0); }

Trying to actually use that constant, however, doesn't work:

pub fn demo() -> Foo { Foo::A }

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d1e7c140a60c78cc6ede62b677a74e5e

error[E0308]: mismatched types --> src/lib.rs:9:5 | 2 | A(i32), | ------ fn(i32) -> Foo {Foo::A} defined here ... 8 | pub fn demo() -> Foo { | --- expected Foo because of return type 9 | Foo::A | ^^^^^^ expected enum Foo, found fn item | = note: expected enum Foo found fn item fn(i32) -> Foo {Foo::A} help: use parentheses to instantiate this tuple variant | 9 | Foo::A(_) | ^^^

If that constant is going to compile, it should probably at least be linted against.