Ideally yes, like with async{} and unsafe{}, once const generics exist. But as a first step it could follow const item rules, and thus would only be able to reference other const items.
Yes, same as with nested unsafe{}
That’s what I was picturing, yes. Like expressions used in the length of an array.
I might be crazy, but my first thought on seeing this topic title was “oh neat, we’ll get lazy_static built into the language”. I don’t know how related that would be to your idea, just food for thought.
(My main use case is just constHashMaps or the like.)
That would then need to be a const pattern (?). Not sure this particular addition would be worth the complexity, one could simply calculate a separate constant and use this instead, which may be more desirable for documentation purposes, anyway.
const MAX = 2 * N;
match x { 0..N => ..., N..MAX => ..., _ => ... }
One neat use case for this would be implementing a generic parse! macro. We already have FromStr for types that can be parsed from strings, but it’s impossible to use at compile-time leading to things like this crate.
With const blocks this macro could simply expand to
let x: u32 = parse!("123");
let y: String = parse!("hello");
let x: PublicKey = parse!("tgta61gja8w7099b17bc33sp49n1zawr037p1n4n7n19qkmgtf9g");
// etc.
And have the parsing (and any errors) happen at compile time.