Skip to content

Bad parse error on token sequences safe unsafe and unsafe safe (before extern fns) #133630

Closed as not planned
@ionicmc-rs

Description

@ionicmc-rs

Code

safe unsafe extern "C" fn foo() {
   // ...
}

Current output

help: unsafe comes before safe: `unsafe safe`

Desired output

error: safe is invalid outside of `unsafe extern` blocks
help: extern functions are safe by default

Rationale and extra context

this is a follow-up to my previous issue #133586, for more info you can visit it or see the PR (#133618 (closed))

Other cases

unsafe safe extern "C" fn foo() {} // safe is recognised as an identifier, and suggests putting a block around it

Rust Version

rustc 1.82.0 (f6e511eec 2024-10-15)
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?

The same happens with nightly releases

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 ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.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