Skip to content

"Built-in" panics (e.g. OOB array access) cannot be caught #1070

Closed

Description

The following code behaves wrong in Miri:

#![allow(const_err)]
use std::panic::catch_unwind;

fn main() {
    catch_unwind(|| [0, 1][2]).unwrap_err();
    println!("after-catch");
}

Instead of catching the panic, we get

error: Miri evaluation error: index out of bounds: the len is 2 but the index is 2
 --> t.rs:5:21
  |
5 |     catch_unwind(|| [0, 1][2]).unwrap_err();
  |                     ^^^^^^^^^ Miri evaluation error: index out of bounds: the len is 2 but the index is 2
  |
  = note: inside call to closure at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/panicking.rs:287:40
  = note: inside call to `std::panicking::try::do_call::<[closure@t.rs:5:18: 5:30], i32>` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/panicking.rs:282:5
  = note: inside call to `std::panicking::try::<i32, [closure@t.rs:5:18: 5:30]>` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/panic.rs:395:9
note: inside call to `std::panic::catch_unwind::<[closure@t.rs:5:18: 5:30], i32>` at t.rs:5:5
 --> t.rs:5:5
  |
5 |     catch_unwind(|| [0, 1][2]).unwrap_err();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: inside call to `main` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/rt.rs:61:34

Cc @Aaron1011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-panicsArea: affects panics and unwindingC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions