about summary refs log tree commit diff
path: root/tests/ui/infinite/infinite-instantiation.rs
blob: 4f86f70ad14dae29bdf81fa70b93b89e8d935709 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//@ build-fail
//@ compile-flags: --diagnostic-width=100 -Zwrite-long-types-to-disk=yes

trait ToOpt: Sized {
    fn to_option(&self) -> Option<Self>;
}

impl ToOpt for usize {
    fn to_option(&self) -> Option<usize> {
        Some(*self)
    }
}

impl<T:Clone> ToOpt for Option<T> {
    fn to_option(&self) -> Option<Option<T>> {
        Some((*self).clone())
    }
}

fn function<T:ToOpt + Clone>(counter: usize, t: T) {
    if counter > 0 {
        function(counter - 1, t.to_option());
        //~^ ERROR reached the recursion limit while instantiating `function::<Option<
    }
}

fn main() {
    function(22, 22);
}