Infallible promotion by RalfJung · Pull Request #3027 · rust-lang/rfcs (original) (raw)

How about changing constants so that if they have a #[panic] attribute they can have a "panic" value that results in a panic upon const use?

That would need a lot of complicated machinery all over the compiler. Note that we need a "complicated, inflexible and limited list of special cases" anyway for promotion, e.g. to exclude interior mutability or types that drop. All this RFC is doing is restricting that list just a bit more to avoid having to deal with consts that can fail to evaluate without making compilation fail.

In other words, this RFC is a lot simpler than what you proposed. The patch to implement this RFC will be less than 20 lines, followed by a cleanup PR that can remove way more code (and way more subtle code) than what the RFC implementation added.

Also note that panics are not the only way consts can fail to evaluate. They can also cause Undefined Behavior or perform an operation that us not support by CTFE.