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 diagnosis for extern "C" pub fn name() {} #113342

Closed
aDotInTheVoid opened this issue Jul 4, 2023 · 0 comments · Fixed by #113350
Closed

Wrong diagnosis for extern "C" pub fn name() {} #113342

aDotInTheVoid opened this issue Jul 4, 2023 · 0 comments · Fixed by #113350
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

Code

#[no_mangle]
extern "C" pub fn id(x: i32) -> i32 { x }

Current output

error: expected `{`, found keyword `pub`
 --> error.rs:2:12
  |
2 | extern "C" pub fn id(x: i32) -> i32 { x }
  |            ^^^ expected `{`

error: aborting due to previous error

Desired output

error: expected `{` or `fn`, found keyword `pub`
 --> error.rs:2:12
  |
2 | extern "C" pub fn id(x: i32) -> i32 { x }
  |            ^^^ expected `{`

error: aborting due to previous error

Rationale and extra context

The correct code here is

 extern "C" fn id(x: i32) -> i32 { x }

but the error doesn't suggest that fn keyword would be allowed here.

Ideally we'd recover from this, and say "visibility isn't allowed for extern functions", but if that's not feasible, then we should accurately report the tokens allowed.

Other cases

No response

Anything else?

No response

@aDotInTheVoid aDotInTheVoid added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 4, 2023
@chenyukang chenyukang self-assigned this Jul 5, 2023
@bors bors closed this as completed in 2bc0ae3 Jul 6, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants