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.
Current documentation for
core::panic::PanicInfouses examples withdowncast_refand anunwrap. I was just porting over some oldno_stdcode and copied over the examples for testing. However in ano_stdcodebase 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 letto handle theNonecase.Not really that big of an issue, but I think any panic handler examples in the documentation should not be able to recursively panic.