|
| 1 | +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// Regression test for #31849: the problem here was actually a performance |
| 12 | +// cliff, but I'm adding the test for reference. |
| 13 | + |
| 14 | +pub trait Upcast<T> { |
| 15 | + fn upcast(self) -> T; |
| 16 | +} |
| 17 | + |
| 18 | +impl<S1, S2, T1, T2> Upcast<(T1, T2)> for (S1,S2) |
| 19 | + where S1: Upcast<T1>, |
| 20 | + S2: Upcast<T2>, |
| 21 | +{ |
| 22 | + fn upcast(self) -> (T1, T2) { (self.0.upcast(), self.1.upcast()) } |
| 23 | +} |
| 24 | + |
| 25 | +impl Upcast<()> for () |
| 26 | +{ |
| 27 | + fn upcast(self) -> () { () } |
| 28 | +} |
| 29 | + |
| 30 | +pub trait ToStatic { |
| 31 | + type Static: 'static; |
| 32 | + fn to_static(self) -> Self::Static where Self: Sized; |
| 33 | +} |
| 34 | + |
| 35 | +impl<T, U> ToStatic for (T, U) |
| 36 | + where T: ToStatic, |
| 37 | + U: ToStatic |
| 38 | +{ |
| 39 | + type Static = (T::Static, U::Static); |
| 40 | + fn to_static(self) -> Self::Static { (self.0.to_static(), self.1.to_static()) } |
| 41 | +} |
| 42 | + |
| 43 | +impl ToStatic for () |
| 44 | +{ |
| 45 | + type Static = (); |
| 46 | + fn to_static(self) -> () { () } |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +trait Factory { |
| 51 | + type Output; |
| 52 | + fn build(&self) -> Self::Output; |
| 53 | +} |
| 54 | + |
| 55 | +impl<S,T> Factory for (S, T) |
| 56 | + where S: Factory, |
| 57 | + T: Factory, |
| 58 | + S::Output: ToStatic, |
| 59 | + <S::Output as ToStatic>::Static: Upcast<S::Output>, |
| 60 | +{ |
| 61 | + type Output = (S::Output, T::Output); |
| 62 | + fn build(&self) -> Self::Output { (self.0.build().to_static().upcast(), self.1.build()) } |
| 63 | +} |
| 64 | + |
| 65 | +impl Factory for () { |
| 66 | + type Output = (); |
| 67 | + fn build(&self) -> Self::Output { () } |
| 68 | +} |
| 69 | + |
| 70 | +fn main() { |
| 71 | + // More parens, more time. |
| 72 | + let it = ((((((((((),()),()),()),()),()),()),()),()),()); |
| 73 | + it.build(); |
| 74 | +} |
| 75 | + |
0 commit comments