Skip to content

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

Description

@frewsxcv

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions