Entering catch
Inner panic
thread 'main' panicked at 'explicit panic', src/lib.rs:4:5
stack backtrace:
0: rust_begin_unwind
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
2: core::panicking::panic
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:48:5
3: do_panic
4: handle_ffi_panic::main::{{closure}}
at ./src/main.rs:6:18
5: std::panicking::try::do_call
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
6: __rust_try
7: std::panicking::try
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
8: std::panic::catch_unwind
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
9: handle_ffi_panic::main
at ./src/main.rs:4:5
10: core::ops::function::FnOnce::call_once
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
I'm still here
I guess nomicon info is outdated? Did I misunderstand something? This also works if I encapsulate panicking lib call inside C-lib call
Should that be the case only when it is extern "C-unwind"?
With #![feature(c_unwind)] attempting to unwind from rust out of an extern "C" function will abort. Currently it is UB. Attempting to unwindind into rust through extern "C" is UB and will remain so.
Panicking in extern "C" fn is subtly broken, and will soon stop working completely. These functions are marked as nounwind in LLVM and it can use this information to miscompile code in more complex cases.
But the actual reason is that I've made noise about it Rust was going to unconditionally hard abort on unwind here, before "C-unwind" existed, but I've abused panics to recover from libjpeg errors, and it'd make my library unusable. Now that Rust has added extern "C-unwind" aborting in extern "C" is coming back.
Catching a panic from extern "Rust" fn is fully defined. In fact all functions are extern "Rust" fn by default. You just have to make sure that both sides are compiled with the same rustc version and use the same function signature if you use extern "Rust" { fn ... }.