Test that unsafe extern defines unsafe fns

This commit is contained in:
Santiago Pastorino 2024-04-25 16:14:22 -03:00
parent 6d670b74e5
commit 46cd80b691
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
3 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,11 @@
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe function or block
--> $DIR/extern-items-unsafe.rs:11:5
|
LL | test1(i);
| ^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0133`.

View File

@ -0,0 +1,11 @@
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe block
--> $DIR/extern-items-unsafe.rs:11:5
|
LL | test1(i);
| ^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0133`.

View File

@ -0,0 +1,21 @@
//@ revisions: edition2021 edition2024
//@[edition2021] edition:2021
//@[edition2024] edition:2024
//@[edition2024] compile-flags: -Zunstable-options
unsafe extern "C" {
fn test1(i: i32);
}
fn test2(i: i32) {
test1(i);
//~^ ERROR: call to unsafe function `test1` is unsafe
}
fn test3(i: i32) {
unsafe {
test1(i);
}
}
fn main() {}