Skip to content

Commit 9a8888c

Browse files
committed
Stabilize unsafe extern blocks (RFC 3484)
1 parent b01a977 commit 9a8888c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+79
-163
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,6 @@ impl<'a> AstValidator<'a> {
447447
item_span: span,
448448
block: Some(self.current_extern_span().shrink_to_lo()),
449449
});
450-
} else if !self.features.unsafe_extern_blocks {
451-
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
452-
item_span: span,
453-
block: None,
454-
});
455450
}
456451
}
457452
}
@@ -1048,32 +1043,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10481043
errors::VisibilityNotPermittedNote::IndividualForeignItems,
10491044
);
10501045

1051-
if this.features.unsafe_extern_blocks {
1052-
if &Safety::Default == safety {
1053-
if item.span.at_least_rust_2024() {
1054-
this.dcx()
1055-
.emit_err(errors::MissingUnsafeOnExtern { span: item.span });
1056-
} else {
1057-
this.lint_buffer.buffer_lint(
1058-
MISSING_UNSAFE_ON_EXTERN,
1059-
item.id,
1060-
item.span,
1061-
BuiltinLintDiag::MissingUnsafeOnExtern {
1062-
suggestion: item.span.shrink_to_lo(),
1063-
},
1064-
);
1065-
}
1046+
if &Safety::Default == safety {
1047+
if item.span.at_least_rust_2024() {
1048+
this.dcx().emit_err(errors::MissingUnsafeOnExtern { span: item.span });
1049+
} else {
1050+
this.lint_buffer.buffer_lint(
1051+
MISSING_UNSAFE_ON_EXTERN,
1052+
item.id,
1053+
item.span,
1054+
BuiltinLintDiag::MissingUnsafeOnExtern {
1055+
suggestion: item.span.shrink_to_lo(),
1056+
},
1057+
);
10661058
}
1067-
} else if let &Safety::Unsafe(span) = safety {
1068-
let mut diag = this
1069-
.dcx()
1070-
.create_err(errors::UnsafeItem { span, kind: "extern block" });
1071-
rustc_session::parse::add_feature_diagnostics(
1072-
&mut diag,
1073-
self.session,
1074-
sym::unsafe_extern_blocks,
1075-
);
1076-
diag.emit();
10771059
}
10781060

10791061
if abi.is_none() {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
545545
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
546546
gate_all!(global_registration, "global registration is experimental");
547547
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
548-
gate_all!(
549-
unsafe_extern_blocks,
550-
"`unsafe extern {}` blocks and `safe` keyword are experimental"
551-
);
552548
gate_all!(return_type_notation, "return type notation is experimental");
553549

554550
if !visitor.features.never_patterns {

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ declare_features! (
387387
(accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208)),
388388
/// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block.
389389
(accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668)),
390+
/// Allows unsafe on extern declarations and safety qualifiers over internal items.
391+
(accepted, unsafe_extern_blocks, "CURRENT_RUSTC_VERSION", Some(123743)),
390392
/// Allows importing and reexporting macros with `use`,
391393
/// enables macro modularization in general.
392394
(accepted, use_extern_macros, "1.30.0", Some(35896)),

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,6 @@ declare_features! (
628628
(incomplete, unnamed_fields, "1.74.0", Some(49804)),
629629
/// Allows unsafe attributes.
630630
(unstable, unsafe_attributes, "1.80.0", Some(123757)),
631-
/// Allows unsafe on extern declarations and safety qualifiers over internal items.
632-
(unstable, unsafe_extern_blocks, "1.80.0", Some(123743)),
633631
/// Allows unsized fn parameters.
634632
(internal, unsized_fn_params, "1.49.0", Some(48055)),
635633
/// Allows unsized rvalues at arguments and parameters.

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4865,7 +4865,6 @@ declare_lint! {
48654865
/// ### Example
48664866
///
48674867
/// ```rust
4868-
/// #![feature(unsafe_extern_blocks)]
48694868
/// #![warn(missing_unsafe_on_extern)]
48704869
/// #![allow(dead_code)]
48714870
///

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,6 @@ impl<'a> Parser<'a> {
11991199
if self.eat_keyword_case(kw::Unsafe, case) {
12001200
Safety::Unsafe(self.prev_token.uninterpolated_span())
12011201
} else if self.eat_keyword_case(kw::Safe, case) {
1202-
self.psess
1203-
.gated_spans
1204-
.gate(sym::unsafe_extern_blocks, self.prev_token.uninterpolated_span());
12051202
Safety::Safe(self.prev_token.uninterpolated_span())
12061203
} else {
12071204
Safety::Default

tests/rustdoc/unsafe-extern-blocks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Test to ensure the feature is working as expected.
22

3-
#![feature(unsafe_extern_blocks)]
43
#![crate_name = "foo"]
54

65
// @has 'foo/index.html'
@@ -13,7 +12,7 @@
1312
// @count - '//ul[@class="item-table"]//sup[@title="unsafe function"]' 1
1413
// @has - '//ul[@class="item-table"]//sup[@title="unsafe function"]' '⚠'
1514

16-
unsafe extern {
15+
unsafe extern "C" {
1716
// @has 'foo/static.FOO.html'
1817
// @has - '//pre[@class="rust item-decl"]' 'pub static FOO: i32'
1918
pub safe static FOO: i32;

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/ui/lint/unsafe_code/unsafe-extern-blocks.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(unsafe_extern_blocks)]
21
#![deny(unsafe_code)]
32

43
#[allow(unsafe_code)]

0 commit comments

Comments
 (0)