Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions library/core/src/num/niche_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ define_valid_range_type! {
pub struct NonZeroI32Inner(i32 as u32 in 1..=0xffff_ffff);
pub struct NonZeroI64Inner(i64 as u64 in 1..=0xffffffff_ffffffff);
pub struct NonZeroI128Inner(i128 as u128 in 1..=0xffffffffffffffff_ffffffffffffffff);

pub struct NonZeroCharInner(char as u32 in 1..=0x10ffff);
}

#[cfg(target_pointer_width = "16")]
Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl_zeroable_primitive!(
NonZeroI64Inner(i64),
NonZeroI128Inner(i128),
NonZeroIsizeInner(isize),
NonZeroCharInner(char),
);

/// A value that is known not to equal zero.
Expand Down
9 changes: 4 additions & 5 deletions library/coretests/tests/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ mod u64;
mod u8;

mod bignum;

mod const_from;
mod dec2flt;
mod float_iter_sum_identity;
mod flt2dec;
mod ieee754;
mod int_log;
mod int_sqrt;
mod midpoint;
mod nan;
mod niche_types;
mod ops;
mod wrapping;

mod float_iter_sum_identity;
mod ieee754;
mod nan;

/// Adds the attribute to all items in the block.
macro_rules! cfg_block {
($(#[$attr:meta]{$($it:item)*})*) => {$($(
Expand Down
12 changes: 12 additions & 0 deletions library/coretests/tests/num/niche_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::num::NonZero;

#[test]
fn test_new_from_zero_is_none() {
assert_eq!(NonZero::<char>::new(0 as char), None);
}

#[test]
fn test_new_from_extreme_is_some() {
assert!(NonZero::<char>::new(1 as char).is_some());
assert!(NonZero::<char>::new(char::MAX).is_some());
}
Loading