Skip to content

Commit

Permalink
Address lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Aug 29, 2023
1 parent 79e4437 commit bf0bc2d
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 49 deletions.
3 changes: 2 additions & 1 deletion tests/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -128,7 +129,7 @@ fn ord() {
fn debug() {
macro_rules! debug_all {
($($x:expr;)*) => {$(
let _ = format!("{:?}", $x);
let _unused = format!("{:?}", $x);
)*};
}

Expand Down
52 changes: 26 additions & 26 deletions tests/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
2 changes: 0 additions & 2 deletions time-macros/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*); };
Expand Down
11 changes: 10 additions & 1 deletion time/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,39 @@ 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",
note = "no longer output. moved to the `ParseFromDescription` variant"
)]
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),
}

Expand Down
4 changes: 2 additions & 2 deletions time/src/error/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions time/src/error/parse_from_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
6 changes: 3 additions & 3 deletions time/src/format_description/well_known/iso8601.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NonZeroU8>,
},
/// 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<NonZeroU8>,
},
/// 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<NonZeroU8>,
},
}
Expand Down
4 changes: 2 additions & 2 deletions time/src/formatting/formattable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion time/src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
6 changes: 3 additions & 3 deletions time/src/serde/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<'a> de::Visitor<'a> for Visitor<UtcOffset> {
}
}

impl<'a> de::Visitor<'a> for Visitor<Weekday> {
impl de::Visitor<'_> for Visitor<Weekday> {
type Value = Weekday;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<'a> de::Visitor<'a> for Visitor<Weekday> {
}
}

impl<'a> de::Visitor<'a> for Visitor<Month> {
impl de::Visitor<'_> for Visitor<Month> {
type Value = Month;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<'a> de::Visitor<'a> for Visitor<Month> {
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 {
Expand Down
14 changes: 7 additions & 7 deletions time/src/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit bf0bc2d

Please sign in to comment.