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

Wrong suggestion: remove the qualifiers: fn #78941

Closed
DutchGhost opened this issue Nov 11, 2020 · 7 comments
Closed

Wrong suggestion: remove the qualifiers: fn #78941

DutchGhost opened this issue Nov 11, 2020 · 7 comments
Assignees
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Nov 11, 2020

When declaring extern functions with any qualifier (async, const, unsafe) like down below, rustc incorrectly suggests to remove the qualifier fn

extern "C" {
    async fn calleth();
}

The error message

error: functions in `extern` blocks cannot have qualifiers
 --> src/lib.rs:2:14
  |
1 | extern "C" {
  | ---------- in this `extern` block
2 |     async fn calleth();
  |     ---------^^^^^^^
  |     |
  |     help: remove the qualifiers: `fn`

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.
@jonas-schievink jonas-schievink added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 11, 2020
@estebank
Copy link
Contributor

It would be clearer if this wasn't an inline suggestion. The suggestion is trying to communicate to write

extern "C" {
    fn calleth();
}

This can be easily be fixed with a change from span_suggestion to span_suggestion_verbose.

@estebank estebank added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Nov 14, 2020
@ThePuzzlemaker
Copy link
Contributor

@rustbot claim

@ThePuzzlemaker
Copy link
Contributor

ThePuzzlemaker commented Nov 15, 2020

When using span_suggestion_verbose, the following is emitted:

error: functions in `extern` blocks cannot have qualifiers
 --> <anon>:2:11
  |
1 | extern "C" {
  | ---------- in this `extern` block
2 |     async fn calleth();
  |              ^^^^^^^
  |
help: remove the qualifiers
  |
2 |     fn calleth();
  |     ^^

error: aborting due to previous error

Is this what is desired?

@estebank
Copy link
Contributor

Is this what is desired?

Yes.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…stebank

Improve the diagnostic for when an `fn` contains qualifiers inside an `extern` block.

This mitigates rust-lang#78941. As suggested by `@estebank,` `span_suggestion` was replaced with `span_suggestion_verbose` for this specific diagnostic.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…stebank

Improve the diagnostic for when an `fn` contains qualifiers inside an `extern` block.

This mitigates rust-lang#78941. As suggested by ``@estebank,`` `span_suggestion` was replaced with `span_suggestion_verbose` for this specific diagnostic.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…stebank

Improve the diagnostic for when an `fn` contains qualifiers inside an `extern` block.

This mitigates rust-lang#78941. As suggested by ```@estebank,``` `span_suggestion` was replaced with `span_suggestion_verbose` for this specific diagnostic.
@ThePuzzlemaker
Copy link
Contributor

Fixed by #79200, a rollup containing #79082

@ThePuzzlemaker
Copy link
Contributor

@DutchGhost ^

@JohnTitor
Copy link
Member

Closing as fixed.

@ThePuzzlemaker You could close an issue by writing Fixes #<issue-number> in the OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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

5 participants