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> {
upcast(self) -> T6 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 {
upcast(self) -> (T1, T2)13 fn upcast(self) -> (T1, T2) { (self.0.upcast(), self.1.upcast()) }
14 }
15
16 impl Upcast<()> for ()
17 {
upcast(self) -> ()18 fn upcast(self) -> () { () }
19 }
20
21 pub trait ToStatic {
22 type Static: 'static;
to_static(self) -> Self::Static where Self: Sized23 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);
to_static(self) -> Self::Static31 fn to_static(self) -> Self::Static { (self.0.to_static(), self.1.to_static()) }
32 }
33
34 impl ToStatic for ()
35 {
36 type Static = ();
to_static(self) -> ()37 fn to_static(self) -> () { () }
38 }
39
40
41 trait Factory {
42 type Output;
build(&self) -> Self::Output43 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);
build(&self) -> Self::Output53 fn build(&self) -> Self::Output { (self.0.build().to_static().upcast(), self.1.build()) }
54 }
55
56 impl Factory for () {
57 type Output = ();
build(&self) -> Self::Output58 fn build(&self) -> Self::Output { () }
59 }
60
main()61 fn main() {
62 // More parens, more time.
63 let it = ((((((((((),()),()),()),()),()),()),()),()),());
64 it.build();
65 }
66