diff --git a/src/format/mod.rs b/src/format/mod.rs index 1cc5048c16..22b2723af4 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -519,7 +519,7 @@ fn format_inner<'a>( }; if let Some(v) = v { - if (spec == &Year || spec == &IsoYear) && !(0 <= v && v < 10_000) { + if (spec == &Year || spec == &IsoYear) && !(0..10_000).contains(&v) { // non-four-digit years require an explicit sign as per ISO 8601 match *pad { Pad::None => write!(result, "{:+}", v), diff --git a/src/format/parsed.rs b/src/format/parsed.rs index b8ed2d90f2..c919cb7995 100644 --- a/src/format/parsed.rs +++ b/src/format/parsed.rs @@ -261,7 +261,7 @@ impl Parsed { /// given hour number in 12-hour clocks. #[inline] pub fn set_hour12(&mut self, value: i64) -> ParseResult<()> { - if value < 1 || value > 12 { + if !(1..=12).contains(&value) { return Err(OUT_OF_RANGE); } set_if_consistent(&mut self.hour_mod_12, value as u32 % 12) diff --git a/src/format/scan.rs b/src/format/scan.rs index 0efb1ee3d1..632fd31126 100644 --- a/src/format/scan.rs +++ b/src/format/scan.rs @@ -48,7 +48,7 @@ pub fn number(s: &str, min: usize, max: usize) -> ParseResult<(&str, i64)> { let mut n = 0i64; for (i, c) in bytes.iter().take(max).cloned().enumerate() { // cloned() = copied() - if c < b'0' || b'9' < c { + if !(b'0'..=b'9').contains(&c) { if i < min { return Err(INVALID); } else { @@ -79,7 +79,7 @@ pub fn nanosecond(s: &str) -> ParseResult<(&str, i64)> { let v = v.checked_mul(SCALE[consumed]).ok_or(OUT_OF_RANGE)?; // if there are more than 9 digits, skip next digits. - let s = s.trim_left_matches(|c: char| '0' <= c && c <= '9'); + let s = s.trim_left_matches(|c: char| ('0'..='9').contains(&c)); Ok((s, v)) } diff --git a/src/naive/date.rs b/src/naive/date.rs index bfb94b497a..8887e9f1f8 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -1640,7 +1640,7 @@ impl fmt::Debug for NaiveDate { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let year = self.year(); let mdf = self.mdf(); - if 0 <= year && year <= 9999 { + if (0..=9999).contains(&year) { write!(f, "{:04}-{:02}-{:02}", year, mdf.month(), mdf.day()) } else { // ISO 8601 requires the explicit sign for out-of-range years diff --git a/src/naive/isoweek.rs b/src/naive/isoweek.rs index 7e34313bad..3de0b17c3d 100644 --- a/src/naive/isoweek.rs +++ b/src/naive/isoweek.rs @@ -131,7 +131,7 @@ impl fmt::Debug for IsoWeek { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let year = self.year(); let week = self.week(); - if 0 <= year && year <= 9999 { + if (0..=9999).contains(&year) { write!(f, "{:04}-W{:02}", year, week) } else { // ISO 8601 requires the explicit sign for out-of-range years diff --git a/src/naive/time.rs b/src/naive/time.rs index 4d2b5c2f51..8e0dc6fcd6 100644 --- a/src/naive/time.rs +++ b/src/naive/time.rs @@ -578,7 +578,7 @@ impl NaiveTime { secs += 1; } debug_assert!(-86_400 <= secs && secs < 2 * 86_400); - debug_assert!(0 <= frac && frac < 1_000_000_000); + debug_assert!((0..=1_000_000_000).contains(&frac)); if secs < 0 { secs += 86_400; @@ -587,7 +587,7 @@ impl NaiveTime { secs -= 86_400; morerhssecs += 86_400; } - debug_assert!(0 <= secs && secs < 86_400); + debug_assert!((0..=86_400).contains(&secs)); (NaiveTime { secs: secs as u32, frac: frac as u32 }, morerhssecs) }