Skip to content

Commit

Permalink
io: always impl Error for Errno in rustc 1.81+
Browse files Browse the repository at this point in the history
In rust 1.81 the feature [`error_in_core`] was stabilized. This makes
the `Error` trait available in `core::error` instead of `std::error`, so
it can be used in a no-std context, too.

[`error_in_core`]: <rust-lang/rust#103765>
  • Loading branch information
Kijewski committed Dec 16, 2024
1 parent 737e1fb commit 2845287
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ check-cfg = [
'cfg(core_intrinsics)',
'cfg(criterion)',
'cfg(document_experimental_runtime_api)',
'cfg(error_in_core)',
'cfg(fix_y2038)',
'cfg(freebsdlike)',
'cfg(libc)',
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn main() {
use_feature_or_nothing("core_ffi_c");
use_feature_or_nothing("alloc_c_string");
use_feature_or_nothing("alloc_ffi");
use_feature_or_nothing("error_in_core");
}

// Feature needed for testing.
Expand Down
4 changes: 3 additions & 1 deletion src/io/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::backend;
use core::{fmt, result};
#[cfg(feature = "std")]
use std::error;
#[cfg(all(not(feature = "std"), error_in_core))]
use core::error;

/// A specialized [`Result`] type for `rustix` APIs.
pub type Result<T> = result::Result<T, Errno>;
Expand Down Expand Up @@ -49,7 +51,7 @@ impl fmt::Debug for Errno {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", error_in_core))]
impl error::Error for Errno {}

#[cfg(feature = "std")]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#![cfg_attr(all(wasi_ext, target_os = "wasi", feature = "std"), feature(wasi_ext))]
#![cfg_attr(core_ffi_c, feature(core_ffi_c))]
#![cfg_attr(core_c_str, feature(core_c_str))]
#![cfg_attr(error_in_core, feature(error_in_core))]
#![cfg_attr(all(feature = "alloc", alloc_c_string), feature(alloc_c_string))]
#![cfg_attr(all(feature = "alloc", alloc_ffi), feature(alloc_ffi))]
#![cfg_attr(not(feature = "std"), no_std)]
Expand Down

0 comments on commit 2845287

Please sign in to comment.