1 // Test that the recursion limit can be changed and that the compiler
2 // suggests a fix. In this case, we have a long chain of Deref impls
3 // which will cause an overflow during the autoderef loop.
4
5 #![allow(dead_code)]
6 #![recursion_limit="10"]
7
8 macro_rules! link {
9 ($outer:ident, $inner:ident) => {
10 struct $outer($inner);
11
12 impl $outer {
13 fn new() -> $outer {
14 $outer($inner::new())
15 }
16 }
17
18 impl std::ops::Deref for $outer {
19 type Target = $inner;
20
21 fn deref(&self) -> &$inner {
22 &self.0
23 }
24 }
25 }
26 }
27
28 struct Bottom;
29 impl Bottom {
new() -> Bottom30 fn new() -> Bottom {
31 Bottom
32 }
33 }
34
35 link!(Top, A);
36 link!(A, B);
37 link!(B, C);
38 link!(C, D);
39 link!(D, E);
40 link!(E, F);
41 link!(F, G);
42 link!(G, H);
43 link!(H, I);
44 link!(I, J);
45 link!(J, K);
46 link!(K, Bottom);
47
main()48 fn main() {
49 let t = Top::new();
50 let x: &Bottom = &t; //~ ERROR mismatched types
51 //~^ error recursion limit
52 }
53