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