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
```
This commit is contained in:
Jan Van Bruggen 2022-01-15 17:19:32 -07:00
parent f7a0fbc8b0
commit c1dc0226f6

View file

@ -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"
}
}
}