For example, I have an Enum:
enum Foo {
Bar,
Baz(i32)
}
And I write like this by mistake (forgot to add the parameter):let mode = Foo::Baz;
. Surprised that the compiler didn't consider this as an error, it will compile, I want to know if mode
's type is Foo
anymore, I write like this:
match mode {
Foo::Bar => {}
Foo::Baz(_) => {}
}
But the compiler give me some error message that confused me a lot:
error[E0308]: mismatched types
--> src/main.rs:9:9
|
2 | Bar,
| --- unit variant defined here
...
8 | match mode {
| ---- this expression has type `fn(i32) -> Foo {Foo::Baz}`
9 | Foo::Bar => {}
| ^^^^^^^^ expected fn item, found enum `Foo`
|
= note: expected fn item `fn(i32) -> Foo {Foo::Baz}`
found enum `Foo`
So what is a Foo::Baz
?