]> git.lizzy.rs Git - rust.git/blob - tests/ui/did_you_mean/recursion_limit_deref.rs
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
[rust.git] / tests / ui / did_you_mean / recursion_limit_deref.rs
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 // compile-flags: -Zdeduplicate-diagnostics=yes
5
6 #![allow(dead_code)]
7 #![recursion_limit="10"]
8
9 macro_rules! link {
10     ($outer:ident, $inner:ident) => {
11         struct $outer($inner);
12
13         impl $outer {
14             fn new() -> $outer {
15                 $outer($inner::new())
16             }
17         }
18
19         impl std::ops::Deref for $outer {
20             type Target = $inner;
21
22             fn deref(&self) -> &$inner {
23                 &self.0
24             }
25         }
26     }
27 }
28
29 struct Bottom;
30 impl Bottom {
31     fn new() -> Bottom {
32         Bottom
33     }
34 }
35
36 link!(Top, A);
37 link!(A, B);
38 link!(B, C);
39 link!(C, D);
40 link!(D, E);
41 link!(E, F);
42 link!(F, G);
43 link!(G, H);
44 link!(H, I);
45 link!(I, J);
46 link!(J, K);
47 link!(K, Bottom);
48
49 fn main() {
50     let t = Top::new();
51     let x: &Bottom = &t; //~ ERROR mismatched types
52     //~^ error recursion limit
53 }