Migrate from failure to thiserror

The failure crate invents its own traits that don't use
std::error::Error (because failure predates certain features added to
Error); this prevents using ? on an error from failure in a function
using Error. The thiserror crate integrates with the standard Error
trait instead.
This commit is contained in:
Josh Triplett
2019-10-30 07:30:20 -07:00
committed by Dan Gohman
parent 6de45ff8fc
commit 7e725cf880
9 changed files with 37 additions and 53 deletions

View File

@@ -1,19 +1,19 @@
//! Result and error types representing the outcome of compiling a function.
use crate::verifier::VerifierErrors;
use failure_derive::Fail;
use thiserror::Error;
/// A compilation error.
///
/// When Cranelift fails to compile a function, it will return one of these error codes.
#[derive(Fail, Debug, PartialEq, Eq)]
#[derive(Error, Debug, PartialEq, Eq)]
pub enum CodegenError {
/// A list of IR verifier errors.
///
/// This always represents a bug, either in the code that generated IR for Cranelift, or a bug
/// in Cranelift itself.
#[fail(display = "Verifier errors:\n{}", _0)]
Verifier(#[cause] VerifierErrors),
#[error("Verifier errors")]
Verifier(#[from] VerifierErrors),
/// An implementation limit was exceeded.
///
@@ -21,22 +21,16 @@ pub enum CodegenError {
/// limits][limits] that cause compilation to fail when they are exceeded.
///
/// [limits]: https://cranelift.readthedocs.io/en/latest/ir.html#implementation-limits
#[fail(display = "Implementation limit exceeded")]
#[error("Implementation limit exceeded")]
ImplLimitExceeded,
/// The code size for the function is too large.
///
/// Different target ISAs may impose a limit on the size of a compiled function. If that limit
/// is exceeded, compilation fails.
#[fail(display = "Code for function is too large")]
#[error("Code for function is too large")]
CodeTooLarge,
}
/// A convenient alias for a `Result` that uses `CodegenError` as the error type.
pub type CodegenResult<T> = Result<T, CodegenError>;
impl From<VerifierErrors> for CodegenError {
fn from(e: VerifierErrors) -> Self {
Self::Verifier(e)
}
}