Use try_from replacing cast in wasmtime-runtime.

This commit is contained in:
Ari Lotter
2019-06-09 04:50:45 -04:00
committed by Jakub Konka
parent f3f6ab0583
commit 8dc1d90352
4 changed files with 31 additions and 33 deletions

View File

@@ -2,9 +2,9 @@
//! signature checking.
use crate::vmcontext::VMSharedSignatureIndex;
use cast;
use cranelift_codegen::ir;
use std::collections::{hash_map, HashMap};
use std::convert::TryFrom;
/// WebAssembly requires that the caller and callee signatures in an indirect
/// call must match. To implement this efficiently, keep a registry of all
@@ -29,10 +29,7 @@ impl SignatureRegistry {
match self.signature_hash.entry(sig.clone()) {
hash_map::Entry::Occupied(entry) => *entry.get(),
hash_map::Entry::Vacant(entry) => {
#[cfg(target_pointer_width = "32")]
let sig_id = VMSharedSignatureIndex::new(cast::u32(len));
#[cfg(target_pointer_width = "64")]
let sig_id = VMSharedSignatureIndex::new(cast::u32(len).unwrap());
let sig_id = VMSharedSignatureIndex::new(u32::try_from(len).unwrap());
entry.insert(sig_id);
sig_id
}