mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 01:01:34 +00:00
Switch from failure
to anyhow
(#1851)
This commit switches all of `wasm-bindgen` from the `failure` crate to `anyhow`. The `anyhow` crate should serve all the purposes that we previously used `failure` for but has a few advantages: * It's based on the standard `Error` trait rather than a custom `Fail` trait, improving ecosystem compatibility. * We don't need a `#[derive(Fail)]`, which means that's less code to compile for `wasm-bindgen`. This notably helps the compile time of `web-sys` itself. * Using `Result<()>` in `fn main` with `anyhow::Error` produces human-readable output, so we can use that natively.
This commit is contained in:
@ -3,9 +3,9 @@ use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::mem;
|
||||
|
||||
use failure::{bail, format_err, Error};
|
||||
use anyhow::{anyhow, bail, Error};
|
||||
use walrus::ir::Value;
|
||||
use walrus::{DataId, FunctionId, InitExpr, ValType};
|
||||
use walrus::{DataId, FunctionId, InitExpr, InstrLocId, ValType};
|
||||
use walrus::{ExportItem, GlobalId, GlobalKind, ImportKind, MemoryId, Module};
|
||||
use wasm_bindgen_wasm_conventions as wasm_conventions;
|
||||
|
||||
@ -180,7 +180,7 @@ fn delete_synthetic_export(module: &mut Module, name: &str) -> Result<ExportItem
|
||||
.exports
|
||||
.iter()
|
||||
.find(|e| e.name == name)
|
||||
.ok_or_else(|| format_err!("failed to find `{}`", name))?;
|
||||
.ok_or_else(|| anyhow!("failed to find `{}`", name))?;
|
||||
let ret = item.item;
|
||||
let id = item.id();
|
||||
module.exports.delete(id);
|
||||
@ -452,7 +452,7 @@ fn find_wbindgen_malloc(module: &Module) -> Result<FunctionId, Error> {
|
||||
.exports
|
||||
.iter()
|
||||
.find(|e| e.name == "__wbindgen_malloc")
|
||||
.ok_or_else(|| format_err!("failed to find `__wbindgen_malloc`"))?;
|
||||
.ok_or_else(|| anyhow!("failed to find `__wbindgen_malloc`"))?;
|
||||
match e.item {
|
||||
walrus::ExportItem::Function(f) => Ok(f),
|
||||
_ => bail!("`__wbindgen_malloc` wasn't a funtion"),
|
||||
@ -515,7 +515,7 @@ fn implement_thread_intrinsics(module: &mut Module, globals: &Globals) -> Result
|
||||
});
|
||||
|
||||
impl VisitorMut for Visitor<'_> {
|
||||
fn visit_instr_mut(&mut self, instr: &mut Instr) {
|
||||
fn visit_instr_mut(&mut self, instr: &mut Instr, _loc: &mut InstrLocId) {
|
||||
let call = match instr {
|
||||
Instr::Call(e) => e,
|
||||
_ => return,
|
||||
|
Reference in New Issue
Block a user