Repository: bytecodealliance/rustix (language: rust)

Issue:
`rustix::io::Errno` should impl `core::error::Error` with rust 1.81+, regardless of `cfg(std)`
Presently, `rustix::io::Errno` conditionally impl's `std::error::Error` when the `std` feature is enabled.  The `Error` trait is available in `core` since Rust 1.81 (per <https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html>); please make an impl of `core::error::Error` unconditionally available when sufficiently new rustc is in use.


Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index c93f7ea52..115357ddd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -259,6 +259,7 @@ check-cfg = [
     'cfg(core_intrinsics)',
     'cfg(criterion)',
     'cfg(document_experimental_runtime_api)',
+    'cfg(error_in_core)',
     'cfg(fix_y2038)',
     'cfg(freebsdlike)',
     'cfg(libc)',
diff --git a/build.rs b/build.rs
index 5b92f070b..68831c351 100644
--- a/build.rs
+++ b/build.rs
@@ -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.
diff --git a/src/io/errno.rs b/src/io/errno.rs
index 2cfaef70d..7d3eadf7e 100644
--- a/src/io/errno.rs
+++ b/src/io/errno.rs
@@ -5,6 +5,8 @@
 //! want unrecognized values to create undefined behavior.
 
 use crate::backend;
+#[cfg(all(not(feature = "std"), error_in_core))]
+use core::error;
 use core::{fmt, result};
 #[cfg(feature = "std")]
 use std::error;
@@ -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")]
diff --git a/src/lib.rs b/src/lib.rs
index 786f9c1d9..1e62091c3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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)]


Test patch: