Skip to content

Commit a4115fa

Browse files
committed
Allow unsafe extern on all editions
1 parent f4b3f15 commit a4115fa

File tree

12 files changed

+19
-36
lines changed

12 files changed

+19
-36
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,15 +1021,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10211021
walk_list!(self, visit_attribute, &item.attrs);
10221022
return; // Avoid visiting again.
10231023
}
1024-
ItemKind::ForeignMod(ForeignMod { abi, unsafety, .. }) => {
1024+
ItemKind::ForeignMod(ForeignMod { abi, .. }) => {
10251025
let old_item = mem::replace(&mut self.extern_mod, Some(item));
10261026
self.visibility_not_permitted(
10271027
&item.vis,
10281028
errors::VisibilityNotPermittedNote::IndividualForeignItems,
10291029
);
1030-
if let &Unsafe::Yes(span) = unsafety {
1031-
self.dcx().emit_err(errors::UnsafeItem { span, kind: "extern block" });
1032-
}
10331030
if abi.is_none() {
10341031
self.maybe_lint_missing_abi(item.span, item.id);
10351032
}

compiler/rustc_codegen_cranelift/src/debuginfo/unwind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Unwind info generation (`.eh_frame`)
22
3+
#![cfg_attr(not(bootstrap), allow(missing_unsafe_on_extern))]
4+
35
use cranelift_codegen::ir::Endianness;
46
use cranelift_codegen::isa::{unwind::UnwindInfo, TargetIsa};
57
use cranelift_object::ObjectProduct;

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(non_camel_case_types)]
22
#![allow(non_upper_case_globals)]
3+
#![cfg_attr(not(bootstrap), allow(missing_unsafe_on_extern))]
34

45
use super::debuginfo::{
56
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,

compiler/rustc_driver_impl/src/signal_handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Signal handler for rustc
22
//! Primarily used to extract a backtrace from stack overflow
33
4+
#![cfg_attr(not(bootstrap), allow(missing_unsafe_on_extern))]
5+
46
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
57
use std::alloc::{alloc, Layout};
68
use std::{fmt, mem, ptr};

compiler/rustc_llvm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![doc(rust_logo)]
33
#![feature(rustdoc_internals)]
44
#![allow(internal_features)]
5+
#![cfg_attr(not(bootstrap), allow(missing_unsafe_on_extern))]
56

67
// NOTE: This crate only exists to allow linking on mingw targets.
78

compiler/rustc_middle/src/ty/list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(bootstrap), allow(missing_unsafe_on_extern))]
2+
13
use super::flags::FlagComputation;
24
use super::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, TyCtxt, TypeFlags, WithInfcx};
35
use crate::arena::Arena;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
extern "C" unsafe {
2-
//~^ ERROR expected `{`, found keyword `unsafe`
3-
//~| ERROR extern block cannot be declared unsafe
2+
//~^ ERROR expected `{`, found keyword `unsafe`
43
unsafe fn foo();
5-
//~^ ERROR functions in `extern` blocks cannot have qualifiers
4+
//~^ ERROR functions in `extern` blocks cannot have qualifiers
65
}
76

87
fn main() {}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ error: expected `{`, found keyword `unsafe`
44
LL | extern "C" unsafe {
55
| ^^^^^^ expected `{`
66

7-
error: extern block cannot be declared unsafe
8-
--> $DIR/unsafe-foreign-mod-2.rs:1:12
9-
|
10-
LL | extern "C" unsafe {
11-
| ^^^^^^
12-
137
error: functions in `extern` blocks cannot have qualifiers
14-
--> $DIR/unsafe-foreign-mod-2.rs:4:5
8+
--> $DIR/unsafe-foreign-mod-2.rs:3:5
159
|
1610
LL | extern "C" unsafe {
1711
| ----------------- in this `extern` block
18-
...
12+
LL |
1913
LL | unsafe fn foo();
2014
| ^^^^^^ help: remove this qualifier
2115

22-
error: aborting due to 3 previous errors
16+
error: aborting due to 2 previous errors
2317

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
unsafe extern "C" {
2-
//~^ ERROR extern block cannot be declared unsafe
3-
}
1+
//@ build-pass
2+
3+
unsafe extern "C" {}
44

55
fn main() {}

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

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

tests/ui/rust-2024/unsafe-extern-blocks/extern-items.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
//@ build-pass
2+
13
extern "C" {
24
static TEST1: i32;
35
fn test1(i: i32);
46
}
57

68
unsafe extern "C" {
7-
//~^ ERROR: extern block cannot be declared unsafe
89
static TEST2: i32;
910
fn test2(i: i32);
1011
}

tests/ui/rust-2024/unsafe-extern-blocks/extern-items.stderr

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

0 commit comments

Comments
 (0)