Currently, it’s illegal to create a constant with the name _. I propose that we allow this, giving it the same semantics as let _ = ... - namely, that the result is discarded.
Constants are often used for the side effect of determining whether some code compiles. This is used in serde, for example, to determine whether certain properties hold about a type. Currently, serde has to do naming tricks like:
const _NAME_THATS_UNLIKELY_TO_ALREADY_BE_USED: () = { <expression that won't compile if certain properties don't hold>; };
This is both ugly (it produces ugly user-visible compiler output when it fails) and error prone, as it’s not guaranteed that the symbol will be unique. Instead, if _ were a supported constant identifier, this could be simplified to:
const _: () = { ...; };
Thoughts?
cc @dtolnay @erickt