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

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

Closed
pickfire opened this issue Sep 7, 2020 · 4 comments
Closed

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

pickfire opened this issue Sep 7, 2020 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST A-visibility Area: Visibility / privacy C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pickfire
Copy link
Contributor

pickfire commented Sep 7, 2020

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.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST A-visibility Area: Visibility / privacy C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 7, 2020
@jyn514 jyn514 changed the title pub visibility position mixed up with async and const Give a better error message for async pub fn and const pub fn Sep 14, 2020
@jyn514 jyn514 added D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 14, 2020
@troublescooter
Copy link

Another place where the messages are confusing:

///
async pub fn foo() {}
error: expected item after doc comment
 --> /home/playground/src/main.rs:1:1
  |
1 | ///
  | ^^^ this doc comment doesn't document anything

@pickfire
Copy link
Contributor Author

pickfire commented Feb 24, 2021

@troublescooter That is a different issue, please open a new issue if there is no existing issue on that. I see no issue with that.

@troublescooter
Copy link

troublescooter commented Feb 24, 2021

I'm confused what you mean by you see no issue with that. Do you mean no Github issue or no problem whatsoever?
I should have formulated the example more clearly, the issue here isn't that the docstring is missing. Swapping pub with async compiles without errors. So this seems at least related to the issue at hand where async was expected to be an item. In my example async pub fn doesn't seem to be recognised at all.

If I misunderstood your disagreement I'll happily file another issue.

@pickfire
Copy link
Contributor Author

I don't think the pull request I sent fix the issue you mentioned, need to check.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 18, 2021
Detect async visibility wrong order, `async pub`

Partially address rust-lang#76437.
@bors bors closed this as completed in 9321efd Mar 18, 2021
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 A-parser Area: The parsing of Rust source code to an AST A-visibility Area: Visibility / privacy C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants