@Lokathor I don’t think that can ever work “as is” without setting the Rust panicking implementation in stone forever, which is something that we probably don’t want to do to allow us to improve the implementation over time.
The problem is, that even if the code at both side of the FFI is Rust, it could be Rust compiled with two different toolchain versions, using incompatible panicking implementations. (Through C FFI, we can’t really check that).
On Windows, MSVC breaks ABI compatibility on every release (similar to how Rust releases currently work), so C++ has this same problem: https://stackoverflow.com/a/5108118
If you want error-handling which is portable across multiple compilers/compiler versions/compiler settings, either use return codes or OS-provided exceptions (e.g. SEH on Windows)
If you want to make this work, you need to pick the same panicking ABI at both sides of the FFI and stick to it. This is possible in Rust today: catch all panics, and pass them using a stable ABI, and then panic in Rust at the other side.
The stable ABI to use is… up to you actually. Sure both error-codes and SEH work, but you can also use a pointer to a string (and if the pointer is null, there was no error), or whatever you want. You can also write a proc macro that does the dance for you, but questions like “which error code should it use”, “should all panics use the same error code, or different ones”, (the same applies to raising structured exceptions), are all pretty much application dependent.
EDIT: Even if we could come up with a general way to translate panics across FFI boundaries for some situations, that won’t necessarily make panicking through FFI a good idea in practice. Lots of things that can’t be checked need to align for it to work (e.g. what happens if the two Rust crates linked use the same panic implementation but a different memory allocator due to a different toolchain version / linking issue, and one crates tries to free the panic payload of the other crate, etc.).