diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /src/test/run-make-fulldeps/c-unwind-abi-catch-lib-panic/main.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/run-make-fulldeps/c-unwind-abi-catch-lib-panic/main.rs')
-rw-r--r-- | src/test/run-make-fulldeps/c-unwind-abi-catch-lib-panic/main.rs | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/src/test/run-make-fulldeps/c-unwind-abi-catch-lib-panic/main.rs b/src/test/run-make-fulldeps/c-unwind-abi-catch-lib-panic/main.rs deleted file mode 100644 index 78a71219c..000000000 --- a/src/test/run-make-fulldeps/c-unwind-abi-catch-lib-panic/main.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! A test for calling `C-unwind` functions across foreign function boundaries. -//! -//! This test triggers a panic in a Rust library that our foreign function invokes. This shows -//! that we can unwind through the C code in that library, and catch the underlying panic. -#![feature(c_unwind)] - -use std::panic::{catch_unwind, AssertUnwindSafe}; - -fn main() { - // Call `add_small_numbers`, passing arguments that will NOT trigger a panic. - let (a, b) = (9, 1); - let c = unsafe { add_small_numbers(a, b) }; - assert_eq!(c, 10); - - // Call `add_small_numbers`, passing arguments that will trigger a panic, and catch it. - let caught_unwind = catch_unwind(AssertUnwindSafe(|| { - let (a, b) = (10, 1); - let _c = unsafe { add_small_numbers(a, b) }; - unreachable!("should have unwound instead of returned"); - })); - - // Assert that we did indeed panic, then unwrap and downcast the panic into the sum. - assert!(caught_unwind.is_err()); - let panic_obj = caught_unwind.unwrap_err(); - let msg = panic_obj.downcast_ref::<String>().unwrap(); - assert_eq!(msg, "11"); -} - -#[link(name = "add", kind = "static")] -extern "C-unwind" { - /// An external function, defined in C. - /// - /// Returns the sum of two numbers, or panics if the sum is greater than 10. - fn add_small_numbers(a: u32, b: u32) -> u32; -} |