Skip to content

Commit 646dbe2

Browse files
committed
Use cast_signed/cast_unsigned from stdlib
1 parent 7542c80 commit 646dbe2

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ deranged = { version = "0.5.2", features = ["powerfmt"] }
2121
itoa = "1.0.1"
2222
js-sys = "0.3.58"
2323
libc = "0.2.98"
24-
num-conv = "0.1.0"
24+
num-conv = "0.2.0"
2525
num_threads = "0.1.2"
2626
powerfmt = { version = "0.2.0", default-features = false }
2727
quickcheck = { version = "1.0.3", default-features = false }

time/src/duration.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,9 +1482,19 @@ impl SubAssign<Duration> for StdDuration {
14821482
}
14831483
}
14841484

1485-
/// Implement `Mul` (reflexively) and `Div` for `Duration` for various types.
1485+
/// Given a value and whether it is signed, cast it to the signed version.
1486+
macro_rules! cast_signed {
1487+
(@signed $val:ident) => {
1488+
$val
1489+
};
1490+
(@unsigned $val:ident) => {
1491+
$val.cast_signed()
1492+
};
1493+
}
1494+
1495+
/// Implement `Mul` (reflexively) and `Div` for `Duration` for various signed types.
14861496
macro_rules! duration_mul_div_int {
1487-
($($type:ty),+) => {$(
1497+
($(@$signedness:ident $type:ty),+ $(,)?) => {$(
14881498
impl Mul<$type> for Duration {
14891499
type Output = Self;
14901500

@@ -1493,7 +1503,7 @@ macro_rules! duration_mul_div_int {
14931503
fn mul(self, rhs: $type) -> Self::Output {
14941504
Self::nanoseconds_i128(
14951505
self.whole_nanoseconds()
1496-
.checked_mul(rhs.cast_signed().extend::<i128>())
1506+
.checked_mul(cast_signed!(@$signedness rhs).extend::<i128>())
14971507
.expect("overflow when multiplying duration")
14981508
)
14991509
}
@@ -1516,13 +1526,21 @@ macro_rules! duration_mul_div_int {
15161526
#[track_caller]
15171527
fn div(self, rhs: $type) -> Self::Output {
15181528
Self::nanoseconds_i128(
1519-
self.whole_nanoseconds() / rhs.cast_signed().extend::<i128>()
1529+
self.whole_nanoseconds() / cast_signed!(@$signedness rhs).extend::<i128>()
15201530
)
15211531
}
15221532
}
15231533
)+};
15241534
}
1525-
duration_mul_div_int![i8, i16, i32, u8, u16, u32];
1535+
1536+
duration_mul_div_int! {
1537+
@signed i8,
1538+
@signed i16,
1539+
@signed i32,
1540+
@unsigned u8,
1541+
@unsigned u16,
1542+
@unsigned u32,
1543+
}
15261544

15271545
impl Mul<f32> for Duration {
15281546
type Output = Self;

time/src/ext/systemtime.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use std::time::SystemTime;
22

3-
#[allow(unused_imports, reason = "MSRV of 1.87")]
4-
use num_conv::prelude::*;
5-
63
use crate::Duration;
74

85
/// Sealed trait to prevent downstream implementations.

time/src/formatting/iso8601.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
33
use std::io;
44

5-
#[allow(unused_imports, reason = "MSRV of 1.87")]
6-
use num_conv::prelude::*;
7-
85
use crate::convert::*;
96
use crate::format_description::well_known::Iso8601;
107
use crate::format_description::well_known::iso8601::{

time/src/parsing/combinator/rfc/iso8601.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
55
use core::num::NonZero;
66

7-
#[allow(unused_imports, reason = "MSRV of 1.87")]
8-
use num_conv::prelude::*;
9-
107
use crate::parsing::ParsedItem;
118
use crate::parsing::combinator::{any_digit, ascii_char, exactly_n_digits, first_match, sign};
129
use crate::{Month, Weekday};

time/src/parsing/iso8601.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//! Parse parts of an ISO 8601-formatted value.
22
3-
#[allow(unused_imports, reason = "MSRV of 1.87")]
4-
use num_conv::prelude::*;
5-
63
use crate::convert::*;
74
use crate::error;
85
use crate::error::ParseFromDescription::{InvalidComponent, InvalidLiteral};

0 commit comments

Comments
 (0)