Add and use a From impl from CodegenError to ModuleError

This will also improve reporting of the chain of errors.
This commit is contained in:
Josh Triplett
2019-10-30 08:02:16 -07:00
committed by Dan Gohman
parent 7e725cf880
commit d6b3ca28b4

View File

@@ -141,7 +141,7 @@ pub enum ModuleError {
InvalidImportDefinition(String),
/// Wraps a `cranelift-codegen` error
#[error("Compilation error: {0}")]
Compilation(CodegenError),
Compilation(#[from] CodegenError),
/// Wraps a generic error from a backend
#[error("Backend error: {0}")]
Backend(String),
@@ -549,9 +549,7 @@ where
func,
ctx.func.display(self.backend.isa())
);
let CodeInfo { total_size, .. } = ctx
.compile(self.backend.isa())
.map_err(ModuleError::Compilation)?;
let CodeInfo { total_size, .. } = ctx.compile(self.backend.isa())?;
let info = &self.contents.functions[func];
if info.compiled.is_some() {
return Err(ModuleError::DuplicateDefinition(info.decl.name.clone()));