From bf0bc2d833f29659b1a0a29a2b412608f3a61e51 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Mon, 28 Aug 2023 23:48:08 -0400 Subject: [PATCH] Address lints --- tests/derives.rs | 3 +- tests/ext.rs | 52 +++++++++---------- tests/formatting.rs | 2 +- time-macros/src/quote.rs | 2 - time/src/error/mod.rs | 11 +++- time/src/error/parse.rs | 4 +- time/src/error/parse_from_description.rs | 1 + .../format_description/well_known/iso8601.rs | 6 +-- time/src/formatting/formattable.rs | 4 +- time/src/month.rs | 13 ++++- time/src/serde/visitor.rs | 6 +-- time/src/weekday.rs | 14 ++--- 12 files changed, 69 insertions(+), 49 deletions(-) diff --git a/tests/derives.rs b/tests/derives.rs index 26d273c388..c87d14356d 100644 --- a/tests/derives.rs +++ b/tests/derives.rs @@ -40,6 +40,7 @@ fn clone() { assert_cloned_eq!(ConversionRange); assert_cloned_eq!(invalid_format_description()); assert_cloned_eq!(TryFromParsed::InsufficientInformation); + #[allow(clippy::clone_on_copy)] // needed for coverage let _ = Parsed::new().clone(); assert_cloned_eq!(error::Parse::ParseFromDescription( error::ParseFromDescription::InvalidComponent("foo") @@ -128,7 +129,7 @@ fn ord() { fn debug() { macro_rules! debug_all { ($($x:expr;)*) => {$( - let _ = format!("{:?}", $x); + let _unused = format!("{:?}", $x); )*}; } diff --git a/tests/ext.rs b/tests/ext.rs index 0e3b16a6c2..e01ea68909 100644 --- a/tests/ext.rs +++ b/tests/ext.rs @@ -58,44 +58,44 @@ mod numerical_duration { } mod numerical_std_duration { - use std::time::Duration; + use std::time::Duration as StdDuration; use time::ext::NumericalStdDuration; #[test] fn unsigned() { - assert_eq!(5.std_nanoseconds(), Duration::from_nanos(5)); - assert_eq!(5.std_microseconds(), Duration::from_micros(5)); - assert_eq!(5.std_milliseconds(), Duration::from_millis(5)); - assert_eq!(5.std_seconds(), Duration::from_secs(5)); - assert_eq!(5.std_minutes(), Duration::from_secs(5 * 60)); - assert_eq!(5.std_hours(), Duration::from_secs(5 * 3_600)); - assert_eq!(5.std_days(), Duration::from_secs(5 * 86_400)); - assert_eq!(5.std_weeks(), Duration::from_secs(5 * 604_800)); + assert_eq!(5.std_nanoseconds(), StdDuration::from_nanos(5)); + assert_eq!(5.std_microseconds(), StdDuration::from_micros(5)); + assert_eq!(5.std_milliseconds(), StdDuration::from_millis(5)); + assert_eq!(5.std_seconds(), StdDuration::from_secs(5)); + assert_eq!(5.std_minutes(), StdDuration::from_secs(5 * 60)); + assert_eq!(5.std_hours(), StdDuration::from_secs(5 * 3_600)); + assert_eq!(5.std_days(), StdDuration::from_secs(5 * 86_400)); + assert_eq!(5.std_weeks(), StdDuration::from_secs(5 * 604_800)); } #[test] fn float() { // Ensure values truncate rather than round. - assert_eq!(1.9.std_nanoseconds(), Duration::from_nanos(1)); + assert_eq!(1.9.std_nanoseconds(), StdDuration::from_nanos(1)); - assert_eq!(1.0.std_nanoseconds(), Duration::from_nanos(1)); - assert_eq!(1.0.std_microseconds(), Duration::from_micros(1)); - assert_eq!(1.0.std_milliseconds(), Duration::from_millis(1)); - assert_eq!(1.0.std_seconds(), Duration::from_secs(1)); - assert_eq!(1.0.std_minutes(), Duration::from_secs(60)); - assert_eq!(1.0.std_hours(), Duration::from_secs(3_600)); - assert_eq!(1.0.std_days(), Duration::from_secs(86_400)); - assert_eq!(1.0.std_weeks(), Duration::from_secs(604_800)); + assert_eq!(1.0.std_nanoseconds(), StdDuration::from_nanos(1)); + assert_eq!(1.0.std_microseconds(), StdDuration::from_micros(1)); + assert_eq!(1.0.std_milliseconds(), StdDuration::from_millis(1)); + assert_eq!(1.0.std_seconds(), StdDuration::from_secs(1)); + assert_eq!(1.0.std_minutes(), StdDuration::from_secs(60)); + assert_eq!(1.0.std_hours(), StdDuration::from_secs(3_600)); + assert_eq!(1.0.std_days(), StdDuration::from_secs(86_400)); + assert_eq!(1.0.std_weeks(), StdDuration::from_secs(604_800)); - assert_eq!(1.5.std_nanoseconds(), Duration::from_nanos(1)); - assert_eq!(1.5.std_microseconds(), Duration::from_nanos(1_500)); - assert_eq!(1.5.std_milliseconds(), Duration::from_micros(1_500)); - assert_eq!(1.5.std_seconds(), Duration::from_millis(1_500)); - assert_eq!(1.5.std_minutes(), Duration::from_secs(90)); - assert_eq!(1.5.std_hours(), Duration::from_secs(90 * 60)); - assert_eq!(1.5.std_days(), Duration::from_secs(36 * 3_600)); - assert_eq!(1.5.std_weeks(), Duration::from_secs(252 * 3_600)); + assert_eq!(1.5.std_nanoseconds(), StdDuration::from_nanos(1)); + assert_eq!(1.5.std_microseconds(), StdDuration::from_nanos(1_500)); + assert_eq!(1.5.std_milliseconds(), StdDuration::from_micros(1_500)); + assert_eq!(1.5.std_seconds(), StdDuration::from_millis(1_500)); + assert_eq!(1.5.std_minutes(), StdDuration::from_secs(90)); + assert_eq!(1.5.std_hours(), StdDuration::from_secs(90 * 60)); + assert_eq!(1.5.std_days(), StdDuration::from_secs(36 * 3_600)); + assert_eq!(1.5.std_weeks(), StdDuration::from_secs(252 * 3_600)); } #[test] diff --git a/tests/formatting.rs b/tests/formatting.rs index 0b0bcffa14..e625caceb9 100644 --- a/tests/formatting.rs +++ b/tests/formatting.rs @@ -111,7 +111,7 @@ fn iso_8601() -> time::Result<()> { assert!( std::panic::catch_unwind(|| { - let _ = datetime!(2021-01-02 03:04:05 UTC).format(&Iso8601::PARSING); + let _unused = datetime!(2021-01-02 03:04:05 UTC).format(&Iso8601::PARSING); }) .is_err() ); diff --git a/time-macros/src/quote.rs b/time-macros/src/quote.rs index 4d3dcbca03..2c96807f9d 100644 --- a/time-macros/src/quote.rs +++ b/time-macros/src/quote.rs @@ -51,14 +51,12 @@ macro_rules! quote_inner { // Single or double symbols ($ts:ident :: $($tail:tt)*) => { sym!($ts ':' ':'); quote_inner!($ts $($tail)*); }; - ($ts:ident .. $($tail:tt)*) => { sym!($ts '.' '.'); quote_inner!($ts $($tail)*); }; ($ts:ident : $($tail:tt)*) => { sym!($ts ':'); quote_inner!($ts $($tail)*); }; ($ts:ident = $($tail:tt)*) => { sym!($ts '='); quote_inner!($ts $($tail)*); }; ($ts:ident ; $($tail:tt)*) => { sym!($ts ';'); quote_inner!($ts $($tail)*); }; ($ts:ident , $($tail:tt)*) => { sym!($ts ','); quote_inner!($ts $($tail)*); }; ($ts:ident . $($tail:tt)*) => { sym!($ts '.'); quote_inner!($ts $($tail)*); }; ($ts:ident & $($tail:tt)*) => { sym!($ts '&'); quote_inner!($ts $($tail)*); }; - ($ts:ident << $($tail:tt)*) => { sym!($ts '<' '<'); quote_inner!($ts $($tail)*); }; ($ts:ident < $($tail:tt)*) => { sym!($ts '<'); quote_inner!($ts $($tail)*); }; ($ts:ident >> $($tail:tt)*) => { sym!($ts '>' '>'); quote_inner!($ts $($tail)*); }; ($ts:ident > $($tail:tt)*) => { sym!($ts '>'); quote_inner!($ts $($tail)*); }; diff --git a/time/src/error/mod.rs b/time/src/error/mod.rs index 5f7c02a398..e53f82f75f 100644 --- a/time/src/error/mod.rs +++ b/time/src/error/mod.rs @@ -41,19 +41,24 @@ pub use try_from_parsed::TryFromParsed; /// This can be used when you either don't know or don't care about the exact error returned. /// `Result<_, time::Error>` (or its alias `time::Result<_>`) will work in these situations. #[allow(missing_copy_implementations, variant_size_differences)] -#[allow(clippy::missing_docs_in_private_items)] // variants only #[non_exhaustive] #[derive(Debug)] pub enum Error { + #[allow(missing_docs)] ConversionRange(ConversionRange), + #[allow(missing_docs)] ComponentRange(ComponentRange), #[cfg(feature = "local-offset")] + #[allow(missing_docs)] IndeterminateOffset(IndeterminateOffset), #[cfg(feature = "formatting")] + #[allow(missing_docs)] Format(Format), #[cfg(feature = "parsing")] + #[allow(missing_docs)] ParseFromDescription(ParseFromDescription), #[cfg(feature = "parsing")] + #[allow(missing_docs)] #[non_exhaustive] #[deprecated( since = "0.3.28", @@ -61,10 +66,14 @@ pub enum Error { )] UnexpectedTrailingCharacters, #[cfg(feature = "parsing")] + #[allow(missing_docs)] TryFromParsed(TryFromParsed), #[cfg(all(any(feature = "formatting", feature = "parsing"), feature = "alloc"))] + #[allow(missing_docs)] InvalidFormatDescription(InvalidFormatDescription), + #[allow(missing_docs)] DifferentVariant(DifferentVariant), + #[allow(missing_docs)] InvalidVariant(InvalidVariant), } diff --git a/time/src/error/parse.rs b/time/src/error/parse.rs index 1f30ea1f40..b91749b5e9 100644 --- a/time/src/error/parse.rs +++ b/time/src/error/parse.rs @@ -9,9 +9,9 @@ use crate::error::{self, ParseFromDescription, TryFromParsed}; #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Parse { - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] TryFromParsed(TryFromParsed), - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] ParseFromDescription(ParseFromDescription), /// The input should have ended, but there were characters remaining. #[non_exhaustive] diff --git a/time/src/error/parse_from_description.rs b/time/src/error/parse_from_description.rs index b5ec1f95f8..40124dce37 100644 --- a/time/src/error/parse_from_description.rs +++ b/time/src/error/parse_from_description.rs @@ -13,6 +13,7 @@ pub enum ParseFromDescription { InvalidLiteral, /// A dynamic component was not valid. InvalidComponent(&'static str), + /// The input was expected to have ended, but there are characters that remain. #[non_exhaustive] UnexpectedTrailingCharacters, } diff --git a/time/src/format_description/well_known/iso8601.rs b/time/src/format_description/well_known/iso8601.rs index 4d3d57bf3e..756f034efa 100644 --- a/time/src/format_description/well_known/iso8601.rs +++ b/time/src/format_description/well_known/iso8601.rs @@ -125,19 +125,19 @@ pub enum TimePrecision { /// Format the hour only. Minutes, seconds, and nanoseconds will be represented with the /// specified number of decimal digits, if any. Hour { - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] decimal_digits: Option, }, /// Format the hour and minute. Seconds and nanoseconds will be represented with the specified /// number of decimal digits, if any. Minute { - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] decimal_digits: Option, }, /// Format the hour, minute, and second. Nanoseconds will be represented with the specified /// number of decimal digits, if any. Second { - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] decimal_digits: Option, }, } diff --git a/time/src/formatting/formattable.rs b/time/src/formatting/formattable.rs index 2b4b350883..cad1d482dc 100644 --- a/time/src/formatting/formattable.rs +++ b/time/src/formatting/formattable.rs @@ -59,7 +59,7 @@ mod sealed { } // region: custom formats -impl<'a> sealed::Sealed for FormatItem<'a> { +impl sealed::Sealed for FormatItem<'_> { fn format_into( &self, output: &mut impl io::Write, @@ -80,7 +80,7 @@ impl<'a> sealed::Sealed for FormatItem<'a> { } } -impl<'a> sealed::Sealed for [FormatItem<'a>] { +impl sealed::Sealed for [FormatItem<'_>] { fn format_into( &self, output: &mut impl io::Write, diff --git a/time/src/month.rs b/time/src/month.rs index 8d8c164b21..ea3480f00a 100644 --- a/time/src/month.rs +++ b/time/src/month.rs @@ -8,21 +8,32 @@ use self::Month::*; use crate::error; /// Months of the year. -#[allow(clippy::missing_docs_in_private_items)] // variants #[repr(u8)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Month { + #[allow(missing_docs)] January = 1, + #[allow(missing_docs)] February = 2, + #[allow(missing_docs)] March = 3, + #[allow(missing_docs)] April = 4, + #[allow(missing_docs)] May = 5, + #[allow(missing_docs)] June = 6, + #[allow(missing_docs)] July = 7, + #[allow(missing_docs)] August = 8, + #[allow(missing_docs)] September = 9, + #[allow(missing_docs)] October = 10, + #[allow(missing_docs)] November = 11, + #[allow(missing_docs)] December = 12, } diff --git a/time/src/serde/visitor.rs b/time/src/serde/visitor.rs index fcf718bb45..3a4311ecb2 100644 --- a/time/src/serde/visitor.rs +++ b/time/src/serde/visitor.rs @@ -181,7 +181,7 @@ impl<'a> de::Visitor<'a> for Visitor { } } -impl<'a> de::Visitor<'a> for Visitor { +impl de::Visitor<'_> for Visitor { type Value = Weekday; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -218,7 +218,7 @@ impl<'a> de::Visitor<'a> for Visitor { } } -impl<'a> de::Visitor<'a> for Visitor { +impl de::Visitor<'_> for Visitor { type Value = Month; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -269,7 +269,7 @@ impl<'a> de::Visitor<'a> for Visitor { macro_rules! well_known { ($article:literal, $name:literal, $($ty:tt)+) => { #[cfg(feature = "parsing")] - impl<'a> de::Visitor<'a> for Visitor<$($ty)+> { + impl de::Visitor<'_> for Visitor<$($ty)+> { type Value = OffsetDateTime; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/time/src/weekday.rs b/time/src/weekday.rs index 761107e694..07642498d5 100644 --- a/time/src/weekday.rs +++ b/time/src/weekday.rs @@ -13,19 +13,19 @@ use crate::error; /// Friday), this type does not implement `PartialOrd` or `Ord`. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Weekday { - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] Monday, - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] Tuesday, - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] Wednesday, - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] Thursday, - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] Friday, - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] Saturday, - #[allow(clippy::missing_docs_in_private_items)] + #[allow(missing_docs)] Sunday, }