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