Skip to content

Commit

Permalink
Merge pull request #463 from shepmaster/rust-1.81
Browse files Browse the repository at this point in the history
Support core::error in Rust 1.81
  • Loading branch information
shepmaster authored Sep 23, 2024
2 parents ff76054 + 695247b commit 6111b50
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 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
File renamed without changes.
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`][].
32 changes: 24 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,27 +338,43 @@ 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)))]
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
)))]
mod fallback_error;
#[cfg(not(any(
feature = "rust_1_81",
feature = "unstable-core-error",
feature = "std",
test
)))]
#[doc(hidden)]
pub use no_std_error::Error;
pub use fallback_error::Error;

/// Ensure a condition is true. If it is not, return from the function
/// with an error.
Expand Down

0 comments on commit 6111b50

Please sign in to comment.