-
Notifications
You must be signed in to change notification settings - Fork 13.4k
confusing diagnostic when variable name equals function name #53841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
They are not because on the second case the local binding
No, it's just confused thinking that The error message should mention the shadowing of the function. |
Just ran into this again with a more simple case :( fn a() {}
fn main() {
let a: bool = false;
if a {
a();
}
} IMO this should compile because we know that The error message is not really helping imo
I wonder if type ascription could solve this: |
When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name. ``` error[E0618]: expected function, found `&str` --> $DIR/issue-22468.rs:3:13 | LL | let foo = "bar"; | --- `foo` has type `&str` LL | let x = foo("baz"); | ^^^------- | | | call expression requires function ... LL | fn foo(file: &str) -> bool { | -------------------------- this function of the same name is avalable here, but it shadowed by the local binding of the same name ``` Fix rust-lang#53841
When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name. ``` error[E0618]: expected function, found `&str` --> $DIR/issue-22468.rs:3:13 | LL | let foo = "bar"; | --- `foo` has type `&str` LL | let x = foo("baz"); | ^^^------- | | | call expression requires function ... LL | fn foo(file: &str) -> bool { | -------------------------- this function of the same name is avalable here, but it shadowed by the local binding of the same name ``` Fix rust-lang#53841
When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name. ``` error[E0618]: expected function, found `&str` --> $DIR/issue-22468.rs:3:13 | LL | let foo = "bar"; | --- `foo` has type `&str` LL | let x = foo("baz"); | ^^^------- | | | call expression requires function ... LL | fn foo(file: &str) -> bool { | -------------------------- this function of the same name is avalable here, but it shadowed by the local binding of the same name ``` Fix rust-lang#53841
When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name. ``` error[E0618]: expected function, found `&str` --> $DIR/issue-22468.rs:3:13 | LL | let foo = "bar"; | --- `foo` has type `&str` LL | let x = foo("baz"); | ^^^------- | | | call expression requires function ... LL | fn foo(file: &str) -> bool { | -------------------------- this function of the same name is avalable here, but it shadowed by the local binding of the same name ``` Fix rust-lang#53841
When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name. ``` error[E0618]: expected function, found `&str` --> $DIR/issue-22468.rs:3:13 | LL | let foo = "bar"; | --- `foo` has type `&str` LL | let x = foo("baz"); | ^^^------- | | | call expression requires function ... LL | fn foo(file: &str) -> bool { | -------------------------- this function of the same name is avalable here, but it shadowed by the local binding of the same name ``` Fix rust-lang#53841
When a local binding shadows a fn, point at fn def in call failure When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name. ``` error[E0618]: expected function, found `&str` --> $DIR/issue-22468.rs:3:13 | LL | let foo = "bar"; | --- `foo` has type `&str` LL | let x = foo("baz"); | ^^^------- | | | call expression requires function ... LL | fn foo(file: &str) -> bool { | -------------------------- this function of the same name is available here, but it shadowed by the local binding of the same name ``` Fix rust-lang#53841
rustc 1.30.0-nightly (02cb8f2a4 2018-08-29)
code:
This causes a very confusing error message
First, the message talks about "enum variant", does it mean
struct variant
?Second, I don't get why it does not compile anyway.
If I rename
commit_hash()
toget_commit_hash()
it builds, but why can't it figure out that that a var and function are different things even if they have the same name?Fun fact:
this doesn't build either
but this does:
Shouldn't the 2 snippets behave identical?
The text was updated successfully, but these errors were encountered: