Skip to content

Commit 8366c7f

Browse files
committed
Stabilize unsafe extern blocks (RFC 3484)
1 parent 20f23ab commit 8366c7f

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

+85
-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
@@ -452,11 +452,6 @@ impl<'a> AstValidator<'a> {
452452
item_span: span,
453453
block: Some(self.current_extern_span().shrink_to_lo()),
454454
});
455-
} else if !self.features.unsafe_extern_blocks {
456-
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
457-
item_span: span,
458-
block: None,
459-
});
460455
}
461456
}
462457
}
@@ -1053,32 +1048,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10531048
errors::VisibilityNotPermittedNote::IndividualForeignItems,
10541049
);
10551050

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

10841066
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
@@ -561,10 +561,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
561561
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
562562
gate_all!(global_registration, "global registration is experimental");
563563
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
564-
gate_all!(
565-
unsafe_extern_blocks,
566-
"`unsafe extern {}` blocks and `safe` keyword are experimental"
567-
);
568564
gate_all!(return_type_notation, "return type notation is experimental");
569565

570566
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 const generic parameters to be defined with types that
634632
/// are not `Sized`, e.g. `fn foo<const N: [u8]>() {`.
635633
(incomplete, unsized_const_params, "CURRENT_RUSTC_VERSION", Some(95174)),

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
@@ -1205,9 +1205,6 @@ impl<'a> Parser<'a> {
12051205
if self.eat_keyword_case(kw::Unsafe, case) {
12061206
Safety::Unsafe(self.prev_token.uninterpolated_span())
12071207
} else if self.eat_keyword_case(kw::Safe, case) {
1208-
self.psess
1209-
.gated_spans
1210-
.gate(sym::unsafe_extern_blocks, self.prev_token.uninterpolated_span());
12111208
Safety::Safe(self.prev_token.uninterpolated_span())
12121209
} else {
12131210
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)