]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-22638.rs
Merged migrated compile-fail tests and ui tests. Fixes #46841.
[rust.git] / src / test / ui / issues / issue-22638.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(unused)]
12
13 #![recursion_limit = "20"]
14 #![type_length_limit = "20000000"]
15 #![crate_type = "rlib"]
16
17 #[derive(Clone)]
18 struct A (B);
19
20 impl A {
21     pub fn matches<F: Fn()>(&self, f: &F) {
22         let &A(ref term) = self;
23         term.matches(f);
24     }
25 }
26
27 #[derive(Clone)]
28 enum B {
29     Variant1,
30     Variant2(C),
31 }
32
33 impl B {
34     pub fn matches<F: Fn()>(&self, f: &F) {
35         match self {
36             &B::Variant2(ref factor) => {
37                 factor.matches(&|| ())
38             }
39             _ => unreachable!("")
40         }
41     }
42 }
43
44 #[derive(Clone)]
45 struct C (D);
46
47 impl C {
48     pub fn matches<F: Fn()>(&self, f: &F) {
49         let &C(ref base) = self;
50         base.matches(&|| {
51             C(base.clone()).matches(f)
52         })
53     }
54 }
55
56 #[derive(Clone)]
57 struct D (Box<A>);
58
59 impl D {
60     pub fn matches<F: Fn()>(&self, f: &F) {
61         //~^ ERROR reached the type-length limit while instantiating `D::matches::<[closure
62         let &D(ref a) = self;
63         a.matches(f)
64     }
65 }
66
67 pub fn matches() {
68     A(B::Variant1).matches(&(|| ()))
69 }