]> git.lizzy.rs Git - rust.git/blob - src/test/ui/recursion/recursion.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[rust.git] / src / test / ui / recursion / recursion.rs
1 enum Nil {NilValue}
2 struct Cons<T> {head:isize, tail:T}
3 trait Dot {fn dot(&self, other:Self) -> isize;}
4 impl Dot for Nil {
5   fn dot(&self, _:Nil) -> isize {0}
6 }
7 impl<T:Dot> Dot for Cons<T> {
8   fn dot(&self, other:Cons<T>) -> isize {
9     self.head * other.head + self.tail.dot(other.tail)
10   }
11 }
12 fn test<T:Dot> (n:isize, i:isize, first:T, second:T) ->isize { //~ ERROR recursion limit
13   match n {    0 => {first.dot(second)}
14       // FIXME(#4287) Error message should be here. It should be
15       // a type error to instantiate `test` at a type other than T.
16     _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})}
17   }
18 }
19 pub fn main() {
20   let n = test(1, 0, Nil::NilValue, Nil::NilValue);
21   println!("{}", n);
22 }