]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-47139-1.rs
Rollup merge of #65389 - ecstatic-morse:zero-sized-array-no-drop, r=eddyb
[rust.git] / src / test / ui / issues / issue-47139-1.rs
1 // run-pass
2 // Regression test for issue #47139:
3 //
4 // Coherence was encountering an (unnecessary) overflow trying to
5 // decide if the two impls of dummy overlap.
6 //
7 // The overflow went something like:
8 //
9 // - `&'a ?T: Insertable` ?
10 // - let ?T = Option<?U> ?
11 // - `Option<?U>: Insertable` ?
12 // - `Option<&'a ?U>: Insertable` ?
13 // - `&'a ?U: Insertable` ?
14 //
15 // While somewhere in the middle, a projection would occur, which
16 // broke cycle detection.
17 //
18 // It turned out that this cycle was being kicked off due to some
19 // extended diagnostic attempts in coherence, so removing those
20 // sidestepped the issue for now.
21
22 #![allow(dead_code)]
23
24 pub trait Insertable {
25     type Values;
26
27     fn values(self) -> Self::Values;
28 }
29
30 impl<T> Insertable for Option<T>
31     where
32     T: Insertable,
33     T::Values: Default,
34 {
35     type Values = T::Values;
36
37     fn values(self) -> Self::Values {
38         self.map(Insertable::values).unwrap_or_default()
39     }
40 }
41
42 impl<'a, T> Insertable for &'a Option<T>
43     where
44     Option<&'a T>: Insertable,
45 {
46     type Values = <Option<&'a T> as Insertable>::Values;
47
48     fn values(self) -> Self::Values {
49         self.as_ref().values()
50     }
51 }
52
53 impl<'a, T> Insertable for &'a [T]
54 {
55     type Values = Self;
56
57     fn values(self) -> Self::Values {
58         self
59     }
60 }
61
62 trait Unimplemented { }
63
64 trait Dummy { }
65
66 struct Foo<T> { t: T }
67
68 impl<'a, U> Dummy for Foo<&'a U>
69     where &'a U: Insertable
70 {
71 }
72
73 impl<T> Dummy for T
74     where T: Unimplemented
75 { }
76
77 fn main() {
78 }