Skip to content

Commit 2ce0fb6

Browse files
committed
Remove unsafe from min/max bounds
1 parent b43a252 commit 2ce0fb6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/bounds.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ bounded_impl!(i128, i128::MIN, i128::MAX);
7474

7575
macro_rules! bounded_impl_nonzero_const {
7676
($t:ty, $v:expr, $i:ident) => {
77-
const $i: $t = {
78-
let arr = [$v];
79-
let idx = if $v != 0 { 0 } else { 1 };
80-
81-
unsafe { <$t>::new_unchecked(arr[idx]) }
77+
const $i: $t = match <$t>::new($v) {
78+
Some(nz) => nz,
79+
None => panic!("bad nonzero bound!"),
8280
};
8381
};
8482
}
@@ -88,12 +86,14 @@ macro_rules! bounded_impl_nonzero {
8886
impl Bounded for $t {
8987
#[inline]
9088
fn min_value() -> $t {
89+
// when MSRV is 1.70 we can use $t::MIN
9190
bounded_impl_nonzero_const!($t, $min, MIN);
9291
MIN
9392
}
9493

9594
#[inline]
9695
fn max_value() -> $t {
96+
// when MSRV is 1.70 we can use $t::MAX
9797
bounded_impl_nonzero_const!($t, $max, MAX);
9898
MAX
9999
}

0 commit comments

Comments
 (0)