There are intrinsics like assert_inhabited, which can unwind, but use rust-intrinsic ABI that never unwinds:
|
| RustIntrinsic |
|
| PlatformIntrinsic |
|
| Unadjusted => false, |
An example demonstrating the issue. The argument passed to function f is never dropped, when assert_inhabited unwinds:
#![feature(core_intrinsics)]
#![feature(never_type)]
struct NoisyDrop(&'static str);
impl Drop for NoisyDrop {
fn drop(&mut self) {
println!("{}", self.0);
}
}
pub fn f<A, B>(_: A) {
core::intrinsics::assert_inhabited::<B>()
}
fn main() {
let _a = NoisyDrop("1");
f::<NoisyDrop, !>(NoisyDrop("2"));
}
$ rustc a.rs && ./a
thread 'main' panicked at 'attempted to instantiate uninhabited type `!`', a.rs:13:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1
There are intrinsics like
assert_inhabited, which can unwind, but userust-intrinsicABI that never unwinds:rust/compiler/rustc_middle/src/ty/layout.rs
Lines 1091 to 1093 in 6d651a2
An example demonstrating the issue. The argument passed to function
fis never dropped, whenassert_inhabitedunwinds: