Skip to content

Commit

Permalink
Address nightly lints
Browse files Browse the repository at this point in the history
This includes `impl Default for Parsed`.
  • Loading branch information
jhpratt committed Mar 23, 2024
1 parent 330865a commit b8d09a7
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 30 deletions.
6 changes: 3 additions & 3 deletions tests/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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());
Expand All @@ -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());
}
1 change: 1 addition & 0 deletions tests/serde/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion time-macros/src/format_description/ast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::boxed::Box;
use std::iter;

use super::{lexer, unused, Error, Location, Spanned, SpannedValue, Unused};
Expand Down
1 change: 0 additions & 1 deletion time-macros/src/format_description/format_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::boxed::Box;
use std::num::NonZeroU16;
use std::str::{self, FromStr};

Expand Down
2 changes: 1 addition & 1 deletion time-macros/src/format_description/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::iter;
use super::{Error, Location, Spanned, SpannedValue};

pub(super) struct Lexed<I: Iterator> {
iter: core::iter::Peekable<I>,
iter: iter::Peekable<I>,
}

impl<I: Iterator> Iterator for Lexed<I> {
Expand Down
6 changes: 2 additions & 4 deletions time-macros/src/format_description/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Parser for format descriptions.
use std::vec::Vec;

macro_rules! version {
($range:expr) => {
$range.contains(&VERSION)
Expand All @@ -17,7 +15,7 @@ pub(crate) fn parse_with_version(
version: Option<crate::FormatDescriptionVersion>,
s: &[u8],
proc_span: proc_macro::Span,
) -> Result<Vec<crate::format_description::public::OwnedFormatItem>, crate::Error> {
) -> Result<Vec<public::OwnedFormatItem>, crate::Error> {
match version {
Some(crate::FormatDescriptionVersion::V1) | None => parse::<1>(s, proc_span),
Some(crate::FormatDescriptionVersion::V2) => parse::<2>(s, proc_span),
Expand All @@ -27,7 +25,7 @@ pub(crate) fn parse_with_version(
fn parse<const VERSION: u8>(
s: &[u8],
proc_span: proc_macro::Span,
) -> Result<Vec<crate::format_description::public::OwnedFormatItem>, crate::Error> {
) -> Result<Vec<public::OwnedFormatItem>, crate::Error> {
let mut lexed = lexer::lex::<VERSION>(s, proc_span);
let ast = ast::parse::<_, VERSION>(&mut lexed);
let format_items = format_item::parse(ast);
Expand Down
2 changes: 1 addition & 1 deletion time-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
12 changes: 7 additions & 5 deletions time/src/date.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 _,
Expand Down Expand Up @@ -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 _,
Expand Down Expand Up @@ -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 _,
Expand Down Expand Up @@ -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 _,
Expand Down Expand Up @@ -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 _,
Expand Down
2 changes: 1 addition & 1 deletion time/src/format_description/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{unused, Error, Location, Spanned, SpannedValue};
/// An iterator over the lexed tokens.
pub(super) struct Lexed<I: Iterator> {
/// The internal iterator.
iter: core::iter::Peekable<I>,
iter: iter::Peekable<I>,
}

impl<I: Iterator> Iterator for Lexed<I> {
Expand Down
2 changes: 2 additions & 0 deletions time/src/formatting/formattable.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 4 additions & 1 deletion time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))]
Expand All @@ -77,6 +77,9 @@
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

mod date;
mod duration;
pub mod error;
Expand Down
10 changes: 4 additions & 6 deletions time/src/offset_date_time.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion time/src/parsing/parsable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<T: Deref> 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 {
Expand Down
6 changes: 6 additions & 0 deletions time/src/parsing/parsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions time/src/primitive_date_time.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions time/src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions time/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions time/src/time.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -718,7 +720,7 @@ impl Time {
self,
output: &mut impl io::Write,
format: &(impl Formattable + ?Sized),
) -> Result<usize, crate::error::Format> {
) -> Result<usize, error::Format> {
format.format_into(output, None, Some(self), None)
}

Expand All @@ -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<String, crate::error::Format> {
pub fn format(self, format: &(impl Formattable + ?Sized)) -> Result<String, error::Format> {
format.format(None, Some(self), None)
}
}
Expand Down
2 changes: 2 additions & 0 deletions time/src/utc_offset.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down

0 comments on commit b8d09a7

Please sign in to comment.