From c1dc0226f691114b38e867d19fb170295aa6c662 Mon Sep 17 00:00:00 2001 From: Jan Van Bruggen Date: Sat, 15 Jan 2022 17:19:32 -0700 Subject: [PATCH] Fix a lint error by simplifying an if/else block From `cargo clippy -- -D warnings`: ``` error: all if blocks contain the same code at the start --> compiler/gen_wasm/src/wasm_module/sections.rs:478:9 | 478 | / if bytes[*cursor] == 0 { 479 | | u8::skip_bytes(bytes, cursor); 480 | | u32::skip_bytes(bytes, cursor); | |___________________________________________^ | = note: `-D clippy::branches-sharing-code` implied by `-D warnings` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code help: consider moving the start statements out like this | 478 ~ u8::skip_bytes(bytes, cursor); 479 + u32::skip_bytes(bytes, cursor); 480 + if bytes[*cursor] == 0 { | error: could not compile `roc_gen_wasm` due to previous error warning: build failed, waiting for other jobs to finish... error: build failed ``` --- compiler/gen_wasm/src/wasm_module/sections.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/gen_wasm/src/wasm_module/sections.rs b/compiler/gen_wasm/src/wasm_module/sections.rs index 4a5e370e1f..117d705a07 100644 --- a/compiler/gen_wasm/src/wasm_module/sections.rs +++ b/compiler/gen_wasm/src/wasm_module/sections.rs @@ -482,13 +482,11 @@ impl Serialize for Limits { impl SkipBytes for Limits { fn skip_bytes(bytes: &[u8], cursor: &mut usize) { - if bytes[*cursor] == LimitsId::Min as u8 { - u8::skip_bytes(bytes, cursor); - u32::skip_bytes(bytes, cursor); - } else { - u8::skip_bytes(bytes, cursor); - u32::skip_bytes(bytes, cursor); - u32::skip_bytes(bytes, cursor); + let variant_id = bytes[*cursor]; + u8::skip_bytes(bytes, cursor); // advance past the variant byte + u32::skip_bytes(bytes, cursor); // skip "min" + if variant_id == LimitsId::MinMax as u8 { + u32::skip_bytes(bytes, cursor); // skip "max" } } }