From cf2dff2b1e3fa55fa5415d524200070d0d7aacfe Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:13:28 +0100 Subject: Move /src/test to /tests --- tests/ui/recursion/recursion.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/ui/recursion/recursion.rs (limited to 'tests/ui/recursion/recursion.rs') diff --git a/tests/ui/recursion/recursion.rs b/tests/ui/recursion/recursion.rs new file mode 100644 index 00000000000..b3ba0ec3a2a --- /dev/null +++ b/tests/ui/recursion/recursion.rs @@ -0,0 +1,25 @@ +// build-fail +// compile-flags:-C overflow-checks=off +// normalize-stderr-test: ".nll/" -> "/" + +enum Nil {NilValue} +struct Cons {head:isize, tail:T} +trait Dot {fn dot(&self, other:Self) -> isize;} +impl Dot for Nil { + fn dot(&self, _:Nil) -> isize {0} +} +impl Dot for Cons { + fn dot(&self, other:Cons) -> isize { + self.head * other.head + self.tail.dot(other.tail) + } +} +fn test (n:isize, i:isize, first:T, second:T) ->isize { + match n { 0 => {first.dot(second)} + _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})} + //~^ ERROR recursion limit + } +} +pub fn main() { + let n = test(1, 0, Nil::NilValue, Nil::NilValue); + println!("{}", n); +} -- cgit 1.4.1-3-g733a5