Skip to content

Bad parse error on token sequences safe unsafe and unsafe safe (before extern blocks) #133586

Closed as not planned
@ionicmc-rs

Description

@ionicmc-rs

Code

safe unsafe extern {
   // Code is irrelevant
}
// And
unsafe safe extern {
   // Code is irrelevant
}

Current output

help: `unsafe` must come before `safe`: `unsafe safe`
# And
help: `safe` must come before `unsafe`: `safe unsafe`

Desired output

# Either an error about how safe isn't stabilized (if it isn't) or something more descriptive
the keyword `safe` is unstable
# ...

Rationale and extra context

the same happens with nightly releases

Other cases

These cases are better mentioned in my newest issue (follow up: #133630)
Note: this is an edit which was made after the pull request

pub unsafe safe extern "C" do_sum(args: (i32, i32)) {
    // ...
}

Ouput:

error: visibility `pub` is not followed by an item
 --> src/err/mod.rs:4:5
  |
4 |     pub unsafe safe extern "C" fn do_sum(args: (i32, i32)) {
  |     ^^^ the visibility
  |
  = help: you likely meant to define an item, e.g., `pub fn foo() {}`

error: expected `{`, found `safe`
 --> src/err/mod.rs:4:16
  |
4 |     pub unsafe safe extern "C" fn do_sum(args: (i32, i32)) {
  |         ------ ^^^^ expected `{`
  |         |
  |         while parsing this `unsafe` expression
  |
help: you might have meant to write this as part of a block
  |
4 |     pub unsafe { safe } extern "C" fn do_sum(args: (i32, i32)) {
  |   

Note: when unsafe and safe are reversed here, it just tells you to reverse it again, but at least this time you aren't in a loop

Rust Version

binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

Anything else?

i was just messing around when i found out safe was a valid keyword, but then i got an infinite loop of reversing the order of safe and unsafe

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionA-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-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