Skip to content

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

Closed
@aDotInTheVoid

Description

@aDotInTheVoid

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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