Skip to main content

object_rainbow/
assert_impl.rs

1#[macro_export]
2#[doc(hidden)]
3macro_rules! unpack_where {
4    ({$($a:tt)*} {$($tr:tt)*} {$ty:ty} {$($w:tt)*} {}) => {
5        const _: () = {
6            fn _inner<$($a)* X: $($tr)*>() $($w)* {}
7            fn _outer<$($a)*>() $($w)* {
8                _inner::<$($a)* $ty>()
9            }
10        };
11    };
12    ({$($a:tt)*} {$($tr:tt)*} {$ty:ty} {$($w:tt)*} $ww:tt $($www:tt)*) => {
13        $crate::unpack_where!{ {$($a)*} {$($tr)*} {$ty} {$($w)* $ww} $($www)* }
14    };
15}
16
17/// ```rust
18/// object_rainbow::assert_impl!(
19///     impl<T> Send for std::sync::Arc<T>
20///     where
21///         T: Send + Sync,
22///     {}
23/// );
24/// object_rainbow::assert_impl!(
25///     impl<T> Sync for std::sync::Arc<T>
26///     where
27///         T: Send + Sync,
28///     {}
29/// );
30/// ```
31#[macro_export]
32macro_rules! assert_impl {
33    (impl $(<$($a:ident),*>)? $tr:ident$(<$($tra:ident),*>)? for $ty:ty where $($w:tt)*) => {
34        $crate::unpack_where! { {$($($a,)*)?} {$tr$(<$($tra),*>)?} {$ty} {} where $($w)* }
35    };
36    (impl $(<$($a:ident),*>)? $tr:ident$(<$($tra:ident),*>)? for $ty:ty {}) => {
37        $crate::unpack_where! { {$($($a,)*)?} {$tr$(<$($tra),*>)?} {$ty} {} {} }
38    };
39}
40
41assert_impl!(
42    impl<T> Clone for T where T: Copy {}
43);
44
45assert_impl!(
46    impl Copy for i64 {}
47);