diff --git a/lib/environ/src/lib.rs b/lib/environ/src/lib.rs index bd7d17c836..8a16bf0fa0 100644 --- a/lib/environ/src/lib.rs +++ b/lib/environ/src/lib.rs @@ -9,7 +9,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( feature = "cargo-clippy", - allow(new_without_default, new_without_default_derive) + allow(clippy::new_without_default, clippy::new_without_default_derive) )] #![cfg_attr( feature = "cargo-clippy", diff --git a/lib/execute/src/lib.rs b/lib/execute/src/lib.rs index 394aa02358..18bf5ff3b5 100644 --- a/lib/execute/src/lib.rs +++ b/lib/execute/src/lib.rs @@ -6,7 +6,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( feature = "cargo-clippy", - allow(new_without_default, new_without_default_derive) + allow(clippy::new_without_default, clippy::new_without_default_derive) )] #![cfg_attr( feature = "cargo-clippy", diff --git a/lib/execute/src/vmcontext.rs b/lib/execute/src/vmcontext.rs index ec985af9b5..ebe520d792 100644 --- a/lib/execute/src/vmcontext.rs +++ b/lib/execute/src/vmcontext.rs @@ -174,32 +174,32 @@ mod test_vmglobal_definition { } impl VMGlobalDefinition { - #[allow(cast_ptr_alignment)] + #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_i32(&mut self) -> &mut i32 { &mut *(self.storage.as_mut().as_mut_ptr() as *mut u8 as *mut i32) } - #[allow(cast_ptr_alignment)] + #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_i64(&mut self) -> &mut i64 { &mut *(self.storage.as_mut().as_mut_ptr() as *mut u8 as *mut i64) } - #[allow(cast_ptr_alignment)] + #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f32(&mut self) -> &mut f32 { &mut *(self.storage.as_mut().as_mut_ptr() as *mut u8 as *mut f32) } - #[allow(cast_ptr_alignment)] + #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f32_bits(&mut self) -> &mut u32 { &mut *(self.storage.as_mut().as_mut_ptr() as *mut u8 as *mut u32) } - #[allow(cast_ptr_alignment)] + #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f64(&mut self) -> &mut f64 { &mut *(self.storage.as_mut().as_mut_ptr() as *mut u8 as *mut f64) } - #[allow(cast_ptr_alignment)] + #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f64_bits(&mut self) -> &mut u64 { &mut *(self.storage.as_mut().as_mut_ptr() as *mut u8 as *mut u64) } @@ -578,7 +578,7 @@ impl VMContext { } /// Return a mutable reference to the associated `Instance`. - #[allow(cast_ptr_alignment)] + #[allow(clippy::cast_ptr_alignment)] pub unsafe fn instance(&mut self) -> &mut Instance { &mut *((self as *mut Self as *mut u8).offset(-Instance::vmctx_offset()) as *mut Instance) } diff --git a/lib/obj/src/lib.rs b/lib/obj/src/lib.rs index e06fb7a73a..012bf1cb00 100644 --- a/lib/obj/src/lib.rs +++ b/lib/obj/src/lib.rs @@ -10,7 +10,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( feature = "cargo-clippy", - allow(new_without_default, new_without_default_derive) + allow(clippy::new_without_default, clippy::new_without_default_derive) )] #![cfg_attr( feature = "cargo-clippy", diff --git a/lib/wast/src/lib.rs b/lib/wast/src/lib.rs index ca4d3d3c3a..1f8fc8f832 100644 --- a/lib/wast/src/lib.rs +++ b/lib/wast/src/lib.rs @@ -6,7 +6,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( feature = "cargo-clippy", - allow(new_without_default, new_without_default_derive) + allow(clippy::new_without_default, clippy::new_without_default_derive) )] #![cfg_attr( feature = "cargo-clippy", diff --git a/lib/wast/src/spectest.rs b/lib/wast/src/spectest.rs index 92d905fd74..dafec15b3b 100644 --- a/lib/wast/src/spectest.rs +++ b/lib/wast/src/spectest.rs @@ -6,29 +6,36 @@ use target_lexicon::HOST; use wasmtime_environ::{translate_signature, MemoryPlan, MemoryStyle, TablePlan, TableStyle}; use wasmtime_execute::{ExportValue, Resolver, VMGlobal, VMMemory, VMTable}; +#[allow(clippy::print_stdout)] extern "C" fn spectest_print() {} +#[allow(clippy::print_stdout)] extern "C" fn spectest_print_i32(x: i32) { println!("{}: i32", x); } +#[allow(clippy::print_stdout)] extern "C" fn spectest_print_i64(x: i64) { println!("{}: i64", x); } +#[allow(clippy::print_stdout)] extern "C" fn spectest_print_f32(x: f32) { println!("{}: f32", x); } +#[allow(clippy::print_stdout)] extern "C" fn spectest_print_f64(x: f64) { println!("{}: f64", x); } +#[allow(clippy::print_stdout)] extern "C" fn spectest_print_i32_f32(x: i32, y: f32) { println!("{}: i32", x); println!("{}: f32", y); } +#[allow(clippy::print_stdout)] extern "C" fn spectest_print_f64_f64(x: f64, y: f64) { println!("{}: f64", x); println!("{}: f64", y); diff --git a/lib/wast/src/wast.rs b/lib/wast/src/wast.rs index 067d0fc686..f77711e872 100644 --- a/lib/wast/src/wast.rs +++ b/lib/wast/src/wast.rs @@ -44,7 +44,11 @@ impl Instances { self.namespace.insert(name, world); } - pub fn perform_action(&mut self, isa: &isa::TargetIsa, action: Action) -> ActionOutcome { + pub fn perform_action( + &mut self, + isa: &isa::TargetIsa, + action: Action, + ) -> Result { match action { Action::Invoke { module, @@ -62,44 +66,50 @@ impl Instances { } match module { None => match self.current { - None => panic!("invoke performed with no module present"), + None => Err("invoke performed with no module present".to_string()), Some(ref mut instance_world) => instance_world .invoke(&mut self.code, isa, &field, &value_args) - .expect(&format!("error invoking {} in current module", field)), + .map_err(|e| { + format!("error invoking {} in current module: {}", field, e) + }), }, Some(name) => self .namespace .get_mut(&name) - .expect(&format!("module {} not declared", name)) + .ok_or_else(|| format!("module {} not declared", name))? .invoke(&mut self.code, isa, &field, &value_args) - .expect(&format!("error invoking {} in module {}", field, name)), + .map_err(|e| format!("error invoking {} in module {}: {}", field, name, e)), } } Action::Get { module, field } => { let value = match module { None => match self.current { - None => panic!("get performed with no module present"), - Some(ref mut instance_world) => instance_world - .get(&field) - .expect(&format!("error getting {} in current module", field)), + None => return Err("get performed with no module present".to_string()), + Some(ref mut instance_world) => { + instance_world.get(&field).map_err(|e| { + format!("error getting {} in current module: {}", field, e) + })? + } }, Some(name) => self .namespace .get_mut(&name) - .expect(&format!("module {} not declared", name)) + .ok_or_else(|| format!("module {} not declared", name))? .get(&field) - .expect(&format!("error getting {} in module {}", field, name)), + .map_err(|e| { + format!("error getting {} in module {}: {}", field, name, e) + })?, }; - ActionOutcome::Returned { + Ok(ActionOutcome::Returned { values: vec![value], - } + }) } } } } /// Run a wast script from a byte buffer. -pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) { +pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) -> Result<(), String> { let mut parser = ScriptParser::from_str(str::from_utf8(wast).unwrap()).unwrap(); let mut instances = Instances::new(); @@ -107,19 +117,19 @@ pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) { match kind { CommandKind::Module { module, name } => { if let Some(name) = name { - instances.define_named_module(&*isa, name, module.clone()); + instances.define_named_module(isa, name, module.clone()); } - instances.define_unnamed_module(&*isa, module) + instances.define_unnamed_module(isa, module) } - CommandKind::PerformAction(action) => match instances.perform_action(&*isa, action) { + CommandKind::PerformAction(action) => match instances.perform_action(isa, action)? { ActionOutcome::Returned { .. } => {} ActionOutcome::Trapped { message } => { panic!("{}:{}: a trap occurred: {}", name, line, message); } }, CommandKind::AssertReturn { action, expected } => { - match instances.perform_action(&*isa, action) { + match instances.perform_action(isa, action)? { ActionOutcome::Returned { values } => { for (v, e) in values.iter().zip(expected.iter()) { match *e { @@ -147,7 +157,7 @@ pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) { } } CommandKind::AssertTrap { action, message } => { - match instances.perform_action(&*isa, action) { + match instances.perform_action(isa, action)? { ActionOutcome::Returned { values } => panic!( "{}:{}: expected trap, but invoke returned with {:?}", name, line, values @@ -163,7 +173,7 @@ pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) { } } CommandKind::AssertExhaustion { action } => { - match instances.perform_action(&*isa, action) { + match instances.perform_action(isa, action)? { ActionOutcome::Returned { values } => panic!( "{}:{}: expected exhaustion, but invoke returned with {:?}", name, line, values @@ -177,7 +187,7 @@ pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) { } } CommandKind::AssertReturnCanonicalNan { action } => { - match instances.perform_action(&*isa, action) { + match instances.perform_action(isa, action)? { ActionOutcome::Returned { values } => { for v in values.iter() { match v { @@ -210,7 +220,7 @@ pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) { } } CommandKind::AssertReturnArithmeticNan { action } => { - match instances.perform_action(&*isa, action) { + match instances.perform_action(isa, action)? { ActionOutcome::Returned { values } => { for v in values.iter() { match v { @@ -247,13 +257,14 @@ pub fn wast_buffer(name: &str, isa: &isa::TargetIsa, wast: &[u8]) { } } } + + Ok(()) } /// Run a wast script from a file. pub fn wast_file(path: &Path, isa: &isa::TargetIsa) -> Result<(), String> { let wast = read_to_end(path).map_err(|e| e.to_string())?; - wast_buffer(&path.display().to_string(), isa, &wast); - Ok(()) + wast_buffer(&path.display().to_string(), isa, &wast) } fn read_to_end(path: &Path) -> Result, io::Error> { diff --git a/src/run_wast.rs b/src/run_wast.rs index 63520186b9..df4a971b0d 100644 --- a/src/run_wast.rs +++ b/src/run_wast.rs @@ -10,7 +10,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( feature = "cargo-clippy", - allow(new_without_default, new_without_default_derive) + allow(clippy::new_without_default, clippy::new_without_default_derive) )] #![cfg_attr( feature = "cargo-clippy", @@ -96,6 +96,7 @@ fn main() { let isa = isa_builder.finish(settings::Flags::new(flag_builder)); for filename in &args.arg_file { let path = Path::new(&filename); - wast_file(path, &*isa).expect(&format!("error reading file {}", path.display())); + wast_file(path, &*isa) + .unwrap_or_else(|e| panic!("error reading file {}: {}", path.display(), e)); } } diff --git a/src/wasm2obj.rs b/src/wasm2obj.rs index dab26c404a..70b6b15d1a 100644 --- a/src/wasm2obj.rs +++ b/src/wasm2obj.rs @@ -14,7 +14,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( feature = "cargo-clippy", - allow(new_without_default, new_without_default_derive) + allow(clippy::new_without_default, clippy::new_without_default_derive) )] #![cfg_attr( feature = "cargo-clippy", diff --git a/src/wasmtime.rs b/src/wasmtime.rs index b1c6d4ce1e..4c23f0a06f 100644 --- a/src/wasmtime.rs +++ b/src/wasmtime.rs @@ -15,7 +15,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( feature = "cargo-clippy", - allow(new_without_default, new_without_default_derive) + allow(clippy::new_without_default, clippy::new_without_default_derive) )] #![cfg_attr( feature = "cargo-clippy", @@ -128,7 +128,7 @@ fn main() { let isa = isa_builder.finish(settings::Flags::new(flag_builder)); for filename in &args.arg_file { let path = Path::new(&filename); - match handle_module(&args, path.to_path_buf(), &*isa) { + match handle_module(&args, path, &*isa) { Ok(()) => {} Err(message) => { let name = path.as_os_str().to_string_lossy(); @@ -139,8 +139,9 @@ fn main() { } } -fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), String> { - let mut data = read_to_end(path.clone()).map_err(|err| String::from(err.description()))?; +fn handle_module(args: &Args, path: &Path, isa: &TargetIsa) -> Result<(), String> { + let mut data = + read_to_end(path.to_path_buf()).map_err(|err| String::from(err.description()))?; // if data is using wat-format, first convert data to wasm if !data.starts_with(&[b'\0', b'a', b's', b'm']) { data = wabt::wat2wasm(data).map_err(|err| String::from(err.description()))?;