| 
 | 1 | +//@ known-bug: #108499  | 
 | 2 | + | 
 | 3 | +// at lower recursion limits the recursion limit is reached before the bug happens  | 
 | 4 | +#![recursion_limit = "2000"]  | 
 | 5 | + | 
 | 6 | +// this will try to calculate 3↑↑3=3^(3^3)  | 
 | 7 | +type Test = <() as Op<((), ()), [[[(); 0]; 0]; 0], [[[(); 0]; 0]; 0],  | 
 | 8 | +    [[[[(); 0]; 0]; 0]; 0]>>::Result;  | 
 | 9 | + | 
 | 10 | +use std::default::Default;  | 
 | 11 | + | 
 | 12 | +fn main() {  | 
 | 13 | +    // force the compiler to actually evaluate `Test`  | 
 | 14 | +    println!("{}", Test::default());  | 
 | 15 | +}  | 
 | 16 | + | 
 | 17 | +trait Op<X, A, B, C> {  | 
 | 18 | +    type Result;  | 
 | 19 | +}  | 
 | 20 | + | 
 | 21 | +// this recursive function defines the hyperoperation sequence,  | 
 | 22 | +// a canonical example of the type of recursion which produces the issue  | 
 | 23 | +// the problem seems to be caused by having two recursive calls, the second  | 
 | 24 | +// of which depending on the first  | 
 | 25 | +impl<  | 
 | 26 | +    X: Op<(X, Y), A, [B; 0], [C; 0]>,  | 
 | 27 | +    Y: Op<(X, Y), A, X::Result, C>,  | 
 | 28 | +    A, B, C,  | 
 | 29 | +> Op<(X, Y), A, [[B; 0]; 0], [C; 0]> for () {  | 
 | 30 | +    type Result = Y::Result;  | 
 | 31 | +}  | 
 | 32 | + | 
 | 33 | +// base cases  | 
 | 34 | +impl<X, A, B> Op<X, A, B, ()> for () {  | 
 | 35 | +    type Result = [B; 0];  | 
 | 36 | +}  | 
 | 37 | + | 
 | 38 | +impl<X, A> Op<X, A, [(); 0], [(); 0]> for () {  | 
 | 39 | +    type Result = [A; 0];  | 
 | 40 | +}  | 
 | 41 | + | 
 | 42 | +impl<X, A, C> Op<X, A, [(); 0], [[C; 0]; 0]> for () {  | 
 | 43 | +    type Result = A;  | 
 | 44 | +}  | 
0 commit comments