Description
When we have a const expression with a generic parameter in it, we cannot be sure that the const expression is valid for all the values that the generic parameter might take.
fn foo<const N: usize>() {
let _: [u8; { /* some expression involving N */ }] = ...;
// ^ this type may not be well-formed, because the length may result in an error
}
If we do not force the caller of the function to specify that the expression must be well-formed, we may get post-monomorphisation errors, as we can only determine that the expression is well-formed after substituting the concrete values for the generic parameters. We therefore need some way to specify such a bound. This is currently not possible.
This was discussed in #66962 (comment), #66962 (comment), #68388 (comment).
@eddyb suggested the syntax where [u8; { /* some expression involving N */ }]:
, though it is not clear whether this would be appropriate. This needs some discussion and careful consideration of the WF implications.