Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement BitAnd-based truncation for integers #54442

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/libcore/ops/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,50 @@ macro_rules! bitand_impl {

bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }

macro_rules! bitand_trunc_impl {
($($t:ty:$u:ty)*) => ($(
#[unstable(feature = "bitand_trunc", issue = "000000")]
impl BitAnd<$u> for $t {
type Output = $u;

#[inline]
fn bitand(self, rhs: $u) -> $u { self as $u & rhs }
}

forward_ref_binop! { impl BitAnd, bitand for $t, $u }
)*)
}

bitand_trunc_impl! {
usize:u32
usize:u16
usize:u8
u128:u64
u128:u32
u128:u16
u128:u8
u64:u32
u64:u16
u64:u8
u32:u16
u32:u8
u16:u8

isize:i32
isize:i16
isize:i8
i128:i64
i128:i32
i128:i16
i128:i8
i64:i32
i64:i16
i64:i8
i32:i16
i32:i8
i16:i8
}

/// The bitwise OR operator `|`.
///
/// Note that `RHS` is `Self` by default, but this is not mandatory.
Expand Down