Skip to content

Commit 6b58bce

Browse files
committed
Allow unsafe extern on all editions
1 parent 83e076d commit 6b58bce

File tree

7 files changed

+11
-36
lines changed

7 files changed

+11
-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
}
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)