Skip to content

Commit

Permalink
feat: Change to use core::error::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Sep 23, 2024
1 parent c8defc7 commit b82f843
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 29 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo test ${{ env.ALL_NON_EXCLUSIVE_FEATURES }} --color=always -- --color=always

# later this may be able to be included with the below
# kept separate for now as the following don't compile on 1.60
# * arbitrary (requires 1.63 as of v1.3.0)
rust_msrv:
strategy:
matrix:
Expand All @@ -34,19 +31,19 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.61.0"
toolchain: "1.81.0"
- uses: Swatinem/rust-cache@v2
# run --lib and --doc to avoid the long running integration tests
# which are run elsewhere
- run: |
cargo test --lib \
--features \
unstable-locales,wasmbind,oldtime,clock,winapi,serde \
unstable-locales,wasmbind,oldtime,clock,winapi,serde,arbitrary \
--color=always -- --color=always
- run: |
cargo test --doc \
--features \
unstable-locales,wasmbind,oldtime,clock,winapi,serde \
unstable-locales,wasmbind,oldtime,clock,winapi,serde,arbitrary \
--color=always -- --color=always
rust_versions:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "README.md"
license = "MIT OR Apache-2.0"
include = ["src/*", "tests/*.rs", "LICENSE.txt", "CITATION.cff"]
edition = "2021"
rust-version = "1.61.0"
rust-version = "1.81.0"

[lib]
name = "chrono"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Note: The `rkyv{,-16,-32,-64}` features are mutually exclusive.

## Rust version requirements

The Minimum Supported Rust Version (MSRV) is currently **Rust 1.61.0**.
The Minimum Supported Rust Version (MSRV) is currently **Rust 1.81.0**.

The MSRV is explicitly tested in CI. It may be bumped in minor releases, but this is not done
lightly.
Expand Down
4 changes: 1 addition & 3 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
#[cfg(all(feature = "alloc", not(feature = "std"), not(test)))]
use alloc::boxed::Box;
use core::error::Error;
use core::fmt;
use core::str::FromStr;
#[cfg(feature = "std")]
use std::error::Error;

use crate::{Month, ParseMonthError, ParseWeekdayError, Weekday};

Expand Down Expand Up @@ -448,7 +447,6 @@ impl fmt::Display for ParseError {
}
}

#[cfg(feature = "std")]
impl Error for ParseError {
#[allow(deprecated)]
fn description(&self) -> &str {
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
//!
//! ## Rust version requirements
//!
//! The Minimum Supported Rust Version (MSRV) is currently **Rust 1.61.0**.
//! The Minimum Supported Rust Version (MSRV) is currently **Rust 1.81.0**.
//!
//! The MSRV is explicitly tested in CI. It may be bumped in minor releases, but this is not done
//! lightly.
Expand Down Expand Up @@ -684,8 +684,7 @@ impl fmt::Debug for OutOfRange {
}
}

#[cfg(feature = "std")]
impl std::error::Error for OutOfRange {}
impl core::error::Error for OutOfRange {}

/// Workaround because `?` is not (yet) available in const context.
#[macro_export]
Expand Down
3 changes: 1 addition & 2 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ pub struct ParseMonthError {
pub(crate) _dummy: (),
}

#[cfg(feature = "std")]
impl std::error::Error for ParseMonthError {}
impl core::error::Error for ParseMonthError {}

impl fmt::Display for ParseMonthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
10 changes: 2 additions & 8 deletions src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ const fn span_for_digits(digits: u16) -> u32 {
/// will also fail if the `TimeDelta` is bigger than the timestamp, negative or zero.
pub trait DurationRound: Sized {
/// Error that can occur in rounding or truncating
#[cfg(feature = "std")]
type Err: std::error::Error;

/// Error that can occur in rounding or truncating
#[cfg(not(feature = "std"))]
type Err: fmt::Debug + fmt::Display;
type Err: core::error::Error;

/// Return a copy rounded by TimeDelta.
///
Expand Down Expand Up @@ -295,8 +290,7 @@ impl fmt::Display for RoundingError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for RoundingError {
impl core::error::Error for RoundingError {
#[allow(deprecated)]
fn description(&self) -> &str {
"error from rounding or truncating with DurationRound"
Expand Down
4 changes: 1 addition & 3 deletions src/time_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

//! Temporal quantification
use core::error::Error;
use core::fmt;
use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};
use core::time::Duration;
#[cfg(feature = "std")]
use std::error::Error;

use crate::{expect, try_opt};

Expand Down Expand Up @@ -607,7 +606,6 @@ impl fmt::Display for OutOfRangeError {
}
}

#[cfg(feature = "std")]
impl Error for OutOfRangeError {
#[allow(deprecated)]
fn description(&self) -> &str {
Expand Down
3 changes: 1 addition & 2 deletions src/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ pub struct ParseWeekdayError {
pub(crate) _dummy: (),
}

#[cfg(feature = "std")]
impl std::error::Error for ParseWeekdayError {}
impl core::error::Error for ParseWeekdayError {}

impl fmt::Display for ParseWeekdayError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down

0 comments on commit b82f843

Please sign in to comment.