Skip to content

Apply clippy suggestions from Rust 1.79 #1595

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

Merged
merged 2 commits into from
Jul 8, 2024
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
1 change: 0 additions & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use core::borrow::Borrow;
use core::str;
use core::usize;

use super::scan;
use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric, Pad, Parsed};
Expand Down
4 changes: 2 additions & 2 deletions src/naive/date/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,14 @@ fn test_date_checked_add_signed() {
ymd(MAX_YEAR, 12, 31),
);
check(ymd(0, 1, 1), TimeDelta::try_days(MAX_DAYS_FROM_YEAR_0 as i64 + 1).unwrap(), None);
check(ymd(0, 1, 1), TimeDelta::max_value(), None);
check(ymd(0, 1, 1), TimeDelta::MAX, None);
check(
ymd(0, 1, 1),
TimeDelta::try_days(MIN_DAYS_FROM_YEAR_0 as i64).unwrap(),
ymd(MIN_YEAR, 1, 1),
);
check(ymd(0, 1, 1), TimeDelta::try_days(MIN_DAYS_FROM_YEAR_0 as i64 - 1).unwrap(), None);
check(ymd(0, 1, 1), TimeDelta::min_value(), None);
check(ymd(0, 1, 1), TimeDelta::MIN, None);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/naive/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ fn test_datetime_add() {
Some((NaiveDate::MAX.year(), 12, 31, 23, 59, 59)),
);
check((0, 1, 1, 0, 0, 0), max_days_from_year_0 + seconds(86_400), None);
check((0, 1, 1, 0, 0, 0), TimeDelta::max_value(), None);
check((0, 1, 1, 0, 0, 0), TimeDelta::MAX, None);

let min_days_from_year_0 =
NaiveDate::MIN.signed_duration_since(NaiveDate::from_ymd_opt(0, 1, 1).unwrap());
check((0, 1, 1, 0, 0, 0), min_days_from_year_0, Some((NaiveDate::MIN.year(), 1, 1, 0, 0, 0)));
check((0, 1, 1, 0, 0, 0), min_days_from_year_0 - seconds(1), None);
check((0, 1, 1, 0, 0, 0), TimeDelta::min_value(), None);
check((0, 1, 1, 0, 0, 0), TimeDelta::MIN, None);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/offset/local/tz_info/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
};

// Check if the current year is valid for the following computations
if !(i32::min_value() + 2 <= current_year && current_year <= i32::max_value() - 2) {
if !(i32::MIN + 2..=i32::MAX - 2).contains(&current_year) {
return Err(Error::OutOfRange("out of range date time"));
}

Expand Down Expand Up @@ -233,7 +233,7 @@
current_year: i32,
) -> Result<crate::MappedLocalTime<LocalTimeType>, Error> {
// Check if the current year is valid for the following computations
if !(i32::min_value() + 2 <= current_year && current_year <= i32::max_value() - 2) {
if !(i32::MIN + 2..=i32::MAX - 2).contains(&current_year) {

Check warning on line 236 in src/offset/local/tz_info/rule.rs

View check run for this annotation

Codecov / codecov/patch

src/offset/local/tz_info/rule.rs#L236

Added line #L236 was not covered by tests
return Err(Error::OutOfRange("out of range date time"));
}

Expand Down Expand Up @@ -687,7 +687,7 @@
let minute = (remaining_seconds / SECONDS_PER_MINUTE) % MINUTES_PER_HOUR;
let second = remaining_seconds % SECONDS_PER_MINUTE;

let year = match year >= i32::min_value() as i64 && year <= i32::max_value() as i64 {
let year = match year >= i32::MIN as i64 && year <= i32::MAX as i64 {
true => year as i32,
false => return Err(Error::OutOfRange("i64 is out of range for i32")),
};
Expand Down
14 changes: 7 additions & 7 deletions src/offset/local/tz_info/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl<'a> TimeZoneRef<'a> {

/// Convert Unix leap time to Unix time, from the list of leap seconds in a time zone
fn unix_leap_time_to_unix_time(&self, unix_leap_time: i64) -> Result<i64, Error> {
if unix_leap_time == i64::min_value() {
if unix_leap_time == i64::MIN {
return Err(Error::OutOfRange("out of range operation"));
}

Expand Down Expand Up @@ -572,7 +572,7 @@ pub(crate) struct LocalTimeType {
impl LocalTimeType {
/// Construct a local time type
pub(super) fn new(ut_offset: i32, is_dst: bool, name: Option<&[u8]>) -> Result<Self, Error> {
if ut_offset == i32::min_value() {
if ut_offset == i32::MIN {
return Err(Error::LocalTimeType("invalid UTC offset"));
}

Expand All @@ -586,7 +586,7 @@ impl LocalTimeType {

/// Construct a local time type with the specified UTC offset in seconds
pub(super) const fn with_offset(ut_offset: i32) -> Result<Self, Error> {
if ut_offset == i32::min_value() {
if ut_offset == i32::MIN {
return Err(Error::LocalTimeType("invalid UTC offset"));
}

Expand Down Expand Up @@ -818,7 +818,7 @@ mod tests {
let time_zone_3 =
TimeZone::new(vec![Transition::new(0, 0)], utc_local_time_types.clone(), vec![], None)?;
let time_zone_4 = TimeZone::new(
vec![Transition::new(i32::min_value().into(), 0), Transition::new(0, 1)],
vec![Transition::new(i32::MIN.into(), 0), Transition::new(0, 1)],
vec![utc, cet],
Vec::new(),
Some(fixed_extra_rule),
Expand Down Expand Up @@ -926,21 +926,21 @@ mod tests {
#[test]
fn test_leap_seconds_overflow() -> Result<(), Error> {
let time_zone_err = TimeZone::new(
vec![Transition::new(i64::min_value(), 0)],
vec![Transition::new(i64::MIN, 0)],
vec![LocalTimeType::UTC],
vec![LeapSecond::new(0, 1)],
Some(TransitionRule::from(LocalTimeType::UTC)),
);
assert!(time_zone_err.is_err());

let time_zone = TimeZone::new(
vec![Transition::new(i64::max_value(), 0)],
vec![Transition::new(i64::MAX, 0)],
vec![LocalTimeType::UTC],
vec![LeapSecond::new(0, 1)],
None,
)?;
assert!(matches!(
time_zone.find_local_time_type(i64::max_value()),
time_zone.find_local_time_type(i64::MAX),
Err(Error::FindLocalTimeType(_))
));

Expand Down
4 changes: 2 additions & 2 deletions src/offset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,9 @@ mod tests {

#[test]
fn test_nanos_never_panics() {
Utc.timestamp_nanos(i64::max_value());
Utc.timestamp_nanos(i64::MAX);
Utc.timestamp_nanos(i64::default());
Utc.timestamp_nanos(i64::min_value());
Utc.timestamp_nanos(i64::MIN);
}

#[test]
Expand Down
10 changes: 9 additions & 1 deletion src/time_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

//! Temporal quantification

use core::fmt;
use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};
use core::time::Duration;
use core::{fmt, i64};
#[cfg(feature = "std")]
use std::error::Error;

Expand Down Expand Up @@ -417,12 +417,14 @@ impl TimeDelta {
}

/// The minimum possible `TimeDelta`: `-i64::MAX` milliseconds.
#[deprecated(since = "0.4.39", note = "Use `TimeDelta::MIN` instead")]
#[inline]
pub const fn min_value() -> TimeDelta {
MIN
}

/// The maximum possible `TimeDelta`: `i64::MAX` milliseconds.
#[deprecated(since = "0.4.39", note = "Use `TimeDelta::MAX` instead")]
#[inline]
pub const fn max_value() -> TimeDelta {
MAX
Expand Down Expand Up @@ -474,6 +476,12 @@ impl TimeDelta {
};
TimeDelta { secs: -self.secs - secs_diff, nanos }
}

/// The minimum possible `TimeDelta`: `-i64::MAX` milliseconds.
pub const MIN: Self = MIN;

/// The maximum possible `TimeDelta`: `i64::MAX` milliseconds.
pub const MAX: Self = MAX;
}

impl Neg for TimeDelta {
Expand Down
5 changes: 4 additions & 1 deletion tests/dateutils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg(all(unix, feature = "clock", feature = "std"))]

use chrono::{Datelike, Days, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Timelike};
use std::{path, process, thread};

#[cfg(target_os = "linux")]
use chrono::Days;
use chrono::{Datelike, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Timelike};

fn verify_against_date_command_local(path: &'static str, dt: NaiveDateTime) {
let output = process::Command::new(path)
.arg("-d")
Expand Down
Loading