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

Rollup of 7 pull requests #71556

Merged
merged 19 commits into from
Apr 25, 2020
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6cdb825
Implement BitOr and BitOrAssign for the NonZero integer types
Mar 8, 2020
3f1a588
stabilize BTreeMap::remove_entry
DutchGhost Apr 2, 2020
cdb6bef
Deprecate `Box::into_raw_non_null`
SimonSapin Apr 15, 2020
b359fe1
Deprecate `Rc::into_raw_non_null` and `Arc::into_raw_non_null`
SimonSapin Apr 15, 2020
9a1c7db
Apply suggestions from code review
SimonSapin Apr 15, 2020
7709d20
Implement `Box::into_raw` based on `Box::leak`
SimonSapin Apr 15, 2020
4282776
Replace filter_map().next() calls with find_map()
cuviper Apr 25, 2020
19c29c4
Fix comment in docstring example for Error::kind
Askaholic Apr 25, 2020
b1fbd79
Add missing Send and Sync bounds for linked list Cursor and CursorMut.
crlf0710 Apr 25, 2020
df99de5
proc_macro: Stabilize `Span::resolved_at` and `Span::located_at`
petrochenkov Feb 10, 2020
966a295
Add a test for `Span::resolved_at` and `Span::located_at`
petrochenkov Apr 18, 2020
78a034d
Use the correct bound for `Cursor` `Send`
crlf0710 Apr 25, 2020
7b7c63c
Rollup merge of #69041 - petrochenkov:stabmodispan, r=Amanieu
Dylan-DPC Apr 25, 2020
b6e03c4
Rollup merge of #69813 - thomcc:nonzero-bitor, r=Amanieu
Dylan-DPC Apr 25, 2020
29fd528
Rollup merge of #70712 - :stabilize-remove-entry, r=Amanieu
Dylan-DPC Apr 25, 2020
939c932
Rollup merge of #71168 - SimonSapin:into_raw_non_null, r=Amanieu
Dylan-DPC Apr 25, 2020
9709785
Rollup merge of #71544 - cuviper:filter_map_next, r=Mark-Simulacrum
Dylan-DPC Apr 25, 2020
ecef6c7
Rollup merge of #71545 - Askaholic:patch-1, r=jonas-schievink
Dylan-DPC Apr 25, 2020
82642d7
Rollup merge of #71548 - crlf0710:cursor_bounds, r=Amanieu
Dylan-DPC Apr 25, 2020
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
52 changes: 52 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use crate::convert::Infallible;
use crate::fmt;
use crate::intrinsics;
use crate::mem;
use crate::ops::{BitOr, BitOrAssign};
use crate::str::FromStr;

// Used because the `?` operator is not allowed in a const context.
@@ -110,6 +111,57 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
}
}

#[stable(feature = "nonzero_bitor", since = "1.43.0")]
impl BitOr for $Ty {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
// Safety: since `self` and `rhs` are both nonzero, the
// result of the bitwise-or will be nonzero.
unsafe { $Ty::new_unchecked(self.get() | rhs.get()) }
}
}

#[stable(feature = "nonzero_bitor", since = "1.43.0")]
impl BitOr<$Int> for $Ty {
type Output = Self;
#[inline]
fn bitor(self, rhs: $Int) -> Self::Output {
// Safety: since `self` is nonzero, the result of the
// bitwise-or will be nonzero regardless of the value of
// `rhs`.
unsafe { $Ty::new_unchecked(self.get() | rhs) }
}
}

#[stable(feature = "nonzero_bitor", since = "1.43.0")]
impl BitOr<$Ty> for $Int {
type Output = $Ty;
#[inline]
fn bitor(self, rhs: $Ty) -> Self::Output {
// Safety: since `rhs` is nonzero, the result of the
// bitwise-or will be nonzero regardless of the value of
// `self`.
unsafe { $Ty::new_unchecked(self | rhs.get()) }
}
}

#[stable(feature = "nonzero_bitor", since = "1.43.0")]
impl BitOrAssign for $Ty {
#[inline]
fn bitor_assign(&mut self, rhs: Self) {
*self = *self | rhs;
}
}

#[stable(feature = "nonzero_bitor", since = "1.43.0")]
impl BitOrAssign<$Int> for $Ty {
#[inline]
fn bitor_assign(&mut self, rhs: $Int) {
*self = *self | rhs;
}
}

impl_nonzero_fmt! {
#[$stability] (Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
}
35 changes: 35 additions & 0 deletions src/libcore/tests/nonzero.rs
Original file line number Diff line number Diff line change
@@ -141,3 +141,38 @@ fn test_from_str() {
Some(IntErrorKind::Overflow)
);
}

#[test]
fn test_nonzero_bitor() {
let nz_alt = NonZeroU8::new(0b1010_1010).unwrap();
let nz_low = NonZeroU8::new(0b0000_1111).unwrap();

let both_nz: NonZeroU8 = nz_alt | nz_low;
assert_eq!(both_nz.get(), 0b1010_1111);

let rhs_int: NonZeroU8 = nz_low | 0b1100_0000u8;
assert_eq!(rhs_int.get(), 0b1100_1111);

let rhs_zero: NonZeroU8 = nz_alt | 0u8;
assert_eq!(rhs_zero.get(), 0b1010_1010);

let lhs_int: NonZeroU8 = 0b0110_0110u8 | nz_alt;
assert_eq!(lhs_int.get(), 0b1110_1110);

let lhs_zero: NonZeroU8 = 0u8 | nz_low;
assert_eq!(lhs_zero.get(), 0b0000_1111);
}

#[test]
fn test_nonzero_bitor_assign() {
let mut target = NonZeroU8::new(0b1010_1010).unwrap();

target |= NonZeroU8::new(0b0000_1111).unwrap();
assert_eq!(target.get(), 0b1010_1111);

target |= 0b0001_0000;
assert_eq!(target.get(), 0b1011_1111);

target |= 0;
assert_eq!(target.get(), 0b1011_1111);
}