From 1035c55f77f93a8cb333b7e399da1e24fc243e5b Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Tue, 10 Sep 2024 01:23:57 +0200 Subject: [PATCH] Fix most clippy warnings This fixes most clippy warnings that I'm seeing. --- crates/fuzz-utils/src/lib.rs | 8 +++--- crates/macro/src/lib.rs | 18 ++++++------- crates/tests-utils/src/lib.rs | 2 +- crates/tests/src/lib.rs | 23 ++++++++--------- crates/tests/tests/custom_sections.rs | 4 +-- crates/tests/tests/spec-tests.rs | 5 ++-- src/dot.rs | 8 +++--- src/module/custom.rs | 25 ++++++------------- src/module/data.rs | 7 ++---- src/module/debug/dwarf.rs | 22 ++++++++-------- src/module/debug/units.rs | 4 +-- src/module/elements.rs | 2 +- .../functions/local_function/context.rs | 4 +-- src/module/functions/local_function/emit.rs | 4 +-- src/module/functions/local_function/mod.rs | 13 +++------- src/module/functions/mod.rs | 6 ++--- src/module/imports.rs | 4 +-- src/module/memories.rs | 5 ++++ src/module/mod.rs | 20 ++++++++------- src/module/producers.rs | 2 +- src/module/types.rs | 2 +- src/parse.rs | 2 +- src/passes/used.rs | 14 +++++------ src/ty.rs | 4 +-- 24 files changed, 95 insertions(+), 113 deletions(-) diff --git a/crates/fuzz-utils/src/lib.rs b/crates/fuzz-utils/src/lib.rs index c595f25c..1873e3af 100755 --- a/crates/fuzz-utils/src/lib.rs +++ b/crates/fuzz-utils/src/lib.rs @@ -99,20 +99,20 @@ where } fn interp(&self, wasm: &[u8]) -> Result { - fs::write(self.scratch.path(), &wasm).context("failed to write to scratch file")?; + fs::write(self.scratch.path(), wasm).context("failed to write to scratch file")?; wasm_interp(self.scratch.path()) } fn round_trip_through_walrus(&self, wasm: &[u8]) -> Result> { let mut module = - walrus::Module::from_buffer(&wasm).context("walrus failed to parse the wasm buffer")?; + walrus::Module::from_buffer(wasm).context("walrus failed to parse the wasm buffer")?; walrus::passes::gc::run(&mut module); let buf = module.emit_wasm(); Ok(buf) } fn test_wat(&self, wat: &str) -> Result<()> { - let wasm = self.wat2wasm(&wat)?; + let wasm = self.wat2wasm(wat)?; let expected = self.interp(&wasm)?; let walrus_wasm = self.round_trip_through_walrus(&wasm)?; @@ -313,7 +313,7 @@ impl WatGen { self.wat.push_str(&operator.to_string()); for op in immediates.into_iter() { - self.wat.push_str(" "); + self.wat.push(' '); self.wat.push_str(op.as_ref()); } diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index 07029f2a..36731a7a 100755 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -103,7 +103,7 @@ impl Parse for WalrusFieldOpts { if attr == "skip_visit" { return Ok(Attr::SkipVisit); } - return Err(Error::new(attr.span(), "unexpected attribute")); + Err(Error::new(attr.span(), "unexpected attribute")) } } } @@ -144,7 +144,7 @@ impl Parse for WalrusVariantOpts { if attr == "skip_builder" { return Ok(Attr::SkipBuilder); } - return Err(Error::new(attr.span(), "unexpected attribute")); + Err(Error::new(attr.span(), "unexpected attribute")) } } } @@ -166,7 +166,7 @@ fn walrus_attrs(attrs: &mut Vec) -> TokenStream { ret.extend(group); ret.extend(quote! { , }); } - return ret.into(); + ret.into() } fn create_types(attrs: &[syn::Attribute], variants: &[WalrusVariant]) -> impl quote::ToTokens { @@ -328,10 +328,10 @@ fn create_types(attrs: &[syn::Attribute], variants: &[WalrusVariant]) -> impl qu } } -fn visit_fields<'a>( - variant: &'a WalrusVariant, +fn visit_fields( + variant: &WalrusVariant, allow_skip: bool, -) -> impl Iterator + 'a { +) -> impl Iterator + '_ { return variant .syn .fields @@ -439,7 +439,7 @@ fn create_visit(variants: &[WalrusVariant]) -> impl quote::ToTokens { } }); - let doc = format!("Visit `{}`.", name.to_string()); + let doc = format!("Visit `{}`.", name); visitor_trait_methods.push(quote! { #[doc=#doc] #[inline] @@ -723,13 +723,13 @@ fn create_builder(variants: &[WalrusVariant]) -> impl quote::ToTokens { let doc = format!( "Push a new `{}` instruction onto this builder's block.", - name.to_string() + name ); let at_doc = format!( "Splice a new `{}` instruction into this builder's block at the given index.\n\n\ # Panics\n\n\ Panics if `position > self.instrs.len()`.", - name.to_string() + name ); let arg_names = &arg_names; diff --git a/crates/tests-utils/src/lib.rs b/crates/tests-utils/src/lib.rs index 6840644f..4bad6b49 100644 --- a/crates/tests-utils/src/lib.rs +++ b/crates/tests-utils/src/lib.rs @@ -67,7 +67,7 @@ where cmd.arg(input); cmd.arg("-o"); cmd.arg(tmp.path()); - cmd.args(&[ + cmd.args([ "--enable-threads", "--enable-bulk-memory", // "--enable-reference-types", diff --git a/crates/tests/src/lib.rs b/crates/tests/src/lib.rs index 63dd2584..5e5217a1 100644 --- a/crates/tests/src/lib.rs +++ b/crates/tests/src/lib.rs @@ -79,11 +79,11 @@ impl FileCheck { let mut iter = contents.lines().map(str::trim); while let Some(line) = iter.next() { if line.starts_with("(; CHECK-ALL:") { - if patterns.len() != 0 { + if !patterns.is_empty() { panic!("CHECK cannot be used with CHECK-ALL"); } let mut pattern = Vec::new(); - while let Some(line) = iter.next() { + for line in iter.by_ref() { if line == ";)" { break; } @@ -95,18 +95,17 @@ impl FileCheck { return FileCheck::Exhaustive(pattern, path.to_path_buf()); } - if line.starts_with(";; CHECK:") { - let p = line[";; CHECK:".len()..].to_string(); - patterns.push(vec![p]); + if let Some(p) = line.strip_prefix(";; CHECK:") { + patterns.push(vec![p.to_string()]); } - if line.starts_with(";; NEXT:") { + if let Some(n) = line.strip_prefix(";; NEXT:") { let p = patterns .last_mut() .expect("NEXT should never come before CHECK"); - p.push(line[";; NEXT:".len()..].to_string()); + p.push(n.to_string()); } } - if patterns.len() == 0 { + if patterns.is_empty() { FileCheck::None(path.to_path_buf()) } else { FileCheck::Patterns(patterns) @@ -125,7 +124,7 @@ impl FileCheck { 'inner: while let Some(pos) = output_lines[start..] .iter() - .position(|l| matches(*l, first_line)) + .position(|l| matches(l, first_line)) { start = pos + 1; if output_lines[pos..].len() + 1 < pattern.len() { @@ -155,11 +154,11 @@ impl FileCheck { } } FileCheck::None(_) => { - println!(""); + println!(); println!("no test assertions were found in this file, but"); println!("you can rerun tests with `WALRUS_BLESS=1` to"); println!("automatically add assertions to this file"); - println!(""); + println!(); panic!("no tests to run") } } @@ -210,7 +209,7 @@ fn update_output(path: &Path, output: &str) { new_output.push_str(" "); new_output.push_str(line.trim_end()); } - new_output.push_str("\n"); + new_output.push('\n'); } let new = format!( "{}\n\n(; CHECK-ALL:\n{}\n;)\n", diff --git a/crates/tests/tests/custom_sections.rs b/crates/tests/tests/custom_sections.rs index 518b44de..0a6e4e8a 100644 --- a/crates/tests/tests/custom_sections.rs +++ b/crates/tests/tests/custom_sections.rs @@ -87,8 +87,8 @@ fn smoke_test_code_transform() { fn apply_code_transform(&mut self, transform: &CodeTransform) { APPLIED_CODE_TRANSFORM.store(1, Ordering::SeqCst); assert!(!transform.instruction_map.is_empty()); - for (input_offset, output_offset) in transform.instruction_map.iter().cloned() { - assert_eq!(input_offset.data() as usize + 3, output_offset); + for (input_offset, output_offset) in transform.instruction_map.iter() { + assert_eq!(input_offset.data() as usize + 3, *output_offset); } } } diff --git a/crates/tests/tests/spec-tests.rs b/crates/tests/tests/spec-tests.rs index f5bad3d4..2a19b1ea 100644 --- a/crates/tests/tests/spec-tests.rs +++ b/crates/tests/tests/spec-tests.rs @@ -19,8 +19,7 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> { let proposal = wast .iter() .skip_while(|part| *part != "proposals") - .skip(1) - .next() + .nth(1) .map(|s| s.to_str().unwrap()); let extra_args: &[&str] = match proposal { @@ -168,7 +167,7 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> { } let wasm = module.emit_wasm(); - fs::write(&file, wasm)?; + fs::write(file, wasm)?; } run_spectest_interp(tempdir.path(), extra_args)?; diff --git a/src/dot.rs b/src/dot.rs index 6d229ff9..d728af13 100644 --- a/src/dot.rs +++ b/src/dot.rs @@ -103,7 +103,7 @@ impl Dot for T { impl FieldAggregator for AppendFields<'_> { fn add_field(&mut self, field: &[&str]) { - assert!(field.len() > 0); + assert!(!field.is_empty()); self.out.push_str(""); for f in field { self.out.push_str(""); @@ -114,7 +114,7 @@ impl Dot for T { } fn add_field_with_port(&mut self, port: &str, field: &str) { - assert!(field.len() > 0); + assert!(!field.is_empty()); self.out.push_str(""); self.out.push_str(" Dot for T { fn add_edge_from_port(&mut self, port: &str, to: &impl DotName) { self.out.push_str(" "); self.out.push_str(self.from); - self.out.push_str(":"); + self.out.push(':'); self.out.push_str(port); self.out.push_str(" -> "); self.out.push_str(&to.dot_name()); @@ -174,7 +174,7 @@ impl Dot for Module { // self.name.dot(out); // self.config.dot(out); - out.push_str("}"); + out.push('}'); } } diff --git a/src/module/custom.rs b/src/module/custom.rs index 89469ee7..c60f7cb1 100644 --- a/src/module/custom.rs +++ b/src/module/custom.rs @@ -193,10 +193,7 @@ where T: CustomSection, { fn clone(&self) -> Self { - TypedCustomSectionId { - id: self.id, - _phantom: PhantomData, - } + *self } } @@ -366,26 +363,18 @@ impl ModuleCustomSections { /// Iterate over shared references to custom sections and their ids. pub fn iter(&self) -> impl Iterator { - self.arena.iter().flat_map(|(id, s)| { - if let Some(s) = s.as_ref() { - Some((UntypedCustomSectionId(id), &**s)) - } else { - None - } - }) + self.arena + .iter() + .flat_map(|(id, s)| Some((UntypedCustomSectionId(id), &**s.as_ref()?))) } /// Iterate over exclusive references to custom sections and their ids. pub fn iter_mut( &mut self, ) -> impl Iterator { - self.arena.iter_mut().flat_map(|(id, s)| { - if let Some(s) = s.as_mut() { - Some((UntypedCustomSectionId(id), &mut **s)) - } else { - None - } - }) + self.arena + .iter_mut() + .flat_map(|(id, s)| Some((UntypedCustomSectionId(id), &mut **s.as_mut()?))) } /// Remove a custom section (by type) from the module. diff --git a/src/module/data.rs b/src/module/data.rs index bd7b5aac..f6442c8c 100644 --- a/src/module/data.rs +++ b/src/module/data.rs @@ -64,10 +64,7 @@ impl Data { /// Is this a passive data segment? pub fn is_passive(&self) -> bool { - match self.kind { - DataKind::Passive => true, - _ => false, - } + matches!(self.kind, DataKind::Passive) } } @@ -129,7 +126,7 @@ impl ModuleData { let mut any_passive = false; for data in self.iter() { - cx.indices.set_data_index(data.id(), count as u32); + cx.indices.set_data_index(data.id(), count); count += 1; any_passive |= data.is_passive(); } diff --git a/src/module/debug/dwarf.rs b/src/module/debug/dwarf.rs index 5d571e82..0b1f36e8 100644 --- a/src/module/debug/dwarf.rs +++ b/src/module/debug/dwarf.rs @@ -324,9 +324,9 @@ mod tests { use gimli::*; use std::cell::RefCell; - fn make_test_debug_line<'a>( - debug_line: &'a mut write::DebugLine>, - ) -> IncompleteLineProgram> { + fn make_test_debug_line( + debug_line: &mut write::DebugLine>, + ) -> IncompleteLineProgram> { let encoding = Encoding { format: Format::Dwarf32, version: 4, @@ -368,11 +368,9 @@ mod tests { .unwrap(); let debug_line = read::DebugLine::new(debug_line.slice(), LittleEndian); - let incomplete_debug_line = debug_line + debug_line .program(DebugLineOffset(0), 4, None, None) - .unwrap(); - - incomplete_debug_line + .unwrap() } #[test] @@ -559,11 +557,11 @@ mod tests { #[test] fn test_convert_high_pc() { let sections = make_test_debug_info(); - let mut read_dwarf = Dwarf::default(); - - read_dwarf.debug_info = read::DebugInfo::new(sections.debug_info.slice(), LittleEndian); - read_dwarf.debug_abbrev = - read::DebugAbbrev::new(sections.debug_abbrev.slice(), LittleEndian); + let read_dwarf = Dwarf { + debug_info: read::DebugInfo::new(sections.debug_info.slice(), LittleEndian), + debug_abbrev: read::DebugAbbrev::new(sections.debug_abbrev.slice(), LittleEndian), + ..Default::default() + }; let read_first_unit_header = read_dwarf.units().next().unwrap().unwrap(); let read_first_unit = read_dwarf.unit(read_first_unit_header).unwrap(); diff --git a/src/module/debug/units.rs b/src/module/debug/units.rs index 10030d88..8905de68 100644 --- a/src/module/debug/units.rs +++ b/src/module/debug/units.rs @@ -76,10 +76,10 @@ mod tests { let mut cursor = DebuggingInformationCursor::new(&mut unit1); - assert_eq!(cursor.current().is_none(), true); + assert!(cursor.current().is_none()); assert_eq!(cursor.next_dfs().unwrap().id(), root_id); assert_eq!(cursor.next_dfs().unwrap().id(), child1_id); assert_eq!(cursor.next_dfs().unwrap().id(), child2_id); - assert_eq!(cursor.next_dfs().is_none(), true); + assert!(cursor.next_dfs().is_none()); } } diff --git a/src/module/elements.rs b/src/module/elements.rs index 1820d2dd..122a8ac2 100644 --- a/src/module/elements.rs +++ b/src/module/elements.rs @@ -258,7 +258,7 @@ impl Emit for ModuleElements { Some(cx.indices.get_table_index(*table)).filter(|&index| index != 0); wasm_element_section.active( table_index, - &offset.to_wasmencoder_type(&cx), + &offset.to_wasmencoder_type(cx), els, ); } diff --git a/src/module/functions/local_function/context.rs b/src/module/functions/local_function/context.rs index 1902ae60..a29700c7 100644 --- a/src/module/functions/local_function/context.rs +++ b/src/module/functions/local_function/context.rs @@ -110,7 +110,7 @@ impl<'a> ValidationContext<'a> { } pub fn pop_control(&mut self) -> Result<(ControlFrame, InstrSeqId)> { - let frame = impl_pop_control(&mut self.controls)?; + let frame = impl_pop_control(self.controls)?; let block = frame.block; Ok((frame, block)) } @@ -214,7 +214,7 @@ fn impl_push_control_with_ty( fn impl_pop_control(controls: &mut ControlStack) -> Result { controls .last() - .ok_or_else(|| ErrorKind::InvalidWasm) + .ok_or(ErrorKind::InvalidWasm) .context("attempted to pop a frame from an empty control stack")?; let frame = controls.pop().unwrap(); Ok(frame) diff --git a/src/module/functions/local_function/emit.rs b/src/module/functions/local_function/emit.rs index 41447bc8..7f5da78d 100644 --- a/src/module/functions/local_function/emit.rs +++ b/src/module/functions/local_function/emit.rs @@ -87,7 +87,7 @@ impl<'instr> Visitor<'instr> for Emit<'_> { if let Some(map) = self.map.as_mut() { let pos = self.encoder.byte_len(); // Save the encoded_at position for the specified ExprId. - map.push((seq.end.clone(), pos)); + map.push((seq.end, pos)); } if let BlockKind::If = popped_kind.unwrap() { @@ -107,7 +107,7 @@ impl<'instr> Visitor<'instr> for Emit<'_> { if let Some(map) = self.map.as_mut() { let pos = self.encoder.byte_len(); // Save the encoded_at position for the specified ExprId. - map.push((instr_loc.clone(), pos)); + map.push((*instr_loc, pos)); } let is_block = match instr { diff --git a/src/module/functions/local_function/mod.rs b/src/module/functions/local_function/mod.rs index bc8c327e..8c66f68a 100644 --- a/src/module/functions/local_function/mod.rs +++ b/src/module/functions/local_function/mod.rs @@ -69,7 +69,7 @@ impl LocalFunction { }), }; - let result: Vec<_> = module.types.get(ty).results().iter().cloned().collect(); + let result: Vec<_> = module.types.get(ty).results().to_vec(); let result = result.into_boxed_slice(); let controls = &mut context::ControlStack::new(); @@ -299,11 +299,7 @@ fn block_param_tys(ctx: &ValidationContext, ty: wasmparser::BlockType) -> Result } } -fn append_instruction<'context>( - ctx: &'context mut ValidationContext, - inst: Operator, - loc: InstrLocId, -) { +fn append_instruction(ctx: &mut ValidationContext, inst: Operator, loc: InstrLocId) { // NB. there's a lot of `unwrap()` here in this function, and that's because // the `Operator` was validated above to already be valid, so everything // should succeed. @@ -963,10 +959,7 @@ fn append_instruction<'context>( } Operator::MemoryAtomicWait32 { ref memarg } | Operator::MemoryAtomicWait64 { ref memarg } => { - let sixty_four = match inst { - Operator::MemoryAtomicWait32 { .. } => false, - _ => true, - }; + let sixty_four = !matches!(inst, Operator::MemoryAtomicWait32 { .. }); let (memory, arg) = mem_arg(ctx, memarg); ctx.alloc_instr( AtomicWait { diff --git a/src/module/functions/mod.rs b/src/module/functions/mod.rs index 871bd5ba..42c02505 100644 --- a/src/module/functions/mod.rs +++ b/src/module/functions/mod.rs @@ -200,7 +200,7 @@ impl ModuleFunctions { /// return the first function in the module with the given name. pub fn by_name(&self, name: &str) -> Option { self.arena.iter().find_map(|(id, f)| { - if f.name.as_ref().map(|s| s.as_str()) == Some(name) { + if f.name.as_deref() == Some(name) { Some(id) } else { None @@ -292,7 +292,7 @@ impl ModuleFunctions { pub(crate) fn emit_func_section(&self, cx: &mut EmitContext) { log::debug!("emit function section"); let functions = used_local_functions(cx); - if functions.len() == 0 { + if functions.is_empty() { return; } let mut func_section = wasm_encoder::FunctionSection::new(); @@ -605,7 +605,7 @@ impl Emit for ModuleFunctions { fn emit(&self, cx: &mut EmitContext) { log::debug!("emit code section"); let functions = used_local_functions(cx); - if functions.len() == 0 { + if functions.is_empty() { return; } diff --git a/src/module/imports.rs b/src/module/imports.rs index 6f0b758a..c37cfda7 100644 --- a/src/module/imports.rs +++ b/src/module/imports.rs @@ -307,8 +307,8 @@ impl Emit for ModuleImports { cx.indices.push_memory(id); let mem = cx.module.memories.get(id); wasm_encoder::EntityType::Memory(wasm_encoder::MemoryType { - minimum: mem.initial as u64, - maximum: mem.maximum.map(|v| v as u64), + minimum: mem.initial, + maximum: mem.maximum, memory64: false, shared: mem.shared, page_size_log2: None, diff --git a/src/module/memories.rs b/src/module/memories.rs index 50907981..0f2f24fc 100644 --- a/src/module/memories.rs +++ b/src/module/memories.rs @@ -144,6 +144,11 @@ impl ModuleMemories { pub fn len(&self) -> usize { self.arena.len() } + + /// Checks if there are no memories in this module + pub fn is_empty(&self) -> bool { + self.arena.len() == 0 + } } impl Module { diff --git a/src/module/mod.rs b/src/module/mod.rs index 55e038f9..370e5a76 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -130,8 +130,10 @@ impl Module { } fn parse(wasm: &[u8], config: &ModuleConfig) -> Result { - let mut ret = Module::default(); - ret.config = config.clone(); + let mut ret = Module { + config: config.clone(), + ..Default::default() + }; let mut indices = IndicesToIds::default(); // For now we have the same set of wasm features @@ -160,7 +162,7 @@ impl Module { validator .data_section(&s) .context("failed to parse data section")?; - ret.parse_data(s, &mut indices)?; + ret.parse_data(s, &indices)?; } Payload::TypeSection(s) => { validator @@ -196,7 +198,7 @@ impl Module { validator .export_section(&s) .context("failed to parse export section")?; - ret.parse_exports(s, &mut indices)?; + ret.parse_exports(s, &indices)?; } Payload::ElementSection(s) => { validator @@ -373,7 +375,7 @@ impl Module { log::debug!("skipping DWARF custom section"); } - let indices = mem::replace(cx.indices, Default::default()); + let indices = std::mem::take(cx.indices); for (_id, section) in customs.iter_mut() { if section.name().starts_with(".debug") { @@ -555,7 +557,7 @@ fn emit_name_section(cx: &mut EmitContext) { Some((*index, name)) }) .collect::>(); - if local_names.len() == 0 { + if local_names.is_empty() { None } else { Some((cx.indices.get_func_index(func.id()), local_names)) @@ -564,7 +566,7 @@ fn emit_name_section(cx: &mut EmitContext) { .collect::>(); locals.sort_by_key(|p| p.0); // sort by index - if cx.module.name.is_none() && funcs.len() == 0 && locals.len() == 0 { + if cx.module.name.is_none() && funcs.is_empty() && locals.is_empty() { return; } @@ -572,7 +574,7 @@ fn emit_name_section(cx: &mut EmitContext) { wasm_name_section.module(name); } - if funcs.len() > 0 { + if !funcs.is_empty() { let mut name_map = wasm_encoder::NameMap::new(); for (index, name) in funcs { name_map.append(index, name); @@ -580,7 +582,7 @@ fn emit_name_section(cx: &mut EmitContext) { wasm_name_section.functions(&name_map); } - if locals.len() > 0 { + if !locals.is_empty() { let mut indirect_name_map = wasm_encoder::IndirectNameMap::new(); for (index, mut map) in locals { let mut name_map = wasm_encoder::NameMap::new(); diff --git a/src/module/producers.rs b/src/module/producers.rs index 8dae0c96..882fc4a2 100644 --- a/src/module/producers.rs +++ b/src/module/producers.rs @@ -101,7 +101,7 @@ impl Module { impl Emit for ModuleProducers { fn emit(&self, cx: &mut EmitContext) { log::debug!("emit producers section"); - if self.fields.len() == 0 { + if self.fields.is_empty() { return; } let mut wasm_producers_section = wasm_encoder::ProducersSection::new(); diff --git a/src/module/types.rs b/src/module/types.rs index 23aec534..3b64b947 100644 --- a/src/module/types.rs +++ b/src/module/types.rs @@ -48,7 +48,7 @@ impl ModuleTypes { /// preserve type names from the WAT. pub fn by_name(&self, name: &str) -> Option { self.arena.iter().find_map(|(id, ty)| { - if ty.name.as_ref().map(|s| s.as_str()) == Some(name) { + if ty.name.as_deref() == Some(name) { Some(id) } else { None diff --git a/src/parse.rs b/src/parse.rs index 77195e38..2c23afd6 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -66,7 +66,7 @@ define_push_get!(push_data, get_data, DataId, data); impl IndicesToIds { /// Pushes a new local ID to map it to the next index internally pub(crate) fn push_local(&mut self, function: FunctionId, id: LocalId) -> u32 { - let list = self.locals.entry(function).or_insert(Vec::new()); + let list = self.locals.entry(function).or_default(); list.push(id); (list.len() as u32) - 1 } diff --git a/src/passes/used.rs b/src/passes/used.rs index b77ec6f1..2e640b73 100644 --- a/src/passes/used.rs +++ b/src/passes/used.rs @@ -151,12 +151,12 @@ impl Used { } // Iteratively visit all items until our stack is empty - while stack.funcs.len() > 0 - || stack.tables.len() > 0 - || stack.memories.len() > 0 - || stack.globals.len() > 0 - || stack.datas.len() > 0 - || stack.elements.len() > 0 + while !stack.funcs.is_empty() + || !stack.tables.is_empty() + || !stack.memories.is_empty() + || !stack.globals.is_empty() + || !stack.datas.is_empty() + || !stack.elements.is_empty() { while let Some(f) = stack.funcs.pop() { let func = module.funcs.get(f); @@ -244,7 +244,7 @@ impl Used { // Let's keep `wabt` passing though and just say that if there are data // segments kept, but no memories, then we try to add the first memory, // if any, to the used set. - if stack.used.data.len() > 0 && stack.used.memories.len() == 0 { + if !stack.used.data.is_empty() && stack.used.memories.is_empty() { if let Some(mem) = module.memories.iter().next() { stack.used.memories.insert(mem.id()); } diff --git a/src/ty.rs b/src/ty.rs index 93f368ba..a61ad60d 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -109,13 +109,13 @@ impl Type { /// Get the parameters to this function type. #[inline] pub fn params(&self) -> &[ValType] { - &*self.params + &self.params } /// Get the results of this function type. #[inline] pub fn results(&self) -> &[ValType] { - &*self.results + &self.results } pub(crate) fn is_for_function_entry(&self) -> bool {