Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,10 @@ impl Visitor<'_> for AstValidator<'_> {

if &Safety::Default == safety {
if item.span.at_least_rust_2024() {
self.dcx().emit_err(diagnostics::MissingUnsafeOnExtern { span: item.span });
self.dcx().emit_err(diagnostics::MissingUnsafeOnExtern {
span: item.span,
unsafe_span: item.span.shrink_to_lo(),
});
} else {
self.lint_buffer.buffer_lint(
MISSING_UNSAFE_ON_EXTERN,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_passes/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,13 @@ pub(crate) struct UnsafeItem {
pub(crate) struct MissingUnsafeOnExtern {
#[primary_span]
pub span: Span,

#[suggestion(
"needs `unsafe` before the extern keyword",
code = "unsafe ",
applicability = "machine-applicable"
)]
pub unsafe_span: Span,
}

#[derive(Diagnostic)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
error: extern blocks must be unsafe
--> $DIR/extern-items.rs:6:1
|
LL | / extern "C" {
LL | extern "C" {
| ^
| |
| _help: needs `unsafe` before the extern keyword: `unsafe`
| |
LL | |
LL | | static TEST1: i32;
LL | | fn test1(i: i32);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
error: extern blocks must be unsafe
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:5:1
|
LL | / extern "C" {
LL | extern "C" {
| ^
| |
| _help: needs `unsafe` before the extern keyword: `unsafe`
| |
LL | |
LL | | safe static TEST1: i32;
... |
Expand Down
Loading