diff --git a/Cargo.toml b/Cargo.toml index 69975a5..4909141 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,4 @@ name = "elf" default = ["std", "to_str"] std = [] to_str = [] +nightly = [] diff --git a/src/lib.rs b/src/lib.rs index 01f9d3b..4afc12a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,6 +133,7 @@ //! ``` #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(all(feature = "nightly", not(feature = "std")), feature(error_in_core))] pub mod abi; diff --git a/src/parse.rs b/src/parse.rs index 77659c0..3df34da 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -78,12 +78,34 @@ impl std::error::Error for ParseError { ParseError::Utf8Error(ref err) => Some(err), ParseError::TryFromSliceError(ref err) => Some(err), ParseError::TryFromIntError(ref err) => Some(err), - #[cfg(feature = "std")] ParseError::IOError(ref err) => Some(err), } } } +#[cfg(all(feature = "nightly", not(feature = "std")))] +impl core::error::Error for ParseError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { + match *self { + ParseError::BadMagic(_) => None, + ParseError::UnsupportedElfClass(_) => None, + ParseError::UnsupportedElfEndianness(_) => None, + ParseError::UnsupportedVersion(_) => None, + ParseError::BadOffset(_) => None, + ParseError::StringTableMissingNul(_) => None, + ParseError::BadEntsize(_) => None, + ParseError::UnexpectedSectionType(_) => None, + ParseError::UnexpectedSegmentType(_) => None, + ParseError::UnexpectedAlignment(_) => None, + ParseError::SliceReadError(_) => None, + ParseError::IntegerOverflow => None, + ParseError::Utf8Error(ref err) => Some(err), + ParseError::TryFromSliceError(ref err) => Some(err), + ParseError::TryFromIntError(ref err) => Some(err), + } + } +} + impl core::fmt::Display for ParseError { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match *self {