3 ms·
Sure, because it's compile-time code inside a (semantically) run-time check. In recent Rust versions you can do fn main() { const { if
by Sharlin 1y ago
Sure, because it's compile-time code inside a (semantically) run-time check. In recent Rust versions you can do
fn main() {
const {
if false {
let _:() = panic!();
}
}
}
which compiles as expected. (Note that if the binding were `const` instead of `let`, it'd still have failed to compile, because the semantics don't change.)
- tialaramex 1y agoPerhaps more succinctly: fn main() { const _:() = const { if false { panic!() } }; } It's fine that we want a constant, it's fine that this constant would, when being computed at compile time, panic if false was true, because it is not.
- dlahoda 1y agonot sure it is to be equivalent to zig. in zig they have one brach const. in rust example from you, whole control flow ix is const. which is not rquivalent to zig. so how to have non const branches?