Skip to content

Suboptimal error message for new extern block syntax #126327

Closed
@GuillaumeGomez

Description

@GuillaumeGomez

With the following code:

extern {
    pub fn foo();
    pub safe fn bar();
}

We get this error:

error: items in unadorned `extern` blocks cannot have safety qualifiers
 --> foo.rs:4:5
  |
1 | extern {
  | ------ help: add unsafe to this `extern` block
...
4 |     pub safe fn bar();
  |     ^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Making the extern block unsafe then gives:

error: extern block cannot be declared unsafe
 --> foo.rs:1:1
  |
1 | unsafe extern {
  | ^^^^^^

error: items in unadorned `extern` blocks cannot have safety qualifiers
 --> foo.rs:4:5
  |
1 | unsafe extern {
  | ------------- help: add unsafe to this `extern` block
...
4 |     pub safe fn bar();
  |     ^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

cc @spastorino

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