If there's a nightly feature for something like this, I don't know it. I also wouldn't know how to name something like this. The combination of calling a const fn and matching the result against a pattern in a where-clause seems quite far-fetched from the current capabilities of bound checks[1]. But you could head over to the Unstable Book and see if you can find something.
Your proposal looks more like LISPian sorcery to me âŠī¸
That's not the target syntax I'm looking for, it's just for ease of understanding. I don't care about the syntax of the implementation; I just need to make the compiler understand my bound.
error: generic parameters may not be used in const operations
--> src/lib.rs:12:22
|
12 | Boolean<{ checker::<T, U>() }>: True
| ^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
error: generic parameters may not be used in const operations
--> src/lib.rs:12:25
|
12 | Boolean<{ checker::<T, U>() }>: True
| ^ cannot perform const operation using `U`
|
= note: type parameters may not be used in const expressions
Edit:
I tried using inline constant expressions, but rustc doesn't provide static type hints for that, for example:
#![feature(inline_const)]
fn bar() -> Option<u32> {
if const { false == true } {
Some(10)
} else {
None
}
}
fn main() {
let b = bar();
b.unwrap();
}
will throw an error at runtime, not compile time, which means that the const is to some extent meaningless.
Edit:
My mistake, unwrap doesn't default to const.
Using a const fn checker that panics can let the compiler understand me, and the only downside is that the error message is a little complicated and hard to understand.