Skip to content

Commit

Permalink
Support core::error in Rust 1.81
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Sep 23, 2024
1 parent ff76054 commit 493bd0e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
10 changes: 5 additions & 5 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ stable_no_std_test_task:
- cargo build --no-default-features --target thumbv6m-none-eabi
before_cache_script: rm -rf $CARGO_HOME/registry/index

nightly_no_std_test_task:
name: "Rust Nightly (no_std)"
rust_1_81_no_std_test_task:
name: "Rust 1.81 (no_std)"
container:
image: rustlang/rust:nightly
image: rust:latest
cpu: 1
memory: 2Gi
cargo_cache:
folder: $CARGO_HOME/registry
fingerprint_script: cat Cargo.toml
setup_script:
- rustup target add thumbv6m-none-eabi --toolchain nightly
- rustup target add thumbv6m-none-eabi
core_error_test_script:
- rustc --version
- cargo +nightly build --no-default-features --features=unstable-core-error --target thumbv6m-none-eabi
- cargo build --no-default-features --features=rust_1_81 --target thumbv6m-none-eabi
before_cache_script: rm -rf $CARGO_HOME/registry/index

nightly_test_task:
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ rust_1_61 = ["snafu-derive/rust_1_61"]
# `Backtrace` was stabilized
rust_1_65 = ["rust_1_61"]

# `core::error` was stabilized
rust_1_81 = ["rust_1_65"]

# The backtrace type becomes `backtrace::Backtrace`
backtraces-impl-backtrace-crate = ["backtrace"]

Expand Down
17 changes: 17 additions & 0 deletions src/guide/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ the standard library is available and no other backtrace provider is
selected.

[`Backtrace`]: std::backtrace::Backtrace

## `rust_1_81`

<dl class="snafu-ff-meta">
<dt>Default</dt>
<dd>disabled</dd>
<dt>Implies</dt>
<dd>

[`rust_1_65`](#rust_1_65)

</dd>
</dl>

When enabled, SNAFU will assume that it's safe to target features
available in Rust 1.81. Notably, the [`core::error::Error`][] trait is
used instead of [`std::error::Error`][].
28 changes: 22 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,25 +338,41 @@ generate_guide! {
}
}

#[cfg(feature = "unstable-core-error")]
#[cfg(any(feature = "rust_1_81", feature = "unstable-core-error"))]
#[doc(hidden)]
pub use core::error;

#[cfg(feature = "unstable-core-error")]
#[cfg(any(feature = "rust_1_81", feature = "unstable-core-error"))]
#[doc(hidden)]
pub use core::error::Error;

#[cfg(all(not(feature = "unstable-core-error"), any(feature = "std", test)))]
#[cfg(all(
not(any(feature = "rust_1_81", feature = "unstable-core-error")),
any(feature = "std", test)
))]
#[doc(hidden)]
pub use std::error;

#[cfg(all(not(feature = "unstable-core-error"), any(feature = "std", test)))]
#[cfg(all(
not(any(feature = "rust_1_81", feature = "unstable-core-error")),
any(feature = "std", test)
))]
#[doc(hidden)]
pub use std::error::Error;

#[cfg(not(any(feature = "unstable-core-error", feature = "std", test)))]
#[cfg(not(any(
feature = "rust_1_81",
feature = "unstable-core-error",
feature = "std",
test
)))]
mod no_std_error;
#[cfg(not(any(feature = "unstable-core-error", feature = "std", test)))]
#[cfg(not(any(
feature = "rust_1_81",
feature = "unstable-core-error",
feature = "std",
test
)))]
#[doc(hidden)]
pub use no_std_error::Error;

Expand Down

0 comments on commit 493bd0e

Please sign in to comment.