Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Change to use core::error::Error #706

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
msrv = "1.67"
msrv = "1.81"

missing-docs-in-crate-items = true
disallowed-macros = [
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
strategy:
matrix:
rust:
- { version: "1.67.0", name: MSRV }
- { version: "1.81.0", name: MSRV }
- { version: stable, name: stable }
kind:
- name: no_std
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
strategy:
matrix:
rust:
- { version: "1.67.0", name: MSRV }
- { version: "1.81.0", name: MSRV }
- { version: stable, name: stable }
os:
- { name: Ubuntu, value: ubuntu-latest }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/powerset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
strategy:
matrix:
rust:
- { version: "1.67.0", name: MSRV }
- { version: "1.81.0", name: MSRV }
- { version: stable, name: stable }
kind:
- name: no_std
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# time

[![minimum rustc: 1.67](https://img.shields.io/badge/minimum%20rustc-1.67-yellowgreen?logo=rust&style=flat-square)](https://www.whatrustisit.com)
[![minimum rustc: 1.81](https://img.shields.io/badge/minimum%20rustc-1.81-yellowgreen?logo=rust&style=flat-square)](https://www.whatrustisit.com)
[![version](https://img.shields.io/crates/v/time?color=blue&logo=rust&style=flat-square)](https://crates.io/crates/time)
[![build status](https://img.shields.io/github/actions/workflow/status/time-rs/time/build.yaml?branch=main&style=flat-square)](https://github.com/time-rs/time/actions)
[![codecov](https://codecov.io/gh/time-rs/time/branch/main/graph/badge.svg?token=yt4XSmQNKQ)](https://codecov.io/gh/time-rs/time)
Expand Down
2 changes: 1 addition & 1 deletion time-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "time-core"
version = "0.1.2"
authors = ["Jacob Pratt <[email protected]>", "Time contributors"]
edition = "2021"
rust-version = "1.67.0"
rust-version = "1.81.0"
repository = "https://github.com/time-rs/time"
keywords = ["date", "time", "calendar", "duration"]
categories = ["date-and-time"]
Expand Down
2 changes: 1 addition & 1 deletion time-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "time-macros"
version = "0.2.18"
authors = ["Jacob Pratt <[email protected]>", "Time contributors"]
edition = "2021"
rust-version = "1.67.0"
rust-version = "1.81.0"
repository = "https://github.com/time-rs/time"
keywords = ["date", "time", "calendar", "duration"]
categories = ["date-and-time"]
Expand Down
4 changes: 2 additions & 2 deletions time-macros/src/date.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::iter::Peekable;

use num_conv::Truncate;
use proc_macro::{token_stream, TokenTree};
use proc_macro::{TokenTree, token_stream};
use time_core::util::{days_in_year, weeks_in_year};

use crate::Error;
use crate::helpers::{
consume_any_ident, consume_number, consume_punct, days_in_year_month, ymd_to_yo, ywd_to_yo,
};
use crate::to_tokens::ToTokenTree;
use crate::Error;

#[cfg(feature = "large-dates")]
const MAX_YEAR: i32 = 999_999;
Expand Down
2 changes: 1 addition & 1 deletion time-macros/src/datetime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::iter::Peekable;

use proc_macro::{token_stream, Ident, Span, TokenTree};
use proc_macro::{Ident, Span, TokenTree, token_stream};

use crate::date::Date;
use crate::error::Error;
Expand Down
2 changes: 1 addition & 1 deletion time-macros/src/format_description/ast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::iter;

use super::{lexer, unused, Error, Location, Spanned, SpannedValue, Unused};
use super::{Error, Location, Spanned, SpannedValue, Unused, lexer, unused};

pub(super) enum Item<'a> {
Literal(Spanned<&'a [u8]>),
Expand Down
2 changes: 1 addition & 1 deletion time-macros/src/format_description/format_item.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::num::NonZeroU16;
use std::str::{self, FromStr};

use super::{ast, unused, Error, Span, Spanned, Unused};
use super::{Error, Span, Spanned, Unused, ast, unused};

pub(super) fn parse<'a>(
ast_items: impl Iterator<Item = Result<ast::Item<'a>, Error>>,
Expand Down
2 changes: 1 addition & 1 deletion time-macros/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::iter::Peekable;
use std::str::FromStr;

use num_conv::prelude::*;
use proc_macro::{token_stream, Span, TokenTree};
use proc_macro::{Span, TokenTree, token_stream};
use time_core::util::{days_in_year, is_leap_year};

use crate::Error;
Expand Down
4 changes: 2 additions & 2 deletions time-macros/src/offset.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::iter::Peekable;

use num_conv::prelude::*;
use proc_macro::{token_stream, Span, TokenTree};
use proc_macro::{Span, TokenTree, token_stream};
use time_core::convert::*;

use crate::Error;
use crate::helpers::{consume_any_ident, consume_number, consume_punct};
use crate::to_tokens::ToTokenTree;
use crate::Error;

pub(crate) struct Offset {
pub(crate) hours: i8,
Expand Down
4 changes: 2 additions & 2 deletions time-macros/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::iter::Peekable;

use proc_macro::{token_stream, Span, TokenTree};
use proc_macro::{Span, TokenTree, token_stream};
use time_core::convert::*;

use crate::Error;
use crate::helpers::{consume_any_ident, consume_number, consume_punct};
use crate::to_tokens::ToTokenTree;
use crate::Error;

enum Period {
Am,
Expand Down
2 changes: 1 addition & 1 deletion time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "time"
version = "0.3.36"
authors = ["Jacob Pratt <[email protected]>", "Time contributors"]
edition = "2021"
rust-version = "1.67.0"
rust-version = "1.81.0"
repository = "https://github.com/time-rs/time"
homepage = "https://time-rs.github.io"
keywords = ["date", "time", "calendar", "duration"]
Expand Down
20 changes: 8 additions & 12 deletions time/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::internal_macros::{
#[cfg(feature = "parsing")]
use crate::parsing::Parsable;
use crate::util::{days_in_year, days_in_year_month, is_leap_year, weeks_in_year};
use crate::{error, Duration, Month, PrimitiveDateTime, Time, Weekday};
use crate::{Duration, Month, PrimitiveDateTime, Time, Weekday, error};

type Year = RangedI32<MIN_YEAR, MAX_YEAR>;

Expand Down Expand Up @@ -1376,17 +1376,13 @@ impl SmartDisplay for Date {
day => width(2),
);

Metadata::new(
formatted_width,
self,
DateMetadata {
year_width,
display_sign,
year,
month: u8::from(month),
day,
},
)
Metadata::new(formatted_width, self, DateMetadata {
year_width,
display_sign,
year,
month: u8::from(month),
day,
})
}

fn fmt_with_metadata(
Expand Down
6 changes: 3 additions & 3 deletions time/src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use core::time::Duration as StdDuration;
use deranged::RangedI32;
use num_conv::prelude::*;

#[cfg(feature = "std")]
#[allow(deprecated)]
use crate::Instant;
use crate::convert::*;
use crate::error;
use crate::internal_macros::{
const_try_opt, expect_opt, impl_add_assign, impl_div_assign, impl_mul_assign, impl_sub_assign,
};
#[cfg(feature = "std")]
#[allow(deprecated)]
use crate::Instant;

/// By explicitly inserting this enum where padding is expected, the compiler is able to better
/// perform niche value optimization.
Expand Down
4 changes: 1 addition & 3 deletions time/src/error/component_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,4 @@ impl ComponentRange {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for ComponentRange {}
impl core::error::Error for ComponentRange {}
4 changes: 1 addition & 3 deletions time/src/error/conversion_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ impl fmt::Display for ConversionRange {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for ConversionRange {}
impl core::error::Error for ConversionRange {}

impl From<ConversionRange> for crate::Error {
fn from(err: ConversionRange) -> Self {
Expand Down
4 changes: 1 addition & 3 deletions time/src/error/different_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ impl fmt::Display for DifferentVariant {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for DifferentVariant {}
impl core::error::Error for DifferentVariant {}

impl From<DifferentVariant> for crate::Error {
fn from(err: DifferentVariant) -> Self {
Expand Down
6 changes: 2 additions & 4 deletions time/src/error/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ impl TryFrom<Format> for io::Error {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for Format {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for Format {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match *self {
Self::InsufficientTypeInformation | Self::InvalidComponent(_) => None,
Self::StdIo(ref err) => Some(err),
Expand Down
4 changes: 1 addition & 3 deletions time/src/error/indeterminate_offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ impl fmt::Display for IndeterminateOffset {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for IndeterminateOffset {}
impl core::error::Error for IndeterminateOffset {}

impl From<IndeterminateOffset> for crate::Error {
fn from(err: IndeterminateOffset) -> Self {
Expand Down
4 changes: 1 addition & 3 deletions time/src/error/invalid_format_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,4 @@ impl fmt::Display for InvalidFormatDescription {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for InvalidFormatDescription {}
impl core::error::Error for InvalidFormatDescription {}
4 changes: 1 addition & 3 deletions time/src/error/invalid_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ impl fmt::Display for InvalidVariant {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for InvalidVariant {}
impl core::error::Error for InvalidVariant {}

impl From<InvalidVariant> for crate::Error {
fn from(err: InvalidVariant) -> Self {
Expand Down
6 changes: 2 additions & 4 deletions time/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ impl fmt::Display for Error {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::ConversionRange(err) => Some(err),
Self::ComponentRange(err) => Some(err),
Expand Down
6 changes: 2 additions & 4 deletions time/src/error/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ impl fmt::Display for Parse {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for Parse {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for Parse {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::TryFromParsed(err) => Some(err),
Self::ParseFromDescription(err) => Some(err),
Expand Down
4 changes: 1 addition & 3 deletions time/src/error/parse_from_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl fmt::Display for ParseFromDescription {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for ParseFromDescription {}
impl core::error::Error for ParseFromDescription {}

impl From<ParseFromDescription> for crate::Error {
fn from(original: ParseFromDescription) -> Self {
Expand Down
6 changes: 2 additions & 4 deletions time/src/error/try_from_parsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ impl TryFrom<TryFromParsed> for error::ComponentRange {
}
}

#[cfg(feature = "std")]
#[allow(clippy::std_instead_of_core)]
impl std::error::Error for TryFromParsed {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for TryFromParsed {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::InsufficientInformation => None,
Self::ComponentRange(err) => Some(err),
Expand Down
2 changes: 1 addition & 1 deletion time/src/ext/numerical_duration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::convert::*;
use crate::Duration;
use crate::convert::*;

/// Sealed trait to prevent downstream implementations.
mod sealed {
Expand Down
2 changes: 1 addition & 1 deletion time/src/format_description/parse/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::iter;

use super::{lexer, unused, Error, Location, Spanned, SpannedValue, Unused};
use super::{Error, Location, Spanned, SpannedValue, Unused, lexer, unused};
use crate::internal_macros::bug;

/// One part of a complete format description.
Expand Down
2 changes: 1 addition & 1 deletion time/src/format_description/parse/format_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::string::String;
use core::num::NonZeroU16;
use core::str::{self, FromStr};

use super::{ast, unused, Error, Span, Spanned};
use super::{Error, Span, Spanned, ast, unused};
use crate::internal_macros::bug;

/// Parse an AST iterator into a sequence of format items.
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 @@ -2,7 +2,7 @@

use core::iter;

use super::{unused, Error, Location, Spanned, SpannedValue};
use super::{Error, Location, Spanned, SpannedValue, unused};

/// An iterator over the lexed tokens.
pub(super) struct Lexed<I: Iterator> {
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 @@ -11,9 +11,9 @@ use crate::format_description::well_known::iso8601::EncodedConfig;
use crate::format_description::well_known::{Iso8601, Rfc2822, Rfc3339};
use crate::format_description::{BorrowedFormatItem, OwnedFormatItem};
use crate::formatting::{
format_component, format_number_pad_zero, iso8601, write, MONTH_NAMES, WEEKDAY_NAMES,
MONTH_NAMES, WEEKDAY_NAMES, format_component, format_number_pad_zero, iso8601, write,
};
use crate::{error, Date, Time, UtcOffset};
use crate::{Date, Time, UtcOffset, error};

/// A type that describes a format.
///
Expand Down
4 changes: 2 additions & 2 deletions time/src/formatting/iso8601.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::io;
use num_conv::prelude::*;

use crate::convert::*;
use crate::format_description::well_known::Iso8601;
use crate::format_description::well_known::iso8601::{
DateKind, EncodedConfig, OffsetPrecision, TimePrecision,
};
use crate::format_description::well_known::Iso8601;
use crate::formatting::{format_float, format_number_pad_zero, write, write_if, write_if_else};
use crate::{error, Date, Time, UtcOffset};
use crate::{Date, Time, UtcOffset, error};

/// Format the date portion of ISO 8601.
pub(super) fn format_date<const CONFIG: EncodedConfig>(
Expand Down
4 changes: 2 additions & 2 deletions time/src/formatting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use num_conv::prelude::*;
pub use self::formattable::Formattable;
use crate::convert::*;
use crate::ext::DigitCount;
use crate::format_description::{modifier, Component};
use crate::{error, Date, OffsetDateTime, Time, UtcOffset};
use crate::format_description::{Component, modifier};
use crate::{Date, OffsetDateTime, Time, UtcOffset, error};

#[allow(clippy::missing_docs_in_private_items)]
const MONTH_NAMES: [&[u8]; 12] = [
Expand Down
Loading