Skip to content

extern "C" const unsafe fn does not trigger the "keyword order for functions declaration" note #140171

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

Open
cyrgani opened this issue Apr 22, 2025 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Apr 22, 2025

Code

extern "C" const unsafe fn x() {}

Current output

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

Desired output

error: expected `fn`, found keyword `const`
 --> src/lib.rs:1:12
  |
1 | extern "C" const unsafe fn x() {}
  | -----------^^^^^
  | |          |
  | |          expected `fn`
  | help: `extern "C"` must come after `const unsafe`: `const unsafe extern "C"`
  |
  = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

Rationale and extra context

this is also not very relevant. the extra diagnostic is probably not emitted because there are two misplaced tokens (extern "C").

Other cases

Rust Version

rustc 1.88.0-nightly (d6c1e454a 2025-04-21)
binary: rustc
commit-hash: d6c1e454aa8af5e7e59fbf5c4e7d3128d2f99582
commit-date: 2025-04-21
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Anything else?

No response

@cyrgani cyrgani 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 Apr 22, 2025
@fmease fmease added A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Apr 22, 2025
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 A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. 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

2 participants