Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply clippy suggestions from Rust 1.79
Browse files Browse the repository at this point in the history
djc committed Jul 8, 2024

Verified

This commit was signed with the committer’s verified signature.
djc Dirkjan Ochtman
1 parent 51c2d4b commit e1cb2b6
Showing 6 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
@@ -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};
6 changes: 3 additions & 3 deletions src/offset/local/tz_info/rule.rs
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ impl AlternateTime {
};

// 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"));
}

@@ -233,7 +233,7 @@ impl AlternateTime {
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) {
return Err(Error::OutOfRange("out of range date time"));
}

@@ -687,7 +687,7 @@ impl UtcDateTime {
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")),
};
14 changes: 7 additions & 7 deletions src/offset/local/tz_info/timezone.rs
Original file line number Diff line number Diff line change
@@ -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"));
}

@@ -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"));
}

@@ -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"));
}

@@ -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),
@@ -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(_))
));

4 changes: 2 additions & 2 deletions src/offset/mod.rs
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion src/time_delta.rs
Original file line number Diff line number Diff line change
@@ -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;

2 changes: 1 addition & 1 deletion tests/dateutils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(all(unix, feature = "clock", feature = "std"))]

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

fn verify_against_date_command_local(path: &'static str, dt: NaiveDateTime) {

0 comments on commit e1cb2b6

Please sign in to comment.