-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Panicking when an Option is unwrapped should give a useful error message #30429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How should the compiler know which stack frame to display in the error message when a panic happens? |
I am also unsure through what mechanism this would be implemented. Even stack crawling's going to fail without debug info and give bad results if functions have been inlined. |
you can create a macro that reports the proper error file and line: http://is.gd/qhd6dt this can probably be generalized by creating an |
In case you don't know, setting |
I know about Similar/related issues:
|
This is going to need an RFC. Fortunately there already is one in rust-lang/rfcs#2091, and it seems to have passed FCP! I don't think we need this issue anymore, we can follow up there. |
Given the Rust program:
Running the program outputs:
The same program using
expect
instead ofunwrap
outputs:In a program of non-trivial size, figuring out which call to
unwrap
orexpect
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 theunwrap
orexpect
was called.The text was updated successfully, but these errors were encountered: