Skip to content
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

Documentation for core::panic::PanicInfo should not use unwrap() #51768

Closed
gamozolabs opened this issue Jun 25, 2018 · 0 comments
Closed

Documentation for core::panic::PanicInfo should not use unwrap() #51768

gamozolabs opened this issue Jun 25, 2018 · 0 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools P-medium Medium priority

Comments

@gamozolabs
Copy link

gamozolabs commented Jun 25, 2018

Current documentation for core::panic::PanicInfo uses examples with downcast_ref and an unwrap. I was just porting over some old no_std code and copied over the examples for testing. However in a no_std codebase this leads to infinite recursion and probably stack exhaustion or other weird behavior depending on the design of the system implementing the panic.

I think that the example should be changed from:

println!("panic occurred: {:?}", panic_info.payload().downcast_ref::<&str>().unwrap());

to something like:

println!("panic occurred: {:?}", panic_info.payload().downcast_ref::<&str>().unwrap_or("Payload unavailable"));

Or switching to if let to handle the None case.

Not really that big of an issue, but I think any panic handler examples in the documentation should not be able to recursively panic.

@sfackler sfackler added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Jun 25, 2018
@steveklabnik steveklabnik added the P-medium Medium priority label Jun 25, 2018
frewsxcv added a commit to frewsxcv/rust that referenced this issue Jul 11, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 11, 2018
…meGomez

Avoid unwrapping in PanicInfo doc example.

Fixes rust-lang#51768.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

3 participants