Enforcing no-std and no-panic during build

I'd be very interested in this as well.

I'm familiar with crates like dtolnay's no-panic and japaric's panic-never, the latter of which is being suggested as a convention or requirement for Rust embedded code, but...

It really seems like the sort of thing that belongs in rustc proper, as opposed to some sort of external hack. It would be nice to say, for some degree of confidence, that a whole program composed of several crates is panic-free, instead of crates having to opt into it on a crate-by-crate basis.

I also imagine that if the compiler knows a program will never panic, it could automatically make use of optimizations which aren't possible in panicking code.

The only way I know how to do that today is using const fn, which presently entails writing panic free code because const_panic isn't stable, but that almost seems like an accidental way of ensuring code is panic-free, and it looks like const_panic will be stable soon. That's actually great and I actually want to use const_panic in other contexts, and perhaps it's okay for otherwise "panic free" code to have const_panic code because it will only panic at compile time.

5 Likes