-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.
Description
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
}
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.
jplatte
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.