4 ms·
Even for normal user space code having a way to detect panic at compile time and abort compilation would be great. Ideally together with a way to wrap functions
by pedrocr 6y ago
Even for normal user space code having a way to detect panic at compile time and abort compilation would be great. Ideally together with a way to wrap functions that do panic by catching it and throwing an error instead so the panic infrastructure can still be used. I've sketched that out on HN the other day:
https://news.ycombinator.com/item?id=26191644 https://news.ycombinator.com/item?id=26191644
- gpm 6y agoThis exists, provided you compile with the (default) unwinding panics https://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
- estebank 6y agoThat is still something that happens at runtime, not compile-time. What the kernel would need is not only for the fallible alloc APIs (like Box::try_new) to be expanded to cover all their needs, but also to be able to remove the ability to use the infallible/panicky ones (like Box::new) to ensure, at compile time, that panic will never be called.
- chrismorgan 6y ago> Note that this function may not catch all panics in Rust. A panic in Rust is not always implemented via unwinding, but can be implemented by aborting the process as well. This function only catches unwinding panics, not those that abort the process. The most notable way this can go wrong in pure Rust code is that panic-while-panicking aborts. So you have to be careful that your destructor can never panic.
- rocqua 6y agoWould a 'no_panic' annotation for a function, that is checked by the compiler, be a possiblity?