Skip to content

Commit 525828d

Browse files
committed
Add rustfix test for unsafe extern blocks
1 parent be0726c commit 525828d

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ run-rustfix
2+
3+
#![feature(unsafe_extern_blocks)]
4+
#![deny(missing_unsafe_on_extern)]
5+
#![allow(unused)]
6+
7+
unsafe extern "C" {
8+
//~^ ERROR extern blocks should be unsafe [missing_unsafe_on_extern]
9+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
10+
static TEST1: i32;
11+
fn test1(i: i32);
12+
}
13+
14+
unsafe extern "C" {
15+
static TEST2: i32;
16+
fn test2(i: i32);
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ run-rustfix
2+
3+
#![feature(unsafe_extern_blocks)]
4+
#![deny(missing_unsafe_on_extern)]
5+
#![allow(unused)]
6+
7+
extern "C" {
8+
//~^ ERROR extern blocks should be unsafe [missing_unsafe_on_extern]
9+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
10+
static TEST1: i32;
11+
fn test1(i: i32);
12+
}
13+
14+
unsafe extern "C" {
15+
static TEST2: i32;
16+
fn test2(i: i32);
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: extern blocks should be unsafe
2+
--> $DIR/unsafe-extern-suggestion.rs:7:1
3+
|
4+
LL | extern "C" {
5+
| ^
6+
| |
7+
| _help: needs `unsafe` before the extern keyword: `unsafe`
8+
| |
9+
LL | |
10+
LL | |
11+
LL | | static TEST1: i32;
12+
LL | | fn test1(i: i32);
13+
LL | | }
14+
| |_^
15+
|
16+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
17+
= note: for more information, see issue #123743 <https://github.com/rust-lang/rust/issues/123743>
18+
note: the lint level is defined here
19+
--> $DIR/unsafe-extern-suggestion.rs:4:9
20+
|
21+
LL | #![deny(missing_unsafe_on_extern)]
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^
23+
24+
error: aborting due to 1 previous error
25+

0 commit comments

Comments
 (0)