]> git.proxmox.com Git - rustc.git/blame - src/tools/rustfmt/tests/source/issue-2917/packed_simd.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / src / tools / rustfmt / tests / source / issue-2917 / packed_simd.rs
CommitLineData
f20569fa
XL
1// rustfmt-wrap_comments: true
2//! Implements `From` and `Into` for vector types.
3
4macro_rules! impl_from_vector {
5 ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt | $source:ident) => {
6 impl From<$source> for $id {
7 #[inline]
8 fn from(source: $source) -> Self {
9 fn static_assert_same_number_of_lanes<T, U>()
10 where
11 T: crate::sealed::Simd,
12 U: crate::sealed::Simd<LanesType = T::LanesType>,
13 {
14 }
15 use llvm::simd_cast;
16 static_assert_same_number_of_lanes::<$id, $source>();
17 Simd(unsafe { simd_cast(source.0) })
18 }
19 }
20
21 // FIXME: `Into::into` is not inline, but due to
22 // the blanket impl in `std`, which is not
23 // marked `default`, we cannot override it here with
24 // specialization.
25 /*
26 impl Into<$id> for $source {
27 #[inline]
28 fn into(self) -> $id {
29 unsafe { simd_cast(self) }
30 }
31 }
32 */
33
34 test_if!{
35 $test_tt:
36 interpolate_idents! {
37 mod [$id _from_ $source] {
38 use super::*;
39 #[test]
40 fn from() {
41 assert_eq!($id::lanes(), $source::lanes());
42 let source: $source = Default::default();
43 let vec: $id = Default::default();
44
45 let e = $id::from(source);
46 assert_eq!(e, vec);
47
48 let e: $id = source.into();
49 assert_eq!(e, vec);
50 }
51 }
52 }
53 }
54 };
55}
56
57macro_rules! impl_from_vectors {
58 ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt | $($source:ident),*) => {
59 $(
60 impl_from_vector!([$elem_ty; $elem_count]: $id | $test_tt | $source);
61 )*
62 }
63}