diff --git a/Cargo.lock b/Cargo.lock index 614076c..71e7f6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "aho-corasick" version = "0.7.18" @@ -32,21 +17,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "backtrace" -version = "0.3.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -77,28 +47,6 @@ dependencies = [ "strsim", ] -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - [[package]] name = "fastrand" version = "1.7.0" @@ -108,12 +56,6 @@ dependencies = [ "instant", ] -[[package]] -name = "gimli" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" - [[package]] name = "hashbrown" version = "0.12.2" @@ -196,24 +138,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "miniz_oxide" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" -dependencies = [ - "adler", -] - -[[package]] -name = "object" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" -dependencies = [ - "memchr", -] - [[package]] name = "pest" version = "2.3.0" @@ -277,12 +201,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "rustc-demangle" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" - [[package]] name = "semver" version = "0.9.0" @@ -353,18 +271,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] - [[package]] name = "tempfile" version = "3.3.0" @@ -410,7 +316,6 @@ name = "ullage" version = "0.1.0" dependencies = [ "docopt", - "failure", "indexmap", "libc", "llvm-sys 100.2.3", @@ -426,12 +331,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" -[[package]] -name = "unicode-xid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 0141301..b199a02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,5 @@ llvm-13 = { package = "llvm-sys", version = "130", optional = true } docopt = "1.1" serde = { version = "1.0", features = ["derive"] } tempfile = "3.1" -failure = "0.1" libc = "0.2" indexmap = "1.5" diff --git a/src/compile/error.rs b/src/compile/error.rs index 1bd30cb..0497f6d 100644 --- a/src/compile/error.rs +++ b/src/compile/error.rs @@ -1,24 +1,40 @@ //! Compilation error module. Contains the Result and Error types for //! the compile module. -use failure::Fail; -use std::io; +use std::{fmt::Display, io}; /// Represents the different types of errors which can be encountered /// when compiling. -#[derive(Fail, Debug)] +#[derive(Debug)] pub enum CompError { /// Generic Error String - #[fail(display = "compilation error: {}", _0)] Generic(String), /// Linker Failure - #[fail(display = "linker failed: {}", _0)] - Linker(#[cause] LinkerError), + Linker(LinkerError), /// Wrapped IO Error - #[fail(display = "IO error: {}", _0)] - IO(#[cause] ::std::io::Error), + IO(io::Error), +} + +impl std::error::Error for CompError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + CompError::Linker(e) => Some(e), + CompError::IO(e) => Some(e), + _ => None, + } + } +} + +impl Display for CompError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + CompError::Generic(msg) => write!(f, "compilation error: {}", msg), + CompError::Linker(cause) => write!(f, "linker failed.: {}", cause), + CompError::IO(cause) => write!(f, "IO error: {}", cause), + } + } } /// Compilation result. Returned from each compilation stage. @@ -27,17 +43,28 @@ pub type CompResult = Result; /// Link Failure Type /// /// Used to group together the different failure modes for the linker. -#[derive(Fail, Debug)] +#[derive(Debug)] pub enum LinkerError { /// The linker failed with a known exit status - #[fail(display = "linker returned exit status {}: {}", _0, _1)] WithExitStatus(i32, String), /// The linker failed with an unknown exit status - #[fail(display = "unknown linker error: {}", _0)] UnknownFailure(String), } +impl std::error::Error for LinkerError {} + +impl Display for LinkerError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + LinkerError::WithExitStatus(status, msg) => { + write!(f, "linker returned exit status {}: {}", status, msg) + } + LinkerError::UnknownFailure(msg) => write!(f, "unknown linker error: {}", msg), + } + } +} + impl From for CompError { /// Convert untyped errors to generic compilation errors. fn from(s: String) -> Self { diff --git a/src/low_loader/targets.rs b/src/low_loader/targets.rs index fab3e8c..4a41f33 100644 --- a/src/low_loader/targets.rs +++ b/src/low_loader/targets.rs @@ -2,8 +2,8 @@ use super::llvm_sys::core::LLVMDisposeMessage; use super::llvm_sys::target_machine::*; -use failure::Fail; use std::ffi::{CStr, CString}; +use std::fmt::Display; use std::{fmt, ptr}; /// Compilation Target @@ -18,10 +18,17 @@ pub struct Target { /// Target Lookup Error /// /// Returned if a target couldn't be resolved from the given triple. -#[derive(Fail, Debug)] -#[fail(display = "Could not find target: '{}'", _0)] +#[derive(Debug)] pub struct TargetLookupError(String); +impl std::error::Error for TargetLookupError {} + +impl Display for TargetLookupError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Could not find target: '{}'", self.0) + } +} + impl fmt::Display for Target { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "Target information for {}:", self.triple)?;