From 94b180feb8c6d75b85badf333f9afbedd38ad46c Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 13 Nov 2021 03:49:19 -0800 Subject: [PATCH] Fix clippy lints --- src/frontend.rs | 24 +++++++++--------------- src/ir.rs | 4 ++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/frontend.rs b/src/frontend.rs index afa32d5..999a6b7 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -10,7 +10,7 @@ use wasmparser::{ ImportSectionEntryType, Operator, Parser, Payload, Type, TypeDef, TypeOrFuncType, }; -pub fn wasm_to_ir<'a>(bytes: &'a [u8]) -> Result> { +pub fn wasm_to_ir(bytes: &[u8]) -> Result> { let mut module = Module::default(); let parser = Parser::new(0); let mut next_func = 0; @@ -32,22 +32,16 @@ fn handle_payload<'a>( Payload::TypeSection(mut reader) => { for _ in 0..reader.get_count() { let ty = reader.read()?; - match ty { - TypeDef::Func(fty) => { - module.signatures.push(fty); - } - _ => {} + if let TypeDef::Func(fty) = ty { + module.signatures.push(fty); } } } Payload::ImportSection(mut reader) => { for _ in 0..reader.get_count() { - match reader.read()?.ty { - ImportSectionEntryType::Function(sig_idx) => { - module.funcs.push(FuncDecl::Import(sig_idx as SignatureId)); - *next_func += 1; - } - _ => {} + if let ImportSectionEntryType::Function(sig_idx) = reader.read()?.ty { + module.funcs.push(FuncDecl::Import(sig_idx as SignatureId)); + *next_func += 1; } } } @@ -64,10 +58,10 @@ fn handle_payload<'a>( *next_func += 1; let my_sig = module.funcs[func_idx].sig(); - let body = parse_body(&module, my_sig, body)?; + let body = parse_body(module, my_sig, body)?; match &mut module.funcs[func_idx] { - &mut FuncDecl::Body(_, ref mut existing_body) => { + FuncDecl::Body(_, ref mut existing_body) => { *existing_body = body; } _ => unreachable!(), @@ -93,7 +87,7 @@ fn parse_body<'a, 'b>( } } - let mut builder = FunctionBodyBuilder::new(&module, my_sig, &mut ret); + let mut builder = FunctionBodyBuilder::new(module, my_sig, &mut ret); let ops = body.get_operators_reader()?; for op in ops.into_iter() { let op = op?; diff --git a/src/ir.rs b/src/ir.rs index f886efb..f783fd4 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -23,8 +23,8 @@ pub enum FuncDecl<'a> { impl<'a> FuncDecl<'a> { pub fn sig(&self) -> SignatureId { match self { - &FuncDecl::Import(sig) => sig, - &FuncDecl::Body(sig, ..) => sig, + FuncDecl::Import(sig) => *sig, + FuncDecl::Body(sig, ..) => *sig, } } }