]> git.lizzy.rs Git - rust.git/blob - tests/ui/recursion/recursion.rs
Rollup merge of #106709 - khuey:disable_split_dwarf_inlining_by_default, r=davidtwco
[rust.git] / tests / ui / recursion / recursion.rs
1 // build-fail
2 // compile-flags:-C overflow-checks=off
3 // normalize-stderr-test: ".nll/" -> "/"
4
5 enum Nil {NilValue}
6 struct Cons<T> {head:isize, tail:T}
7 trait Dot {fn dot(&self, other:Self) -> isize;}
8 impl Dot for Nil {
9   fn dot(&self, _:Nil) -> isize {0}
10 }
11 impl<T:Dot> Dot for Cons<T> {
12   fn dot(&self, other:Cons<T>) -> isize {
13     self.head * other.head + self.tail.dot(other.tail)
14   }
15 }
16 fn test<T:Dot> (n:isize, i:isize, first:T, second:T) ->isize {
17   match n {    0 => {first.dot(second)}
18     _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})}
19     //~^ ERROR recursion limit
20   }
21 }
22 pub fn main() {
23   let n = test(1, 0, Nil::NilValue, Nil::NilValue);
24   println!("{}", n);
25 }