Skip to content

Compiler diagnostic suggests wrong keyword order #94879

Closed
@PoignardAzur

Description

@PoignardAzur

If I write this code:

#[cfg(FALSE)]
extern const fn hello() {}

The compiler tells me:

error: expected `fn`, found keyword `const`
 --> src/lib.rs:2:8
  | ...
  = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`

That's a great message, very helpful... except the order is wrong. If I write:

#[cfg(FALSE)]
default pub const async unsafe extern fn hello() {}

The compiler gives me a weird error message.

The correct order is pub, default, const, async, unsafe, extern; in other words, pub before everything else.

Indeed, the following code compiles without complaint:

#[cfg(FALSE)]
pub default const async unsafe extern fn hello() {}

(as well as other variants with pub(crate), crate, etc)

The diagnostic suggestion should be fixed.

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