Skip to content

Commit 09c71a5

Browse files
committed
add test for issue #96944
1 parent a339ed1 commit 09c71a5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// build-pass
2+
#![crate_type = "lib"]
3+
#![allow(arithmetic_overflow)]
4+
5+
pub trait BitSplit {
6+
type Half;
7+
fn merge(halves: [Self::Half; 2]) -> Self;
8+
}
9+
10+
macro_rules! impl_ints {
11+
($int:ty => $half:ty; $mask:expr) => {
12+
impl BitSplit for $int {
13+
type Half = $half;
14+
#[inline]
15+
fn merge(halves: [Self::Half; 2]) -> Self {
16+
const HALF_SIZE: usize = std::mem::size_of::<$half>() * 8;
17+
(halves[0] << HALF_SIZE) as $int | halves[1] as $int
18+
}
19+
}
20+
};
21+
}
22+
23+
impl_ints!(u128 => u64; 0x0000_0000_0000_0000_FFFF_FFFF_FFFF_FFFF);
24+
impl_ints!( u64 => u32; 0x0000_0000_FFFF_FFFF);
25+
impl_ints!( u32 => u16; 0x0000_FFFF);
26+
impl_ints!( u16 => u8; 0x00FF);

0 commit comments

Comments
 (0)