Skip to content

Commit 2845287

Browse files
committed
io: always impl Error for Errno in rustc 1.81+
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>
1 parent 737e1fb commit 2845287

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ check-cfg = [
262262
'cfg(core_intrinsics)',
263263
'cfg(criterion)',
264264
'cfg(document_experimental_runtime_api)',
265+
'cfg(error_in_core)',
265266
'cfg(fix_y2038)',
266267
'cfg(freebsdlike)',
267268
'cfg(libc)',

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fn main() {
7171
use_feature_or_nothing("core_ffi_c");
7272
use_feature_or_nothing("alloc_c_string");
7373
use_feature_or_nothing("alloc_ffi");
74+
use_feature_or_nothing("error_in_core");
7475
}
7576

7677
// Feature needed for testing.

src/io/errno.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::backend;
88
use core::{fmt, result};
99
#[cfg(feature = "std")]
1010
use std::error;
11+
#[cfg(all(not(feature = "std"), error_in_core))]
12+
use core::error;
1113

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

52-
#[cfg(feature = "std")]
54+
#[cfg(any(feature = "std", error_in_core))]
5355
impl error::Error for Errno {}
5456

5557
#[cfg(feature = "std")]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#![cfg_attr(all(wasi_ext, target_os = "wasi", feature = "std"), feature(wasi_ext))]
109109
#![cfg_attr(core_ffi_c, feature(core_ffi_c))]
110110
#![cfg_attr(core_c_str, feature(core_c_str))]
111+
#![cfg_attr(error_in_core, feature(error_in_core))]
111112
#![cfg_attr(all(feature = "alloc", alloc_c_string), feature(alloc_c_string))]
112113
#![cfg_attr(all(feature = "alloc", alloc_ffi), feature(alloc_ffi))]
113114
#![cfg_attr(not(feature = "std"), no_std)]

0 commit comments

Comments
 (0)