From b964fa497fd285df5b901c1c59c900cc640f3157 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 2 Jan 2025 15:19:00 +0000 Subject: [PATCH] fix clippy lints --- agb/examples/dma_effect_circular_window.rs | 2 +- agb/examples/dynamic_tiles.rs | 2 +- agb/src/bitarray.rs | 2 +- agb/src/display/bitmap4.rs | 10 +++++++--- agb/src/display/object/sprites/sprite_allocator.rs | 7 ++++--- agb/src/display/window.rs | 4 ++-- agb/src/dma.rs | 6 +++--- agb/src/save/flash.rs | 2 +- agb/src/sound/dmg.rs | 6 +++--- agb/src/sound/mixer/hw.rs | 2 +- tracker/agb-midi-core/src/lib.rs | 2 +- 11 files changed, 25 insertions(+), 20 deletions(-) diff --git a/agb/examples/dma_effect_circular_window.rs b/agb/examples/dma_effect_circular_window.rs index 1fe1c927c..336b17036 100644 --- a/agb/examples/dma_effect_circular_window.rs +++ b/agb/examples/dma_effect_circular_window.rs @@ -72,7 +72,7 @@ fn main(mut gba: agb::Gba) -> ! { let x_pos = pos.x.floor().max(0) as u16; let y_pos = pos.y.floor().max(0); - let x_adjustment = x_pos << 8 | x_pos; + let x_adjustment = (x_pos << 8) | x_pos; for (i, value) in circle_poses.iter_mut().enumerate() { let i = i as i32; if i <= y_pos || i >= y_pos + 64 { diff --git a/agb/examples/dynamic_tiles.rs b/agb/examples/dynamic_tiles.rs index 2fb4eb9b6..6a9306441 100644 --- a/agb/examples/dynamic_tiles.rs +++ b/agb/examples/dynamic_tiles.rs @@ -32,7 +32,7 @@ fn main(mut gba: agb::Gba) -> ! { let mut value = 0; for j in 0..4 { - value |= (value << 8) | ((x + i) % 8) | ((y + j) % 8) << 4; + value |= (value << 8) | ((x + i) % 8) | (((y + j) % 8) << 4); } *bit = value; diff --git a/agb/src/bitarray.rs b/agb/src/bitarray.rs index 9086e9231..7d1b7b3c1 100644 --- a/agb/src/bitarray.rs +++ b/agb/src/bitarray.rs @@ -10,7 +10,7 @@ impl Bitarray { pub fn get(&self, index: usize) -> Option { if index < N * 32 { - Some((self.a[index / 32] >> (index % 32) & 1) != 0) + Some(((self.a[index / 32] >> (index % 32)) & 1) != 0) } else { None } diff --git a/agb/src/display/bitmap4.rs b/agb/src/display/bitmap4.rs index 297090c94..03ebca71c 100644 --- a/agb/src/display/bitmap4.rs +++ b/agb/src/display/bitmap4.rs @@ -54,7 +54,11 @@ impl Bitmap4<'_> { let c = addr.get(x_in_screen, y_in_screen); if x & 0b1 != 0 { - addr.set(x_in_screen, y_in_screen, c & 0xff | u16::from(colour) << 8); + addr.set( + x_in_screen, + y_in_screen, + c & 0xff | (u16::from(colour) << 8), + ); } else { addr.set(x_in_screen, y_in_screen, c & 0xff00 | u16::from(colour)); } @@ -117,7 +121,7 @@ impl Bitmap4<'_> { let x_in_screen = (x / 2) as usize; let y_in_screen = y as usize; let c = u16::from(colour); - addr.set(x_in_screen, y_in_screen, c << 8 | c); + addr.set(x_in_screen, y_in_screen, (c << 8) | c); } /// Fills specified page with color. @@ -131,7 +135,7 @@ impl Bitmap4<'_> { for x in 0..(WIDTH / 2) as usize { for y in 0..(HEIGHT as usize) { - addr.set(x, y, c << 8 | c); + addr.set(x, y, (c << 8) | c); } } } diff --git a/agb/src/display/object/sprites/sprite_allocator.rs b/agb/src/display/object/sprites/sprite_allocator.rs index 8050347b8..74b4fa321 100644 --- a/agb/src/display/object/sprites/sprite_allocator.rs +++ b/agb/src/display/object/sprites/sprite_allocator.rs @@ -388,9 +388,10 @@ impl DynamicSprite { /// Wipes the sprite pub fn clear(&mut self, paletted_pixel: usize) { assert!(paletted_pixel < 0x10); - let reset = - (paletted_pixel | paletted_pixel << 4 | paletted_pixel << 8 | paletted_pixel << 12) - as u16; + let reset = (paletted_pixel + | (paletted_pixel << 4) + | (paletted_pixel << 8) + | (paletted_pixel << 12)) as u16; self.data.fill(reset); } diff --git a/agb/src/display/window.rs b/agb/src/display/window.rs index e248d1f22..449b07a22 100644 --- a/agb/src/display/window.rs +++ b/agb/src/display/window.rs @@ -235,10 +235,10 @@ impl MovableWindow { self.inner.commit(self.id); let left_right = - (self.rect.position.x as u16) << 8 | (self.rect.position.x + self.rect.size.x) as u16; + ((self.rect.position.x as u16) << 8) | (self.rect.position.x + self.rect.size.x) as u16; let top_bottom = - (self.rect.position.y as u16) << 8 | (self.rect.position.y + self.rect.size.y) as u16; + ((self.rect.position.y as u16) << 8) | (self.rect.position.y + self.rect.size.y) as u16; unsafe { REG_HORIZONTAL_BASE.add(self.id).write_volatile(left_right); REG_VERTICAL_BASE.add(self.id).write_volatile(top_bottom); diff --git a/agb/src/dma.rs b/agb/src/dma.rs index 4f17e2cda..7d51f093f 100644 --- a/agb/src/dma.rs +++ b/agb/src/dma.rs @@ -101,10 +101,10 @@ impl Dma { self.ctrl_addr.set( (0b10 << 0x15) | // keep destination address fixed // (0b00 << 0x17) | // increment the source address each time - 1 << 0x19 | // repeat the copy each hblank + (1 << 0x19) | // repeat the copy each hblank // 0 << 0x1a | // copy in half words (see n_transfers above) - 0b10 << 0x1c | // copy each hblank - 1 << 0x1f | // enable the dma + (0b10 << 0x1c) | // copy each hblank + (1 << 0x1f) | // enable the dma n_transfers, // the number of halfwords to copy ); diff --git a/agb/src/save/flash.rs b/agb/src/save/flash.rs index f0b0f65bc..e76334fd4 100644 --- a/agb/src/save/flash.rs +++ b/agb/src/save/flash.rs @@ -106,7 +106,7 @@ pub fn detect_chip_id() -> Result { issue_flash_command(CMD_READ_CHIP_ID); let high = unsafe { read_raw_byte(0x0E000001) }; let low = unsafe { read_raw_byte(0x0E000000) }; - let id = (high as u16) << 8 | low as u16; + let id = ((high as u16) << 8) | low as u16; issue_flash_command(CMD_READ_CONTENTS); Ok(id) } diff --git a/agb/src/sound/dmg.rs b/agb/src/sound/dmg.rs index 206948e59..f67c9158e 100644 --- a/agb/src/sound/dmg.rs +++ b/agb/src/sound/dmg.rs @@ -180,8 +180,8 @@ impl SweepSettings { fn as_bits(&self) -> u16 { (u16::from(self.number_of_sweep_shifts) & 0b111) - | ((1 - self.sound_direction.as_bits()) << 3) // sweep works backwards - | (u16::from(self.sweep_time) & 0b111) << 4 + | ((1 - self.sound_direction.as_bits()) << 3) // sweep works backwards + | ((u16::from(self.sweep_time) & 0b111) << 4) } } @@ -210,7 +210,7 @@ impl EnvelopeSettings { } fn as_bits(&self) -> u16 { - u16::from(self.step_time) << 8 + (u16::from(self.step_time) << 8) | (self.direction.as_bits() << 11) | (u16::from(self.initial_volume) << 12) } diff --git a/agb/src/sound/mixer/hw.rs b/agb/src/sound/mixer/hw.rs index ba6b7ba5f..5a6b8e5c6 100644 --- a/agb/src/sound/mixer/hw.rs +++ b/agb/src/sound/mixer/hw.rs @@ -93,7 +93,7 @@ pub(super) fn set_sound_control_register_for_mixer() { SOUND_CONTROL_X.set(1 << 7); // Set the sound bias PWM resampling rate to 8bit at 65536Hz (default for most games) - SOUND_BIAS.set(SOUND_BIAS.get() | 1 << 14); + SOUND_BIAS.set(SOUND_BIAS.get() | (1 << 14)); } pub(super) fn set_timer_counter_for_frequency_and_enable(timer: &mut Timer, frequency: i32) { diff --git a/tracker/agb-midi-core/src/lib.rs b/tracker/agb-midi-core/src/lib.rs index 2b1cefacc..8f4329792 100644 --- a/tracker/agb-midi-core/src/lib.rs +++ b/tracker/agb-midi-core/src/lib.rs @@ -41,7 +41,7 @@ pub fn parse_midi(midi_info: &MidiInfo) -> Track { for (i, preset) in sf2.get_presets().iter().enumerate() { preset_lookup.insert( - preset.get_bank_number() << 16 | preset.get_patch_number(), + (preset.get_bank_number() << 16) | preset.get_patch_number(), i, ); }