diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index c2ca35591a..8c373d3ba3 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -1,3 +1,5 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + use super::DateTime; use crate::naive::{NaiveDate, NaiveTime}; #[cfg(feature = "clock")] @@ -6,68 +8,45 @@ use crate::offset::{FixedOffset, TimeZone, Utc}; use crate::oldtime::Duration; #[cfg(feature = "clock")] use crate::Datelike; -use std::time::{SystemTime, UNIX_EPOCH}; #[test] -#[allow(non_snake_case)] fn test_datetime_offset() { - let Est = FixedOffset::west(5 * 60 * 60); - let Edt = FixedOffset::west(4 * 60 * 60); - let Kst = FixedOffset::east(9 * 60 * 60); + let est = FixedOffset::west(5 * 60 * 60); + let edt = FixedOffset::west(4 * 60 * 60); + let kst = FixedOffset::east(9 * 60 * 60); assert_eq!(format!("{}", Utc.ymd(2014, 5, 6).and_hms(7, 8, 9)), "2014-05-06 07:08:09 UTC"); - assert_eq!( - format!("{}", Edt.ymd(2014, 5, 6).and_hms(7, 8, 9)), - "2014-05-06 07:08:09 -04:00" - ); - assert_eq!( - format!("{}", Kst.ymd(2014, 5, 6).and_hms(7, 8, 9)), - "2014-05-06 07:08:09 +09:00" - ); + assert_eq!(format!("{}", edt.ymd(2014, 5, 6).and_hms(7, 8, 9)), "2014-05-06 07:08:09 -04:00"); + assert_eq!(format!("{}", kst.ymd(2014, 5, 6).and_hms(7, 8, 9)), "2014-05-06 07:08:09 +09:00"); assert_eq!(format!("{:?}", Utc.ymd(2014, 5, 6).and_hms(7, 8, 9)), "2014-05-06T07:08:09Z"); - assert_eq!( - format!("{:?}", Edt.ymd(2014, 5, 6).and_hms(7, 8, 9)), - "2014-05-06T07:08:09-04:00" - ); - assert_eq!( - format!("{:?}", Kst.ymd(2014, 5, 6).and_hms(7, 8, 9)), - "2014-05-06T07:08:09+09:00" - ); + assert_eq!(format!("{:?}", edt.ymd(2014, 5, 6).and_hms(7, 8, 9)), "2014-05-06T07:08:09-04:00"); + assert_eq!(format!("{:?}", kst.ymd(2014, 5, 6).and_hms(7, 8, 9)), "2014-05-06T07:08:09+09:00"); // edge cases assert_eq!(format!("{:?}", Utc.ymd(2014, 5, 6).and_hms(0, 0, 0)), "2014-05-06T00:00:00Z"); + assert_eq!(format!("{:?}", edt.ymd(2014, 5, 6).and_hms(0, 0, 0)), "2014-05-06T00:00:00-04:00"); + assert_eq!(format!("{:?}", kst.ymd(2014, 5, 6).and_hms(0, 0, 0)), "2014-05-06T00:00:00+09:00"); + assert_eq!(format!("{:?}", Utc.ymd(2014, 5, 6).and_hms(23, 59, 59)), "2014-05-06T23:59:59Z"); assert_eq!( - format!("{:?}", Edt.ymd(2014, 5, 6).and_hms(0, 0, 0)), - "2014-05-06T00:00:00-04:00" - ); - assert_eq!( - format!("{:?}", Kst.ymd(2014, 5, 6).and_hms(0, 0, 0)), - "2014-05-06T00:00:00+09:00" - ); - assert_eq!( - format!("{:?}", Utc.ymd(2014, 5, 6).and_hms(23, 59, 59)), - "2014-05-06T23:59:59Z" - ); - assert_eq!( - format!("{:?}", Edt.ymd(2014, 5, 6).and_hms(23, 59, 59)), + format!("{:?}", edt.ymd(2014, 5, 6).and_hms(23, 59, 59)), "2014-05-06T23:59:59-04:00" ); assert_eq!( - format!("{:?}", Kst.ymd(2014, 5, 6).and_hms(23, 59, 59)), + format!("{:?}", kst.ymd(2014, 5, 6).and_hms(23, 59, 59)), "2014-05-06T23:59:59+09:00" ); let dt = Utc.ymd(2014, 5, 6).and_hms(7, 8, 9); - assert_eq!(dt, Edt.ymd(2014, 5, 6).and_hms(3, 8, 9)); + assert_eq!(dt, edt.ymd(2014, 5, 6).and_hms(3, 8, 9)); assert_eq!(dt + Duration::seconds(3600 + 60 + 1), Utc.ymd(2014, 5, 6).and_hms(8, 9, 10)); assert_eq!( - dt.signed_duration_since(Edt.ymd(2014, 5, 6).and_hms(10, 11, 12)), + dt.signed_duration_since(edt.ymd(2014, 5, 6).and_hms(10, 11, 12)), Duration::seconds(-7 * 3600 - 3 * 60 - 3) ); assert_eq!(*Utc.ymd(2014, 5, 6).and_hms(7, 8, 9).offset(), Utc); - assert_eq!(*Edt.ymd(2014, 5, 6).and_hms(7, 8, 9).offset(), Edt); - assert!(*Edt.ymd(2014, 5, 6).and_hms(7, 8, 9).offset() != Est); + assert_eq!(*edt.ymd(2014, 5, 6).and_hms(7, 8, 9).offset(), edt); + assert!(*edt.ymd(2014, 5, 6).and_hms(7, 8, 9).offset() != est); } #[test] @@ -107,31 +86,27 @@ fn test_datetime_with_timezone() { } #[test] -#[allow(non_snake_case)] fn test_datetime_rfc2822_and_rfc3339() { - let EDT = FixedOffset::east(5 * 60 * 60); + let edt = FixedOffset::east(5 * 60 * 60); assert_eq!( Utc.ymd(2015, 2, 18).and_hms(23, 16, 9).to_rfc2822(), "Wed, 18 Feb 2015 23:16:09 +0000" ); + assert_eq!(Utc.ymd(2015, 2, 18).and_hms(23, 16, 9).to_rfc3339(), "2015-02-18T23:16:09+00:00"); assert_eq!( - Utc.ymd(2015, 2, 18).and_hms(23, 16, 9).to_rfc3339(), - "2015-02-18T23:16:09+00:00" - ); - assert_eq!( - EDT.ymd(2015, 2, 18).and_hms_milli(23, 16, 9, 150).to_rfc2822(), + edt.ymd(2015, 2, 18).and_hms_milli(23, 16, 9, 150).to_rfc2822(), "Wed, 18 Feb 2015 23:16:09 +0500" ); assert_eq!( - EDT.ymd(2015, 2, 18).and_hms_milli(23, 16, 9, 150).to_rfc3339(), + edt.ymd(2015, 2, 18).and_hms_milli(23, 16, 9, 150).to_rfc3339(), "2015-02-18T23:16:09.150+05:00" ); assert_eq!( - EDT.ymd(2015, 2, 18).and_hms_micro(23, 59, 59, 1_234_567).to_rfc2822(), + edt.ymd(2015, 2, 18).and_hms_micro(23, 59, 59, 1_234_567).to_rfc2822(), "Wed, 18 Feb 2015 23:59:60 +0500" ); assert_eq!( - EDT.ymd(2015, 2, 18).and_hms_micro(23, 59, 59, 1_234_567).to_rfc3339(), + edt.ymd(2015, 2, 18).and_hms_micro(23, 59, 59, 1_234_567).to_rfc3339(), "2015-02-18T23:59:60.234567+05:00" ); @@ -149,11 +124,11 @@ fn test_datetime_rfc2822_and_rfc3339() { ); assert_eq!( DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:59:60 +0500"), - Ok(EDT.ymd(2015, 2, 18).and_hms_milli(23, 59, 59, 1_000)) + Ok(edt.ymd(2015, 2, 18).and_hms_milli(23, 59, 59, 1_000)) ); assert_eq!( DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00"), - Ok(EDT.ymd(2015, 2, 18).and_hms_micro(23, 59, 59, 1_234_567)) + Ok(edt.ymd(2015, 2, 18).and_hms_micro(23, 59, 59, 1_234_567)) ); } @@ -237,11 +212,8 @@ fn test_datetime_parse_from_str() { Ok(ymdhms(2014, 5, 7, 12, 34, 56, 570 * 60)) ); // ignore offset assert!(DateTime::parse_from_str("20140507000000", "%Y%m%d%H%M%S").is_err()); // no offset - assert!(DateTime::parse_from_str( - "Fri, 09 Aug 2013 23:54:35 GMT", - "%a, %d %b %Y %H:%M:%S GMT" - ) - .is_err()); + assert!(DateTime::parse_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT") + .is_err()); assert_eq!( Utc.datetime_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT"), Ok(Utc.ymd(2013, 8, 9).and_hms(23, 54, 35)) diff --git a/src/format/mod.rs b/src/format/mod.rs index 11611b98e1..5d720c0b57 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -33,8 +33,6 @@ //! # } //! ``` -#![allow(ellipsis_inclusive_range_patterns)] - #[cfg(feature = "alloc")] extern crate alloc; @@ -749,7 +747,7 @@ pub struct DelayedFormat { /// Locale used for text. // TODO: Only used with the locale feature. We should make this property // only present when the feature is enabled. - #[allow(dead_code)] + #[cfg(feature = "unstable-locales")] locale: Option, } @@ -757,7 +755,14 @@ pub struct DelayedFormat { impl<'a, I: Iterator + Clone, B: Borrow>> DelayedFormat { /// Makes a new `DelayedFormat` value out of local date and time. pub fn new(date: Option, time: Option, items: I) -> DelayedFormat { - DelayedFormat { date, time, off: None, items, locale: None } + DelayedFormat { + date, + time, + off: None, + items, + #[cfg(feature = "unstable-locales")] + locale: None, + } } /// Makes a new `DelayedFormat` value out of local date and time and UTC offset. @@ -771,7 +776,14 @@ impl<'a, I: Iterator + Clone, B: Borrow>> DelayedFormat { Off: Offset + fmt::Display, { let name_and_diff = (offset.to_string(), offset.fix()); - DelayedFormat { date, time, off: Some(name_and_diff), items, locale: None } + DelayedFormat { + date, + time, + off: Some(name_and_diff), + items, + #[cfg(feature = "unstable-locales")] + locale: None, + } } /// Makes a new `DelayedFormat` value out of local date and time and locale. diff --git a/src/format/parse.rs b/src/format/parse.rs index fdde32a297..e57fb8a9d2 100644 --- a/src/format/parse.rs +++ b/src/format/parse.rs @@ -117,10 +117,10 @@ fn parse_rfc2822<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult<(&'a st let mut year = try_consume!(scan::number(s, 2, usize::MAX)); let yearlen = prevlen - s.len(); match (yearlen, year) { - (2, 0...49) => { + (2, 0..=49) => { year += 2000; } // 47 -> 2047, 05 -> 2005 - (2, 50...99) => { + (2, 50..=99) => { year += 1900; } // 79 -> 1979 (3, _) => { diff --git a/src/format/parsed.rs b/src/format/parsed.rs index aed780a751..011ad889aa 100644 --- a/src/format/parsed.rs +++ b/src/format/parsed.rs @@ -22,7 +22,6 @@ use crate::{Datelike, Timelike}; /// /// - `to_*` methods try to make a concrete date and time value out of set fields. /// It fully checks any remaining out-of-range conditions and inconsistent/impossible fields. -#[allow(missing_copy_implementations)] #[derive(Clone, PartialEq, Debug, Default)] pub struct Parsed { /// Year. @@ -305,7 +304,7 @@ impl Parsed { // check if present quotient and/or modulo is consistent to the full year. // since the presence of those fields means a positive full year, // we should filter a negative full year first. - (Some(y), q, r @ Some(0...99)) | (Some(y), q, r @ None) => { + (Some(y), q, r @ Some(0..=99)) | (Some(y), q, r @ None) => { if y < 0 { return Err(OUT_OF_RANGE); } @@ -319,7 +318,7 @@ impl Parsed { // the full year is missing but we have quotient and modulo. // reconstruct the full year. make sure that the result is always positive. - (None, Some(q), Some(r @ 0...99)) => { + (None, Some(q), Some(r @ 0..=99)) => { if q < 0 { return Err(OUT_OF_RANGE); } @@ -329,7 +328,7 @@ impl Parsed { // we only have modulo. try to interpret a modulo as a conventional two-digit year. // note: we are affected by Rust issue #18060. avoid multiple range patterns. - (None, None, Some(r @ 0...99)) => Ok(Some(r + if r < 70 { 2000 } else { 1900 })), + (None, None, Some(r @ 0..=99)) => Ok(Some(r + if r < 70 { 2000 } else { 1900 })), // otherwise it is an out-of-bound or insufficient condition. (None, Some(_), None) => Err(NOT_ENOUGH), @@ -500,32 +499,32 @@ impl Parsed { /// It is able to handle leap seconds when given second is 60. pub fn to_naive_time(&self) -> ParseResult { let hour_div_12 = match self.hour_div_12 { - Some(v @ 0...1) => v, + Some(v @ 0..=1) => v, Some(_) => return Err(OUT_OF_RANGE), None => return Err(NOT_ENOUGH), }; let hour_mod_12 = match self.hour_mod_12 { - Some(v @ 0...11) => v, + Some(v @ 0..=11) => v, Some(_) => return Err(OUT_OF_RANGE), None => return Err(NOT_ENOUGH), }; let hour = hour_div_12 * 12 + hour_mod_12; let minute = match self.minute { - Some(v @ 0...59) => v, + Some(v @ 0..=59) => v, Some(_) => return Err(OUT_OF_RANGE), None => return Err(NOT_ENOUGH), }; // we allow omitting seconds or nanoseconds, but they should be in the range. let (second, mut nano) = match self.second.unwrap_or(0) { - v @ 0...59 => (v, 0), + v @ 0..=59 => (v, 0), 60 => (59, 1_000_000_000), _ => return Err(OUT_OF_RANGE), }; nano += match self.nanosecond { - Some(v @ 0...999_999_999) if self.second.is_some() => v, - Some(0...999_999_999) => return Err(NOT_ENOUGH), // second is missing + Some(v @ 0..=999_999_999) if self.second.is_some() => v, + Some(0..=999_999_999) => return Err(NOT_ENOUGH), // second is missing Some(_) => return Err(OUT_OF_RANGE), None => 0, }; diff --git a/src/format/scan.rs b/src/format/scan.rs index ffa213dd81..6969c81a1e 100644 --- a/src/format/scan.rs +++ b/src/format/scan.rs @@ -14,7 +14,7 @@ use crate::Weekday; /// Assumes that the `pattern` is already converted to lower case. fn equals(s: &str, pattern: &str) -> bool { let mut xs = s.as_bytes().iter().map(|&c| match c { - b'A'...b'Z' => c + 32, + b'A'..=b'Z' => c + 32, _ => c, }); let mut ys = pattern.as_bytes().iter().cloned(); @@ -240,7 +240,7 @@ where // hours (00--99) let hours = match digits(s)? { - (h1 @ b'0'...b'9', h2 @ b'0'...b'9') => i32::from((h1 - b'0') * 10 + (h2 - b'0')), + (h1 @ b'0'..=b'9', h2 @ b'0'..=b'9') => i32::from((h1 - b'0') * 10 + (h2 - b'0')), _ => return Err(INVALID), }; s = &s[2..]; @@ -252,8 +252,8 @@ where // if the next two items are digits then we have to add minutes let minutes = if let Ok(ds) = digits(s) { match ds { - (m1 @ b'0'...b'5', m2 @ b'0'...b'9') => i32::from((m1 - b'0') * 10 + (m2 - b'0')), - (b'6'...b'9', b'0'...b'9') => return Err(OUT_OF_RANGE), + (m1 @ b'0'..=b'5', m2 @ b'0'..=b'9') => i32::from((m1 - b'0') * 10 + (m2 - b'0')), + (b'6'..=b'9', b'0'..=b'9') => return Err(OUT_OF_RANGE), _ => return Err(INVALID), } } else if allow_missing_minutes { @@ -314,7 +314,7 @@ pub(super) fn timezone_offset_2822(s: &str) -> ParseResult<(&str, Option)> .as_bytes() .iter() .position(|&c| match c { - b'a'...b'z' | b'A'...b'Z' => false, + b'a'..=b'z' | b'A'..=b'Z' => false, _ => true, }) .unwrap_or(s.len()); diff --git a/src/lib.rs b/src/lib.rs index 62b997a951..80065c3051 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -424,8 +424,6 @@ #![deny(missing_debug_implementations)] #![warn(unreachable_pub)] #![deny(dead_code)] -// lints are added all the time, we test on 1.13 -#![allow(unknown_lints)] #![cfg_attr(not(any(feature = "std", test)), no_std)] #[cfg(feature = "oldtime")] diff --git a/src/naive/internals.rs b/src/naive/internals.rs index 1fa2045a85..43b769df39 100644 --- a/src/naive/internals.rs +++ b/src/naive/internals.rs @@ -13,7 +13,6 @@ //! but the conversion keeps the valid value valid and the invalid value invalid //! so that the user-facing `NaiveDate` can validate the input as late as possible. -#![allow(dead_code)] // some internal methods have been left for consistency #![cfg_attr(feature = "__internal_bench", allow(missing_docs))] use crate::Weekday; @@ -175,7 +174,6 @@ impl fmt::Debug for YearFlags { pub(super) const MIN_OL: u32 = 1 << 1; pub(super) const MAX_OL: u32 = 366 << 1; // larger than the non-leap last day `(365 << 1) | 1` -pub(super) const MIN_MDL: u32 = (1 << 6) | (1 << 1); pub(super) const MAX_MDL: u32 = (12 << 6) | (31 << 1) | 1; const XX: i8 = -128; @@ -321,12 +319,6 @@ impl Of { YearFlags((of & 0b1111) as u8) } - #[inline] - pub(super) fn with_flags(&self, YearFlags(flags): YearFlags) -> Of { - let Of(of) = *self; - Of((of & !0b1111) | u32::from(flags)) - } - #[inline] pub(super) fn weekday(&self) -> Weekday { let Of(of) = *self; @@ -416,7 +408,7 @@ impl Mdf { } } - #[inline] + #[cfg(test)] pub(super) fn valid(&self) -> bool { let Mdf(mdf) = *self; let mdl = mdf >> 3; @@ -452,12 +444,6 @@ impl Mdf { Mdf((mdf & !0b1_1111_0000) | (day << 4)) } - #[inline] - pub(super) fn flags(&self) -> YearFlags { - let Mdf(mdf) = *self; - YearFlags((mdf & 0b1111) as u8) - } - #[inline] pub(super) fn with_flags(&self, YearFlags(flags): YearFlags) -> Mdf { let Mdf(mdf) = *self;