Skip to content

Commit a62cbda

Browse files
committed
Add feature diagnostic for unsafe_extern_blocks
1 parent 99f77a2 commit a62cbda

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10881088
}
10891089
}
10901090
} else if let &Safety::Unsafe(span) = safety {
1091-
this.dcx().emit_err(errors::UnsafeItem { span, kind: "extern block" });
1091+
let mut diag = this
1092+
.dcx()
1093+
.create_err(errors::UnsafeItem { span, kind: "extern block" });
1094+
rustc_session::parse::add_feature_diagnostics(
1095+
&mut diag,
1096+
self.session,
1097+
sym::unsafe_extern_blocks,
1098+
);
1099+
diag.emit();
10921100
}
10931101

10941102
if abi.is_none() {

tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ error: extern block cannot be declared unsafe
33
|
44
LL | unsafe extern "C" {
55
| ^^^^^^
6+
|
7+
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information
8+
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
610

711
error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental
812
--> $DIR/feature-gate-unsafe-extern-blocks.rs:9:5

tests/ui/parser/unsafe-foreign-mod-2.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ error: extern block cannot be declared unsafe
99
|
1010
LL | extern "C" unsafe {
1111
| ^^^^^^
12+
|
13+
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information
14+
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable
15+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1216

1317
error: items in unadorned `extern` blocks cannot have safety qualifiers
1418
--> $DIR/unsafe-foreign-mod-2.rs:4:5

tests/ui/parser/unsafe-foreign-mod.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ error: extern block cannot be declared unsafe
33
|
44
LL | unsafe extern "C" {
55
| ^^^^^^
6+
|
7+
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information
8+
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
610

711
error: aborting due to 1 previous error
812

0 commit comments

Comments
 (0)