Skip to content
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

Incorrect error message when attempting to access field on struct constructor #27990

Closed
frewsxcv opened this issue Aug 25, 2015 · 3 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@frewsxcv
Copy link
Member

playpen

struct MyStruct { field: u8 }

fn main() {
    MyStruct.foo;
}

results in

<anon>:4:5: 4:13 error: `MyStruct` is the name of a struct or struct variant, but this expression uses it like a function name [E0423]
<anon>:4     MyStruct.foo;
             ^~~~~~~~
<anon>:4:5: 4:13 help: see the detailed explanation for E0423
<anon>:4:5: 4:13 help: did you mean to write: `MyStruct { /* fields */ }`?
error: aborting due to previous error

in particular

but this expression uses it like a function name

which doesn't make sense in this context. the same error message appears if one attempts MyStruct(), which makes more sense.

@sfackler sfackler added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 25, 2015
@steveklabnik
Copy link
Member

Triage: new error format, but the underlying issue is still there:

error[E0423]: `MyStruct` is the name of a struct or struct variant, but this expression uses it like a function name
 --> <anon>:4:5
  |
4 |     MyStruct.foo;
  |     ^^^^^^^^ struct called like a function
  |
  = help: did you mean to write: `MyStruct { /* fields */ }`?

@petrochenkov
Copy link
Contributor

Error on non-ancient version of rustc:

rustc 1.17.0-nightly (be760566c 2017-02-28)
error[E0423]: expected value, found struct `MyStruct`
 --> <anon>:4:5
  |
4 |     MyStruct.foo;
  |     ^^^^^^^^ did you mean `MyStruct { /* fields */ }`?

error: aborting due to previous error

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 1, 2017

For MyStruct():

rustc 1.17.0-nightly (be760566c 2017-02-28)
error[E0423]: expected function, found struct `MyStruct`
 --> <anon>:4:5
  |
4 |     MyStruct();
  |     ^^^^^^^^ did you mean `MyStruct { /* fields */ }`?

error: aborting due to previous error

Seems fixed (also tested in #38154).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

4 participants