Closed
Description
Given the Rust program:
fn main() {
let option: Option<bool> = None;
option.unwrap();
}
Running the program outputs:
thread '<main>' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:365
The same program using expect
instead of unwrap
outputs:
thread '<main>' panicked at 'oops', ../src/libcore/option.rs:333
In a program of non-trivial size, figuring out which call to unwrap
or expect
generated the panic is harder than it needs to be, since the line shown is where the panic actually happens inside libcore. For improved ergonomics, the file and line reported should be from the user's source code where the unwrap
or expect
was called.