考虑以下故意导致双重恐慌的代码:
use scopeguard::defer; // 1.1.0
fn main() {
defer!{ panic!() };
defer!{ panic!() };
}
我知道这通常发生在Drop
从先前的恐慌中展开时实现恐慌,但为什么它会导致程序发出非法指令?听起来代码已损坏或意外跳转到某个地方。我认为这可能与系统或代码生成有关,但我在各种平台上进行了测试,它们都以相同的原因发出类似的错误:
Linux:
thread panicked while panicking. aborting. Illegal instruction (core dumped)
窗户(带
cargo run
):thread panicked while panicking. aborting. error: process didn't exit successfully: `target\debug\tests.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
锈游乐场:
thread panicked while panicking. aborting. timeout: the monitored command dumped core /playground/tools/entrypoint.sh: line 11: 8 Illegal instruction timeout --signal=KILL ${timeout} "$@"
这是怎么回事?这是什么原因造成的?