One of the things holding static_assertions from becoming 1.0 is a restriction on where the wildcard identifier is allowed. I'm requesting that consts may be allowed to use _ just like with let bindings.
Nit: _ is a pattern, not an identifier. To me it'd seem odd to support only _ and not more general patterns (but general patterns do not seem useful for constants).
I feel this issue would be better simply by having some method--any method--of generating a hygienic name for an item (a const, fn, mod, etc.) inside a macro just like we are capable of doing (or perhaps, rather, forced to do) for local variables.
For static_assertions though you don鈥檛 actually want a const item, only the side effects of evaluating its initializer, right?
@SimonSapin yes, I'm mainly after the side effects. This is one way I can think of achieving what I want with minimal effect on the language. This is also a backwards-compatible change.
A const item using _ would allow for using the compile-time side effects multiple times within the same context without naming conflicts.
const destructuring (const (A, B): (&str, i32) = ("foo", 0);) might be a very nice addition, and then the _ patterns would come "for free". cc @nikomatsakis
I actually spoke to Niko about this a month ago. He recommended to add something like my const_assert macro to the language instead. The issue is that I need this issue for other macros within this crate as well.
@eddyb I really like the idea of adding constant destructuring to the language! This should also work for statics.
Closing in favor of https://github.com/rust-lang/rfcs/pull/2526.
Most helpful comment
constdestructuring (const (A, B): (&str, i32) = ("foo", 0);) might be a very nice addition, and then the_patterns would come "for free". cc @nikomatsakis