Skip to content

Confusing diagnostic for inversion of extern "..." and unsafe in function decl #87217

Closed
@poliorcetics

Description

@poliorcetics

Given the following code (playground link):

extern "C" unsafe fn test() {}

The current output is:

error: expected `{`, found keyword `unsafe`
 --> src/lib.rs:1:12
  |
1 | extern "C" unsafe fn test() {}
  |            ^^^^^^ expected `{`

error: could not compile `playground` due to previous error

Ideally the output should look like the one for inverting unsafe and a visibility like pub:

error: expected one of `extern` or `fn`, found keyword `pub`
 --> src/main.rs:1:8
  |
1 | unsafe pub fn test() {}
  | -------^^^
  | |      |
  | |      expected one of `extern` or `fn`
  | help: visibility `pub` must come before `unsafe`: `pub unsafe`

error: could not compile `playground` due to previous error

Meta rustc -V:

rustc 1.55.0-nightly (74ef0c3e4 2021-07-16)

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