]> git.lizzy.rs Git - rust.git/blob - src/test/ui/did_you_mean/recursion_limit_deref.rs
Fix test
[rust.git] / src / test / ui / did_you_mean / recursion_limit_deref.rs
1 // Copyright 2017 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 // Test that the recursion limit can be changed and that the compiler
12 // suggests a fix. In this case, we have a long chain of Deref impls
13 // which will cause an overflow during the autoderef loop.
14
15 #![allow(dead_code)]
16 #![recursion_limit="10"]
17
18 macro_rules! link {
19     ($outer:ident, $inner:ident) => {
20         struct $outer($inner);
21
22         impl $outer {
23             fn new() -> $outer {
24                 $outer($inner::new())
25             }
26         }
27
28         impl std::ops::Deref for $outer {
29             type Target = $inner;
30
31             fn deref(&self) -> &$inner {
32                 &self.0
33             }
34         }
35     }
36 }
37
38 struct Bottom;
39 impl Bottom {
40     fn new() -> Bottom {
41         Bottom
42     }
43 }
44
45 link!(Top, A);
46 link!(A, B);
47 link!(B, C);
48 link!(C, D);
49 link!(D, E);
50 link!(E, F);
51 link!(F, G);
52 link!(G, H);
53 link!(H, I);
54 link!(I, J);
55 link!(J, K);
56 link!(K, Bottom);
57
58 fn main() {
59     let t = Top::new();
60     let x: &Bottom = &t;
61 }
62