3 ms·
If you don’t want to pay for landing pads, you can compile your program with panic=abort, and you won’t get them. As you say, you can still get stack traces. T
by steveklabnik 7y ago
If you don’t want to pay for landing pads, you can compile your program with panic=abort, and you won’t get them. As you say, you can still get stack traces.
The only reason that this is feasible is precisely because panics are not used for recoverable error handing in Rust; libraries don’t break if you turn this option on.
- nixpulvis 7y agoWell, panics should not be used for recoverable error handing in Rust. There's no guarantee turning off panics in favor of aborts wont break the assumptions of some library. That library should probably break tho, since as you said, panics aren't meant to emulate application logic exceptions. use std::panic::catch_unwind; fn main() { let err = catch_unwind(|| { panic!("B") }); println!("Look ma, recoverable error handing! {:?}", err); }
- steveklabnik 7y agoYes, libraries that do this are encouraged to configure their Cargo.toml so that compilation will fail if someone turns on aborts.
- mwcampbell 7y agoCan I go further and disable stack traces as well, without giving up entirely on std? I don't want my release builds to have any of the extra code required to walk the stack. Just let the app crash; if I want a stack trace, I'll use a debugger.
- steveklabnik 7y agoI don’t remember details, but there’s somehow to do it, I think.
- connicpu 7y agoAlmost all of the bloat you get for stack traces is the extra information embedded in the stack frames, which you still need if you want your debugger to be able to display stack traces. If you don't want them to get printed on panic, you can give it a custom panic hook that doesn't do the stack trace walk.