Recursive type usage in function with Const Generics causes ICE #66205
Description
This is a toy example I made in order to later make tests which run for T<const M: usize>
with M=0..N
.
#![feature(const_generics)]
#[allow(incomplete_features)]
struct Z<const N: i32>;
impl<const N: i32> Z<{N}> {
fn fact() -> i32 {
match N {
k if k < 1 => 1,
_ => Z::<{N - 1}>::fact()
}
}
}
This is the error I get:
error: internal compiler error: src/librustc/ty/subst.rs:651: const parameter `N/#0` (Const { ty: i32, val: Param(N/#0) }/0) out of range when substituting substs=[]
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:890:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Error notes:
-
rustc 1.40.0-nightly (50f8aadd7 2019-11-07) running on x86_64-unknown-linux-gnu
-
compiler flags:
-C debuginfo=2 -C incremental --crate-type lib
Questions
I don't know if this kind of pattern is intended as part of the feature or in its future, but if not, I think it can be satisfied by using a procedural macro so that's probably alright.
The point of the pattern, as I mentioned at the beginning of the post, is to be able to test a particular generic type's implementation up to an arbitrary range of numeric constants. While implementing another project to help @varkor test the feature, I stumbled upon the problem of wanting to test hundreds of different constants, but having no way of doing so with say, a for
loop over a range of constants. This is one way I thought of making it work.
Am I making the right decisions here? How should I go about testing hundreds of constants? Thanks :)