From b8d09a7bccbd3ea300fe30bf12b5f0a11ba1d539 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Thu, 21 Mar 2024 21:06:37 -0400 Subject: [PATCH] Address nightly lints This includes `impl Default for Parsed`. --- tests/error.rs | 6 +++--- tests/serde/macros.rs | 1 + time-macros/src/format_description/ast.rs | 1 - time-macros/src/format_description/format_item.rs | 1 - time-macros/src/format_description/lexer.rs | 2 +- time-macros/src/format_description/mod.rs | 6 ++---- time-macros/src/lib.rs | 2 +- time/src/date.rs | 12 +++++++----- time/src/format_description/parse/lexer.rs | 2 +- time/src/formatting/formattable.rs | 2 ++ time/src/lib.rs | 5 ++++- time/src/offset_date_time.rs | 10 ++++------ time/src/parsing/parsable.rs | 2 +- time/src/parsing/parsed.rs | 6 ++++++ time/src/primitive_date_time.rs | 2 ++ time/src/serde/mod.rs | 2 ++ time/src/tests.rs | 1 + time/src/time.rs | 9 ++++----- time/src/utc_offset.rs | 2 ++ 19 files changed, 44 insertions(+), 30 deletions(-) diff --git a/tests/error.rs b/tests/error.rs index 1a3a5a741..244aba31c 100644 --- a/tests/error.rs +++ b/tests/error.rs @@ -36,7 +36,7 @@ fn component_range() -> ComponentRange { fn insufficient_type_information() -> Format { Time::MIDNIGHT - .format(&time::format_description::well_known::Rfc3339) + .format(&format_description::well_known::Rfc3339) .expect_err("missing date and UTC offset") } @@ -176,7 +176,7 @@ fn conversion() { assert!(ComponentRange::try_from(TryFromParsed::ComponentRange(component_range())).is_ok()); assert!(TryFromParsed::try_from(Error::from(TryFromParsed::InsufficientInformation)).is_ok()); assert!(TryFromParsed::try_from(Parse::from(TryFromParsed::InsufficientInformation)).is_ok()); - assert!(std::io::Error::try_from(Format::from(io_error())).is_ok()); + assert!(io::Error::try_from(Format::from(io_error())).is_ok()); assert!(ComponentRange::try_from(Error::from(IndeterminateOffset)).is_err()); assert!(ConversionRange::try_from(Error::from(IndeterminateOffset)).is_err()); @@ -190,5 +190,5 @@ fn conversion() { assert!(ComponentRange::try_from(TryFromParsed::InsufficientInformation).is_err()); assert!(TryFromParsed::try_from(Error::from(IndeterminateOffset)).is_err()); assert!(TryFromParsed::try_from(unexpected_trailing_characters()).is_err()); - assert!(std::io::Error::try_from(insufficient_type_information()).is_err()); + assert!(io::Error::try_from(insufficient_type_information()).is_err()); } diff --git a/tests/serde/macros.rs b/tests/serde/macros.rs index 3b38e5894..66037b7e7 100644 --- a/tests/serde/macros.rs +++ b/tests/serde/macros.rs @@ -10,6 +10,7 @@ use time::macros::{date, datetime, offset, time}; use time::{serde, Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset}; // Not used in the tests, but ensures that the macro compiles. +#[allow(dead_code)] const ISO_FORMAT: Iso8601<{ iso8601::Config::DEFAULT.encode() }> = Iso8601::<{ iso8601::Config::DEFAULT.encode() }>; time::serde::format_description!(my_format, OffsetDateTime, ISO_FORMAT); diff --git a/time-macros/src/format_description/ast.rs b/time-macros/src/format_description/ast.rs index b75056bc2..4c3a19e5a 100644 --- a/time-macros/src/format_description/ast.rs +++ b/time-macros/src/format_description/ast.rs @@ -1,4 +1,3 @@ -use std::boxed::Box; use std::iter; use super::{lexer, unused, Error, Location, Spanned, SpannedValue, Unused}; diff --git a/time-macros/src/format_description/format_item.rs b/time-macros/src/format_description/format_item.rs index 711686683..b5c6d05ff 100644 --- a/time-macros/src/format_description/format_item.rs +++ b/time-macros/src/format_description/format_item.rs @@ -1,4 +1,3 @@ -use std::boxed::Box; use std::num::NonZeroU16; use std::str::{self, FromStr}; diff --git a/time-macros/src/format_description/lexer.rs b/time-macros/src/format_description/lexer.rs index 2c927cb94..2ea53af57 100644 --- a/time-macros/src/format_description/lexer.rs +++ b/time-macros/src/format_description/lexer.rs @@ -3,7 +3,7 @@ use core::iter; use super::{Error, Location, Spanned, SpannedValue}; pub(super) struct Lexed { - iter: core::iter::Peekable, + iter: iter::Peekable, } impl Iterator for Lexed { diff --git a/time-macros/src/format_description/mod.rs b/time-macros/src/format_description/mod.rs index fde1272f6..676028dec 100644 --- a/time-macros/src/format_description/mod.rs +++ b/time-macros/src/format_description/mod.rs @@ -1,7 +1,5 @@ //! Parser for format descriptions. -use std::vec::Vec; - macro_rules! version { ($range:expr) => { $range.contains(&VERSION) @@ -17,7 +15,7 @@ pub(crate) fn parse_with_version( version: Option, s: &[u8], proc_span: proc_macro::Span, -) -> Result, crate::Error> { +) -> Result, crate::Error> { match version { Some(crate::FormatDescriptionVersion::V1) | None => parse::<1>(s, proc_span), Some(crate::FormatDescriptionVersion::V2) => parse::<2>(s, proc_span), @@ -27,7 +25,7 @@ pub(crate) fn parse_with_version( fn parse( s: &[u8], proc_span: proc_macro::Span, -) -> Result, crate::Error> { +) -> Result, crate::Error> { let mut lexed = lexer::lex::(s, proc_span); let ast = ast::parse::<_, VERSION>(&mut lexed); let format_items = format_item::parse(ast); diff --git a/time-macros/src/lib.rs b/time-macros/src/lib.rs index d9e46931b..04f6a7583 100644 --- a/time-macros/src/lib.rs +++ b/time-macros/src/lib.rs @@ -68,7 +68,7 @@ enum FormatDescriptionVersion { #[cfg(any(feature = "formatting", feature = "parsing"))] enum VersionOrModuleName { Version(FormatDescriptionVersion), - #[cfg_attr(not(feature = "serde"), allow(unused_tuple_struct_fields))] + #[cfg_attr(not(feature = "serde"), allow(dead_code))] ModuleName(Ident), } diff --git a/time/src/date.rs b/time/src/date.rs index 71dfc32a0..ed443c5fd 100644 --- a/time/src/date.rs +++ b/time/src/date.rs @@ -1,5 +1,7 @@ //! The [`Date`] struct and its associated `impl`s. +#[cfg(feature = "formatting")] +use alloc::string::String; use core::num::NonZeroI32; use core::ops::{Add, Sub}; use core::time::Duration as StdDuration; @@ -120,7 +122,7 @@ impl Date { 1..=28 => {} 29..=31 if day <= days_in_year_month(year, month) => {} _ => { - return Err(crate::error::ComponentRange { + return Err(error::ComponentRange { name: "day", minimum: 1, maximum: days_in_year_month(year, month) as _, @@ -158,7 +160,7 @@ impl Date { 1..=365 => {} 366 if is_leap_year(year) => {} _ => { - return Err(crate::error::ComponentRange { + return Err(error::ComponentRange { name: "ordinal", minimum: 1, maximum: days_in_year(year) as _, @@ -195,7 +197,7 @@ impl Date { 1..=52 => {} 53 if week <= weeks_in_year(year) => {} _ => { - return Err(crate::error::ComponentRange { + return Err(error::ComponentRange { name: "week", minimum: 1, maximum: weeks_in_year(year) as _, @@ -1132,7 +1134,7 @@ impl Date { 1..=28 => {} 29..=31 if day <= days_in_year_month(self.year(), self.month()) => {} _ => { - return Err(crate::error::ComponentRange { + return Err(error::ComponentRange { name: "day", minimum: 1, maximum: days_in_year_month(self.year(), self.month()) as _, @@ -1165,7 +1167,7 @@ impl Date { 1..=365 => {} 366 if is_leap_year(self.year()) => {} _ => { - return Err(crate::error::ComponentRange { + return Err(error::ComponentRange { name: "ordinal", minimum: 1, maximum: days_in_year(self.year()) as _, diff --git a/time/src/format_description/parse/lexer.rs b/time/src/format_description/parse/lexer.rs index 1604fd497..2979fff9e 100644 --- a/time/src/format_description/parse/lexer.rs +++ b/time/src/format_description/parse/lexer.rs @@ -7,7 +7,7 @@ use super::{unused, Error, Location, Spanned, SpannedValue}; /// An iterator over the lexed tokens. pub(super) struct Lexed { /// The internal iterator. - iter: core::iter::Peekable, + iter: iter::Peekable, } impl Iterator for Lexed { diff --git a/time/src/formatting/formattable.rs b/time/src/formatting/formattable.rs index 769b827fd..7256a8acd 100644 --- a/time/src/formatting/formattable.rs +++ b/time/src/formatting/formattable.rs @@ -1,5 +1,7 @@ //! A trait that can be used to format an item from its components. +use alloc::string::String; +use alloc::vec::Vec; use core::ops::Deref; use std::io; diff --git a/time/src/lib.rs b/time/src/lib.rs index e2ef68b92..511df04de 100644 --- a/time/src/lib.rs +++ b/time/src/lib.rs @@ -68,7 +68,7 @@ #![doc(html_playground_url = "https://play.rust-lang.org")] #![cfg_attr(__time_03_docs, feature(doc_auto_cfg, doc_notable_trait))] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![doc(html_favicon_url = "https://avatars0.githubusercontent.com/u/55999857")] #![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/55999857")] #![doc(test(attr(deny(warnings))))] @@ -77,6 +77,9 @@ #[cfg(feature = "alloc")] extern crate alloc; +#[cfg(feature = "std")] +extern crate std; + mod date; mod duration; pub mod error; diff --git a/time/src/offset_date_time.rs b/time/src/offset_date_time.rs index 750a3c633..52f179985 100644 --- a/time/src/offset_date_time.rs +++ b/time/src/offset_date_time.rs @@ -1,8 +1,8 @@ //! The [`OffsetDateTime`] struct and its associated `impl`s. +#[cfg(feature = "formatting")] +use alloc::string::String; use core::cmp::Ordering; -#[cfg(feature = "std")] -use core::convert::From; use core::fmt; use core::hash::Hash; use core::ops::{Add, AddAssign, Sub, SubAssign}; @@ -26,9 +26,7 @@ use crate::internal_macros::{ }; #[cfg(feature = "parsing")] use crate::parsing::Parsable; -#[cfg(feature = "parsing")] -use crate::util; -use crate::{error, Date, Duration, Month, PrimitiveDateTime, Time, UtcOffset, Weekday}; +use crate::{error, util, Date, Duration, Month, PrimitiveDateTime, Time, UtcOffset, Weekday}; /// The Julian day of the Unix epoch. // Safety: `ordinal` is not zero. @@ -271,7 +269,7 @@ impl OffsetDateTime { cascade!(ordinal => year); debug_assert!(ordinal > 0); - debug_assert!(ordinal <= crate::util::days_in_year(year) as i16); + debug_assert!(ordinal <= util::days_in_year(year) as i16); ( year, diff --git a/time/src/parsing/parsable.rs b/time/src/parsing/parsable.rs index 1b7043899..a86259316 100644 --- a/time/src/parsing/parsable.rs +++ b/time/src/parsing/parsable.rs @@ -34,7 +34,7 @@ impl Parsable for T where T::Target: Parsable {} mod sealed { #[allow(clippy::wildcard_imports)] use super::*; - use crate::{OffsetDateTime, PrimitiveDateTime}; + use crate::PrimitiveDateTime; /// Parse the item using a format description and an input. pub trait Sealed { diff --git a/time/src/parsing/parsed.rs b/time/src/parsing/parsed.rs index e6451c197..94fc1225d 100644 --- a/time/src/parsing/parsed.rs +++ b/time/src/parsing/parsed.rs @@ -177,6 +177,12 @@ pub struct Parsed { pub(super) leap_second_allowed: bool, } +impl Default for Parsed { + fn default() -> Self { + Self::new() + } +} + impl Parsed { /// Create a new instance of `Parsed` with no information known. pub const fn new() -> Self { diff --git a/time/src/primitive_date_time.rs b/time/src/primitive_date_time.rs index 74eff7a51..85ae075e8 100644 --- a/time/src/primitive_date_time.rs +++ b/time/src/primitive_date_time.rs @@ -1,5 +1,7 @@ //! The [`PrimitiveDateTime`] struct and its associated `impl`s. +#[cfg(feature = "formatting")] +use alloc::string::String; use core::fmt; use core::ops::{Add, AddAssign, Sub, SubAssign}; use core::time::Duration as StdDuration; diff --git a/time/src/serde/mod.rs b/time/src/serde/mod.rs index baffb4e50..1468e2191 100644 --- a/time/src/serde/mod.rs +++ b/time/src/serde/mod.rs @@ -22,6 +22,8 @@ pub mod rfc3339; pub mod timestamp; mod visitor; +#[cfg(feature = "serde-human-readable")] +use alloc::string::ToString; use core::marker::PhantomData; #[cfg(feature = "serde-human-readable")] diff --git a/time/src/tests.rs b/time/src/tests.rs index 2f9dbfe56..4ccd87b18 100644 --- a/time/src/tests.rs +++ b/time/src/tests.rs @@ -25,6 +25,7 @@ //! This module should only be used when it is not possible to test the implementation in a //! reasonable manner externally. +use std::format; use std::num::NonZeroU8; use crate::ext::DigitCount; diff --git a/time/src/time.rs b/time/src/time.rs index 6b6e3186f..2bd2fefe8 100644 --- a/time/src/time.rs +++ b/time/src/time.rs @@ -1,5 +1,7 @@ //! The [`Time`] struct and its associated `impl`s. +#[cfg(feature = "formatting")] +use alloc::string::String; use core::fmt; use core::ops::{Add, Sub}; use core::time::Duration as StdDuration; @@ -718,7 +720,7 @@ impl Time { self, output: &mut impl io::Write, format: &(impl Formattable + ?Sized), - ) -> Result { + ) -> Result { format.format_into(output, None, Some(self), None) } @@ -731,10 +733,7 @@ impl Time { /// assert_eq!(time!(12:00).format(&format)?, "12:00:00"); /// # Ok::<_, time::Error>(()) /// ``` - pub fn format( - self, - format: &(impl Formattable + ?Sized), - ) -> Result { + pub fn format(self, format: &(impl Formattable + ?Sized)) -> Result { format.format(None, Some(self), None) } } diff --git a/time/src/utc_offset.rs b/time/src/utc_offset.rs index b43ca78f6..7cf24d141 100644 --- a/time/src/utc_offset.rs +++ b/time/src/utc_offset.rs @@ -1,5 +1,7 @@ //! The [`UtcOffset`] struct and its associated `impl`s. +#[cfg(feature = "formatting")] +use alloc::string::String; use core::fmt; use core::ops::Neg; #[cfg(feature = "formatting")]