Idea: Static assertions

I think a valuable goal is the possibility of declaring all of the contract outside of the fn body:

fn foo<const N: usize, const M: usize>() -> usize
  where predicate(N, M) {
    ...
}

Even for run-time values:

fn foo(n: usize, m: usize) -> usize
  where predicate(n, m) {
    ...
}

If the predicate of some run-time values cannot be determined at compile time then a run-time assertion would have to be generated by the compiler. However, if the predicate can be proved at compile time then the run-time check is unnecessary and is eliminated.

3 Likes