]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-22638.rs
Rollup merge of #53208 - BurntPizza:protect-the-environment, r=alexcrichton
[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 // normalize-stderr-test: "<\[closure@.+`" -> "$$CLOSURE`"
12
13 #![allow(unused)]
14
15 #![recursion_limit = "20"]
16 #![type_length_limit = "20000000"]
17 #![crate_type = "rlib"]
18
19 #[derive(Clone)]
20 struct A (B);
21
22 impl A {
23     pub fn matches<F: Fn()>(&self, f: &F) {
24         let &A(ref term) = self;
25         term.matches(f);
26     }
27 }
28
29 #[derive(Clone)]
30 enum B {
31     Variant1,
32     Variant2(C),
33 }
34
35 impl B {
36     pub fn matches<F: Fn()>(&self, f: &F) {
37         match self {
38             &B::Variant2(ref factor) => {
39                 factor.matches(&|| ())
40             }
41             _ => unreachable!("")
42         }
43     }
44 }
45
46 #[derive(Clone)]
47 struct C (D);
48
49 impl C {
50     pub fn matches<F: Fn()>(&self, f: &F) {
51         let &C(ref base) = self;
52         base.matches(&|| {
53             C(base.clone()).matches(f)
54         })
55     }
56 }
57
58 #[derive(Clone)]
59 struct D (Box<A>);
60
61 impl D {
62     pub fn matches<F: Fn()>(&self, f: &F) {
63         //~^ ERROR reached the type-length limit while instantiating `D::matches::<[closure
64         let &D(ref a) = self;
65         a.matches(f)
66     }
67 }
68
69 pub fn matches() {
70     A(B::Variant1).matches(&(|| ()))
71 }