Open
Description
Description
It's currently possible to name a function associated to an enum identically to the name of one of its variants.
This function cannot be called (see below), but rather than warning at the point that the function is defined, the compiler only emits an error upon trying to call said function (and in some cases - see the 'Alternate Reproduction' - it doesn't even do that).
#[derive(Debug)]
enum X {
a
}
impl X {
fn a() -> X {
X::a
}
}
fn main() {
println!("{:?}", X::a())
}
yields:
rustc 1.15.1 (021bd294c 2017-02-08)
error: `X::a` is being called, but it is not a function
--> <anon>:13:22
|
13 | println!("{:?}", X::a())
| ^^^^^^
|
= help: did you mean to write `X::a`?
note: defined here
--> <anon>:3:5
|
3 | a
| ^
error: aborting due to previous error
Expected behaviour:
Emit an error at the point (fn a() -> X
) that the function is defined.
Alternate reproduction
Even more confusing is the code:
#[derive(Debug)]
enum X {
a(),
b,
}
impl X {
fn a() -> X {
X::b
}
}
fn main() {
println!("{:?}", X::a())
}
This compiles and runs.
Any guesses whether the variant or the function wins? 😄