Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 46cd80b

Browse files
committed
Test that unsafe extern defines unsafe fns
1 parent 6d670b7 commit 46cd80b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe function or block
2+
--> $DIR/extern-items-unsafe.rs:11:5
3+
|
4+
LL | test1(i);
5+
| ^^^^^^^^ call to unsafe function
6+
|
7+
= note: consult the function's documentation for information on how to avoid undefined behavior
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0133`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe block
2+
--> $DIR/extern-items-unsafe.rs:11:5
3+
|
4+
LL | test1(i);
5+
| ^^^^^^^^ call to unsafe function
6+
|
7+
= note: consult the function's documentation for information on how to avoid undefined behavior
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0133`.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ revisions: edition2021 edition2024
2+
//@[edition2021] edition:2021
3+
//@[edition2024] edition:2024
4+
//@[edition2024] compile-flags: -Zunstable-options
5+
6+
unsafe extern "C" {
7+
fn test1(i: i32);
8+
}
9+
10+
fn test2(i: i32) {
11+
test1(i);
12+
//~^ ERROR: call to unsafe function `test1` is unsafe
13+
}
14+
15+
fn test3(i: i32) {
16+
unsafe {
17+
test1(i);
18+
}
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)