Use try_from instead of the cast crate.

Now that `try_from` is in stable Rust, we can use it here.
This commit is contained in:
Dan Gohman
2019-05-31 09:51:11 -07:00
committed by Benjamin Bouvier
parent fbaffa2c04
commit da1baf7481
3 changed files with 4 additions and 4 deletions

View File

@@ -19,7 +19,6 @@ hashmap_core = { version = "0.1.9", optional = true }
failure = { version = "0.1.1", default-features = false, features = ["derive"] } failure = { version = "0.1.1", default-features = false, features = ["derive"] }
failure_derive = { version = "0.1.1", default-features = false } failure_derive = { version = "0.1.1", default-features = false }
log = { version = "0.4.6", default-features = false } log = { version = "0.4.6", default-features = false }
cast = { version = "0.2.2", default-features = false }
[dev-dependencies] [dev-dependencies]
wabt = "0.7.0" wabt = "0.7.0"

View File

@@ -11,7 +11,7 @@ use crate::translation_utils::{
DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table,
TableIndex, TableIndex,
}; };
use cast; use core::convert::TryFrom;
use cranelift_codegen::cursor::FuncCursor; use cranelift_codegen::cursor::FuncCursor;
use cranelift_codegen::ir::immediates::{Offset32, Uimm64}; use cranelift_codegen::ir::immediates::{Offset32, Uimm64};
use cranelift_codegen::ir::types::*; use cranelift_codegen::ir::types::*;
@@ -196,7 +196,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
index: GlobalIndex, index: GlobalIndex,
) -> WasmResult<GlobalVariable> { ) -> WasmResult<GlobalVariable> {
// Just create a dummy `vmctx` global. // Just create a dummy `vmctx` global.
let offset = cast::i32((index.index() * 8) + 8).unwrap().into(); let offset = i32::try_from((index.index() * 8) + 8).unwrap().into();
let vmctx = func.create_global_value(ir::GlobalValueData::VMContext {}); let vmctx = func.create_global_value(ir::GlobalValueData::VMContext {});
Ok(GlobalVariable::Memory { Ok(GlobalVariable::Memory {
gv: vmctx, gv: vmctx,

View File

@@ -12,6 +12,7 @@ use crate::translation_utils::{
type_to_type, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, SignatureIndex, type_to_type, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, SignatureIndex,
Table, TableElementType, TableIndex, Table, TableElementType, TableIndex,
}; };
use core::convert::TryFrom;
use cranelift_codegen::ir::{self, AbiParam, Signature}; use cranelift_codegen::ir::{self, AbiParam, Signature};
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use std::vec::Vec; use std::vec::Vec;
@@ -270,7 +271,7 @@ pub fn parse_element_section<'data>(
ref s => panic!("unsupported init expr in element section: {:?}", s), ref s => panic!("unsupported init expr in element section: {:?}", s),
}; };
let items_reader = items.get_items_reader()?; let items_reader = items.get_items_reader()?;
let mut elems = Vec::with_capacity(cast::usize(items_reader.get_count())); let mut elems = Vec::with_capacity(usize::try_from(items_reader.get_count()).unwrap());
for item in items_reader { for item in items_reader {
let x = item?; let x = item?;
elems.push(FuncIndex::from_u32(x)); elems.push(FuncIndex::from_u32(x));