Skip to content

Give a better error message for async pub fn and const pub fn #76437

Closed
@pickfire

Description

@pickfire

It may be possible that developers get mixed up where pub visibility needs to be shown.

error: expected item, found keyword `async`
 --> src/lib.rs:1:1
  |
1 | async pub fn t() {}
  | ^^^^^ expected item

error: aborting due to previous error
error: expected identifier, found keyword `pub`
 --> src/lib.rs:1:7
  |
1 | const pub fn t() {}
  |       ^^^ expected identifier, found keyword

error: expected one of `:`, `;`, or `=`, found keyword `fn`
 --> src/lib.rs:1:11
  |
1 | const pub fn t() {}
  |           ^^ expected one of `:`, `;`, or `=`

error: missing type for `const` item
 --> src/lib.rs:1:7
  |
1 | const pub fn t() {}
  |       ^^^ help: provide a type for the item: `r#pub: <type>`

error: aborting due to 3 previous errors

I am working on the first one, the second one looks harder to solve so I am not solving it.

It would be good to suggest the developer that pub needs to come before async or const. And I don't even know if async should come before const or the other way around.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-visibilityArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions