From 46cd80b691f0e127076b6dcd1bf9285c3e608d4a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 25 Apr 2024 16:14:22 -0300 Subject: [PATCH] Test that unsafe extern defines unsafe fns --- .../extern-items-unsafe.edition2021.stderr | 11 ++++++++++ .../extern-items-unsafe.edition2024.stderr | 11 ++++++++++ .../extern-items-unsafe.rs | 21 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr create mode 100644 tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr create mode 100644 tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr new file mode 100644 index 00000000000..a94f8d74236 --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr @@ -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`. diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr new file mode 100644 index 00000000000..c187dac1152 --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr @@ -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`. diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs new file mode 100644 index 00000000000..70f3c0afe7c --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs @@ -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() {}