]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/project-cache-issue-31849.rs
Rollup merge of #61499 - varkor:issue-53457, r=oli-obk
[rust.git] / src / test / run-pass / project-cache-issue-31849.rs
1 // Regression test for #31849: the problem here was actually a performance
2 // cliff, but I'm adding the test for reference.
3
4 pub trait Upcast<T> {
5     fn upcast(self) -> T;
6 }
7
8 impl<S1, S2, T1, T2> Upcast<(T1, T2)> for (S1,S2)
9     where S1: Upcast<T1>,
10           S2: Upcast<T2>,
11 {
12     fn upcast(self) -> (T1, T2) { (self.0.upcast(), self.1.upcast()) }
13 }
14
15 impl Upcast<()> for ()
16 {
17     fn upcast(self) -> () { () }
18 }
19
20 pub trait ToStatic {
21     type Static: 'static;
22     fn to_static(self) -> Self::Static where Self: Sized;
23 }
24
25 impl<T, U> ToStatic for (T, U)
26     where T: ToStatic,
27           U: ToStatic
28 {
29     type Static = (T::Static, U::Static);
30     fn to_static(self) -> Self::Static { (self.0.to_static(), self.1.to_static()) }
31 }
32
33 impl ToStatic for ()
34 {
35     type Static = ();
36     fn to_static(self) -> () { () }
37 }
38
39
40 trait Factory {
41     type Output;
42     fn build(&self) -> Self::Output;
43 }
44
45 impl<S,T> Factory for (S, T)
46     where S: Factory,
47           T: Factory,
48           S::Output: ToStatic,
49           <S::Output as ToStatic>::Static: Upcast<S::Output>,
50 {
51     type Output = (S::Output, T::Output);
52     fn build(&self) -> Self::Output { (self.0.build().to_static().upcast(), self.1.build()) }
53 }
54
55 impl Factory for () {
56     type Output = ();
57     fn build(&self) -> Self::Output { () }
58 }
59
60 fn main() {
61     // More parens, more time.
62     let it = ((((((((((),()),()),()),()),()),()),()),()),());
63     it.build();
64 }