| 1 |
// { dg-additional-options "-w" } |
| 2 |
#![feature(intrinsics)] |
| 3 |
|
| 4 |
#[lang = "sized"] |
| 5 |
pub trait Sized {} |
| 6 |
|
| 7 |
mod intrinsics { |
| 8 |
extern "rust-intrinsic" { |
| 9 |
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] |
| 10 |
pub fn wrapping_add<T>(a: T, b: T) -> T; |
| 11 |
#[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")] |
| 12 |
pub fn rotate_left<T>(a: T, b: T) -> T; |
| 13 |
#[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")] |
| 14 |
pub fn rotate_right<T>(a: T, b: T) -> T; |
| 15 |
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] |
| 16 |
pub fn offset<T>(ptr: *const T, count: isize) -> *const T; |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
mod mem { |
| 21 |
extern "rust-intrinsic" { |
| 22 |
#[rustc_const_stable(feature = "const_transmute", since = "1.46.0")] |
| 23 |
fn transmute<T, U>(_: T) -> U; |
| 24 |
#[rustc_const_stable(feature = "const_size_of", since = "1.40.0")] |
| 25 |
fn size_of<T>() -> usize; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
macro_rules! impl_uint { |
| 30 |
($($ty:ident = $lang:literal),*) => { |
| 31 |
$( |
| 32 |
impl $ty { |
| 33 |
pub fn wrapping_add(self, rhs: Self) -> Self { |
| 34 |
// intrinsics::wrapping_add(self, rhs) |
| 35 |
self + rhs |
| 36 |
} |
| 37 |
|
| 38 |
pub fn rotate_left(self, n: u32) -> Self { |
| 39 |
unsafe { |
| 40 |
intrinsics::rotate_left(self, n as Self) |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
pub fn rotate_right(self, n: u32) -> Self { |
| 45 |
unsafe { |
| 46 |
intrinsics::rotate_right(self, n as Self) |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
pub fn to_le(self) -> Self { |
| 51 |
{ |
| 52 |
self |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { |
| 57 |
Self::from_le(Self::from_ne_bytes(bytes)) |
| 58 |
} |
| 59 |
|
| 60 |
pub const fn from_le(x: Self) -> Self { |
| 61 |
#[cfg(target_endian = "little")] |
| 62 |
{ |
| 63 |
x |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { |
| 68 |
unsafe { mem::transmute(bytes) } |
| 69 |
} |
| 70 |
} |
| 71 |
)* |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
impl_uint!( |
| 76 |
u8 = "u8", |
| 77 |
u16 = "u16", |
| 78 |
u32 = "u32", |
| 79 |
u64 = "u64", |
| 80 |
usize = "usize" |
| 81 |
); |