Skip to content

Commit bdb95f1

Browse files
nikomatsakisNiko Matsakis
authored andcommitted
extend upcasting to bigger tuples
1 parent 529f5f9 commit bdb95f1

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

crates/formality-core/src/cast.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -246,28 +246,27 @@ where
246246
}
247247
}
248248

249-
impl<A, B, A1, B1> UpcastFrom<(A1, B1)> for (A, B)
250-
where
251-
A1: Upcast<A>,
252-
B1: Upcast<B>,
253-
{
254-
fn upcast_from(term: (A1, B1)) -> Self {
255-
let (a1, b1) = term;
256-
(a1.upcast(), b1.upcast())
257-
}
249+
macro_rules! tuple_impl {
250+
($($from:ident),*; $($to:ident),*) => {
251+
impl<$($from,)* $($to,)*> UpcastFrom<($($from,)*)> for ($($to,)*)
252+
where
253+
$($from: Upcast<$to>,)*
254+
{
255+
#[allow(non_snake_case)]
256+
fn upcast_from(term: ($($from,)*)) -> Self {
257+
let ($($from,)*) = term;
258+
($($from.upcast(),)*)
259+
}
260+
}
261+
};
258262
}
259263

260-
impl<A, B, C, A1, B1, C1> UpcastFrom<(A1, B1, C1)> for (A, B, C)
261-
where
262-
A1: Upcast<A>,
263-
B1: Upcast<B>,
264-
C1: Upcast<C>,
265-
{
266-
fn upcast_from(term: (A1, B1, C1)) -> Self {
267-
let (a1, b1, c1) = term;
268-
(a1.upcast(), b1.upcast(), c1.upcast())
269-
}
270-
}
264+
tuple_impl!(A1, B1; A, B);
265+
tuple_impl!(A1, B1, C1; A, B, C);
266+
tuple_impl!(A1, B1, C1, D1; A, B, C, D);
267+
tuple_impl!(A1, B1, C1, D1, E1; A, B, C, D, E);
268+
tuple_impl!(A1, B1, C1, D1, E1, F1; A, B, C, D, E, F);
269+
tuple_impl!(A1, B1, C1, D1, E1, F1, G1; A, B, C, D, E, F, G);
271270

272271
#[macro_export]
273272
macro_rules! cast_impl {

0 commit comments

Comments
 (0)