From bc8da0212d76a80c77860df5d4907f0ea139e771 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Tue, 19 Nov 2024 10:16:32 +1100 Subject: [PATCH] clippy: automatic fixes --- frontend-common/src/debug.rs | 10 ++--- frontend-common/src/lib.rs | 2 +- frontend-common/src/window/winit_manager.rs | 2 +- gb-vst/src/lib.rs | 2 +- gb-vst/src/plugin.rs | 2 +- gb-vst/src/plugin/ui.rs | 2 +- .../game_list_entry_display/imp.rs | 2 +- lib/src/config/mod.rs | 41 +++++++++---------- lib/src/connect/mod.rs | 33 +++++++-------- lib/src/lib.rs | 4 +- lib/src/processor/instructions/primitives.rs | 4 +- lib/src/processor/memory.rs | 18 ++++---- lib/src/processor/memory/addresses.rs | 2 +- lib/src/processor/memory/mmio/apu.rs | 2 +- lib/src/processor/memory/mmio/apu/channels.rs | 28 ++++++------- lib/src/processor/memory/mmio/cgb/vram_dma.rs | 4 +- lib/src/processor/memory/mmio/gpu.rs | 16 ++++---- lib/src/processor/memory/mmio/gpu/cgb.rs | 2 +- .../processor/memory/mmio/gpu/layer_window.rs | 2 +- .../processor/memory/mmio/gpu/tile_window.rs | 2 +- lib/src/processor/memory/mmio/gpu/types.rs | 8 ++-- lib/src/processor/memory/rom.rs | 10 ++--- lib/src/processor/memory/rom/licensee.rs | 2 +- lib/src/processor/memory/rom/mbcs/mbc3.rs | 10 ++--- lib/src/processor/memory/rom/mbcs/mbc5.rs | 8 ++-- .../processor/memory/rom/mbcs/pocketcamera.rs | 2 +- lib/src/processor/mod.rs | 4 +- xtask/src/args.rs | 2 +- xtask/src/main.rs | 16 ++++---- xtask/src/types.rs | 2 +- 30 files changed, 118 insertions(+), 126 deletions(-) diff --git a/frontend-common/src/debug.rs b/frontend-common/src/debug.rs index 7b09e7a..8f19fa0 100644 --- a/frontend-common/src/debug.rs +++ b/frontend-common/src/debug.rs @@ -55,11 +55,11 @@ pub struct Debugger { } impl Debugger { - pub fn new(core: Box) -> Self { + #[must_use] pub fn new(core: Box) -> Self { Self { core, stepping: true, - last_command: String::from(""), + last_command: String::new(), watches: HashMap::new(), breakpoints: Vec::new(), } @@ -77,7 +77,7 @@ impl Debugger { let mut line = String::new(); line = match io::stdin().read_line(&mut line) { Ok(_) => line, - Err(_) => String::from(""), + Err(_) => String::new(), }; if line.trim().is_empty() { line = self.last_command.clone(); @@ -95,7 +95,7 @@ impl Debugger { Commands::Continue => self.stepping = false, Commands::Break(address) => { if !self.breakpoints.contains(&address) { - self.breakpoints.push(address) + self.breakpoints.push(address); } } } @@ -116,7 +116,7 @@ impl Debugger { should_pause = true; println!("Memory at 0x{address:0>4X} changed:"); println!(" from 0b{0:0>8b}/0x{0:0>2X}", *data); - println!(" to 0b{0:0>8b}/0x{0:0>2X}", new_data); + println!(" to 0b{new_data:0>8b}/0x{new_data:0>2X}"); *data = new_data; } } diff --git a/frontend-common/src/lib.rs b/frontend-common/src/lib.rs index 49badb2..7fbca85 100644 --- a/frontend-common/src/lib.rs +++ b/frontend-common/src/lib.rs @@ -77,7 +77,7 @@ pub struct RunOptions { } impl RunOptions { - pub fn new(rom: PathBuf) -> Self { + #[must_use] pub fn new(rom: PathBuf) -> Self { Self { rom, save: SramType::Auto, diff --git a/frontend-common/src/window/winit_manager.rs b/frontend-common/src/window/winit_manager.rs index cabd33a..632c80e 100644 --- a/frontend-common/src/window/winit_manager.rs +++ b/frontend-common/src/window/winit_manager.rs @@ -60,7 +60,7 @@ where Backend: RendererBackend, ::RendererError: Sync + Send + 'static, { - pub fn new( + #[must_use] pub fn new( sender: Sender>, _stream: Stream, record_main: bool, diff --git a/gb-vst/src/lib.rs b/gb-vst/src/lib.rs index 574d3a9..fbbd535 100644 --- a/gb-vst/src/lib.rs +++ b/gb-vst/src/lib.rs @@ -22,7 +22,7 @@ impl Default for VstConfig { fn default() -> Self { Self { scale_factor: 3, - rom: String::from(""), + rom: String::new(), force_skip_bootrom: true, } } diff --git a/gb-vst/src/plugin.rs b/gb-vst/src/plugin.rs index 2ca9677..e5c9d8e 100644 --- a/gb-vst/src/plugin.rs +++ b/gb-vst/src/plugin.rs @@ -346,7 +346,7 @@ impl Plugin for GameboyEmu { if let Ok(comms) = self.emu_comms.lock() { if let Some(ref comms) = *comms { match comms.sender.send(EmulatorMessage::Exit) { - Ok(_) => self.vars = None, + Ok(()) => self.vars = None, Err(e) => nih_log!("error {e} sending message to emulator"), } } diff --git a/gb-vst/src/plugin/ui.rs b/gb-vst/src/plugin/ui.rs index a21625f..1247c3a 100644 --- a/gb-vst/src/plugin/ui.rs +++ b/gb-vst/src/plugin/ui.rs @@ -222,7 +222,7 @@ impl WindowHandler for TwincEditorWindow { self.joypad_state, ), ) { - Ok(_) => {} + Ok(()) => {} Err(e) => nih_error!("error sending joypad update: {e:#?}"), } } diff --git a/gui/src/crossplatform/game_list_entry_display/imp.rs b/gui/src/crossplatform/game_list_entry_display/imp.rs index ae4d141..e9ce441 100644 --- a/gui/src/crossplatform/game_list_entry_display/imp.rs +++ b/gui/src/crossplatform/game_list_entry_display/imp.rs @@ -81,7 +81,7 @@ impl ObjectImpl for GameListWindow { .and_then(move |v| v.downcast::().ok()) .unwrap() .path() - ) + ); }); } } diff --git a/lib/src/config/mod.rs b/lib/src/config/mod.rs index 4bb7039..2703bfc 100644 --- a/lib/src/config/mod.rs +++ b/lib/src/config/mod.rs @@ -33,42 +33,39 @@ impl ConfigManager { }) } - pub fn dir(&self) -> PathBuf { + #[must_use] pub fn dir(&self) -> PathBuf { self.path.clone() } - pub fn load_or_create_base_config(&self) -> Config { + #[must_use] pub fn load_or_create_base_config(&self) -> Config { self.load_or_create_config() } - pub fn load_or_create_config(&self) -> C + #[must_use] pub fn load_or_create_config(&self) -> C where C: NamedConfig + Serialize + DeserializeOwned + Default + Clone, { - match self.load_custom_config::() { - Some(v) => { - let _ = self.save_custom_config(v.clone()); - v - } - None => { - let config = C::default(); - if let Ok(true) = self.path.join(C::name()).try_exists() { - log::error!( - "Failed to load \"{}\" config, but it exists on disk", - C::name() - ); - } else { - let result = self.save_custom_config(config.clone()); - if let Err(e) = result { - log::error!("Failed to save \"{}\" config: {e:#?}", C::name()); - } + if let Some(v) = self.load_custom_config::() { + let _ = self.save_custom_config(v.clone()); + v + } else { + let config = C::default(); + if let Ok(true) = self.path.join(C::name()).try_exists() { + log::error!( + "Failed to load \"{}\" config, but it exists on disk", + C::name() + ); + } else { + let result = self.save_custom_config(config.clone()); + if let Err(e) = result { + log::error!("Failed to save \"{}\" config: {e:#?}", C::name()); } - config } + config } } - pub fn load_custom_config(&self) -> Option + #[must_use] pub fn load_custom_config(&self) -> Option where C: NamedConfig + DeserializeOwned + Default, { diff --git a/lib/src/connect/mod.rs b/lib/src/connect/mod.rs index 337d26e..97eb9e4 100644 --- a/lib/src/connect/mod.rs +++ b/lib/src/connect/mod.rs @@ -84,7 +84,7 @@ pub enum RendererMessage> { } impl> RendererMessage { - pub fn display_message(buffer: Vec) -> Self { + #[must_use] pub fn display_message(buffer: Vec) -> Self { Self::Display { buffer } } } @@ -105,7 +105,7 @@ pub struct AudioOutput { } impl AudioOutput { - pub fn new( + #[must_use] pub fn new( sample_rate: f32, buffers_per_frame: usize, downsample_type: DownsampleType, @@ -190,12 +190,9 @@ where #[allow(unused)] pub(crate) fn tick(&mut self, steps: usize) { if self.counter > 0 { - self.counter = match self.counter.checked_sub(steps) { - Some(num) => num, - None => { - self.next_image = Some(self.inner.get_image()); - 0 - } + self.counter = if let Some(num) = self.counter.checked_sub(steps) { num } else { + self.next_image = Some(self.inner.get_image()); + 0 }; } } @@ -242,7 +239,7 @@ impl EmulatorOptions where ColourFormat: From + Copy, { - pub fn new( + #[must_use] pub fn new( window: Option>>, rom: Rom, output: AudioOutput, @@ -298,37 +295,37 @@ where self } - pub fn with_dmg_bootrom(mut self, dmg_bootrom: Option) -> Self { + #[must_use] pub fn with_dmg_bootrom(mut self, dmg_bootrom: Option) -> Self { self.dmg_bootrom = dmg_bootrom; self } - pub fn with_cgb_bootrom(mut self, cgb_bootrom: Option) -> Self { + #[must_use] pub fn with_cgb_bootrom(mut self, cgb_bootrom: Option) -> Self { self.cgb_bootrom = cgb_bootrom; self } - pub fn with_show_bootrom(mut self, show_bootrom: bool) -> Self { + #[must_use] pub fn with_show_bootrom(mut self, show_bootrom: bool) -> Self { self.show_bootrom = show_bootrom; self } - pub fn with_no_output(mut self, no_output: bool) -> Self { + #[must_use] pub fn with_no_output(mut self, no_output: bool) -> Self { self.no_output = no_output; self } - pub fn with_stdout(mut self) -> Self { + #[must_use] pub fn with_stdout(mut self) -> Self { self.serial_target = SerialTarget::Stdout(StdoutType::Ascii); self } - pub fn with_serial_target(mut self, target: SerialTarget) -> Self { + #[must_use] pub fn with_serial_target(mut self, target: SerialTarget) -> Self { self.serial_target = target; self } - pub fn with_tile_window( + #[must_use] pub fn with_tile_window( mut self, window: Option>>, ) -> Self { @@ -336,7 +333,7 @@ where self } - pub fn with_layer_window( + #[must_use] pub fn with_layer_window( mut self, window: Option>>, ) -> Self { @@ -344,7 +341,7 @@ where self } - pub fn with_cgb_mode(mut self, cgb_mode: bool) -> Self { + #[must_use] pub fn with_cgb_mode(mut self, cgb_mode: bool) -> Self { self.cgb_mode = cgb_mode; self } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 5c8a12e..8da0d2c 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -67,7 +67,7 @@ where rom.mbc_type(), if is_cgb_mode { "CGB" } else { "DMG" } ), - })? + })?; } Ok(Self::new( @@ -167,7 +167,7 @@ where EmulatorMessage::Start => self.paused = false, EmulatorMessage::Pause => self.paused = true, EmulatorMessage::JoypadUpdate(new_state) => { - self.cpu.next_joypad_state = Some(new_state) + self.cpu.next_joypad_state = Some(new_state); } EmulatorMessage::NewLayerWindow(new) => self.cpu.memory.gpu.set_layer_window(new), EmulatorMessage::NewTileWindow(new) => self.cpu.memory.gpu.set_tile_window(new), diff --git a/lib/src/processor/instructions/primitives.rs b/lib/src/processor/instructions/primitives.rs index 63030de..b349b61 100644 --- a/lib/src/processor/instructions/primitives.rs +++ b/lib/src/processor/instructions/primitives.rs @@ -103,9 +103,9 @@ where pub(crate) fn set_or_clear_flag(&mut self, flag: Flags, state: bool) { if state { - self.set_flag(flag) + self.set_flag(flag); } else { - self.clear_flag(flag) + self.clear_flag(flag); } } diff --git a/lib/src/processor/memory.rs b/lib/src/processor/memory.rs index e9a7a58..91b54e6 100644 --- a/lib/src/processor/memory.rs +++ b/lib/src/processor/memory.rs @@ -218,7 +218,7 @@ where Address::Prohibited(_) => 0xFF, Address::Io(address) => self.get_io(address), Address::Hram(address) => self.cpu_ram[address.get_local() as usize], - Address::InterruptEnable(_) => self.interrupts.get_enable_register(), + Address::InterruptEnable(()) => self.interrupts.get_enable_register(), } } @@ -253,25 +253,25 @@ where Address::CartRam(address) => self.rom.set_ram(address, data), Address::WorkRam(address) => self.ram.bank_0[address.get_local() as usize] = data, Address::BankedWorkRam(address) => { - self.ram.set_banked(address.get_local() as usize, data) + self.ram.set_banked(address.get_local() as usize, data); } Address::MirroredWorkRam(address) => { - self.ram.bank_0[address.get_local() as usize] = data + self.ram.bank_0[address.get_local() as usize] = data; } Address::MirroredBankedWorkRam(address) => { - self.ram.set_banked(address.get_local() as usize, data) + self.ram.set_banked(address.get_local() as usize, data); } Address::Oam(address) => self.gpu.set_oam(address, data), Address::Prohibited(_) => {} Address::Io(address) => { if address.inner() == 0xFF50 { - self.bootrom = None + self.bootrom = None; } else { - self.set_io(address, data) + self.set_io(address, data); } } Address::Hram(address) => self.cpu_ram[address.get_local() as usize] = data, - Address::InterruptEnable(_) => self.interrupts.set_enable_register(data), + Address::InterruptEnable(()) => self.interrupts.set_enable_register(data), } } @@ -380,7 +380,7 @@ where CgbIoAddress::PrepareSpeed => cgb_peripherals.double_speed.set(data), CgbIoAddress::VramBank => self.gpu.vram.set_vram_bank(data), CgbIoAddress::VramDma(address) => { - cgb_peripherals.vram_dma.set_register(address, data) + cgb_peripherals.vram_dma.set_register(address, data); } CgbIoAddress::Infrared => cgb_peripherals.infrared.set(data), CgbIoAddress::Palette(address) => self.gpu.set_cgb_palette(address, data), @@ -389,7 +389,7 @@ where CgbIoAddress::Pcm12 => {} CgbIoAddress::Pcm34 => {} CgbIoAddress::Unused(v) => { - log::error!("attempt to set unused address 0x{v:0>4X} to 0x{data:0>2X}") + log::error!("attempt to set unused address 0x{v:0>4X} to 0x{data:0>2X}"); } } } diff --git a/lib/src/processor/memory/addresses.rs b/lib/src/processor/memory/addresses.rs index 8c0a834..2684e53 100644 --- a/lib/src/processor/memory/addresses.rs +++ b/lib/src/processor/memory/addresses.rs @@ -225,7 +225,7 @@ impl AddressMarker for Address { Address::Prohibited(v) => v.inner(), Address::Io(v) => v.inner(), Address::Hram(v) => v.inner(), - Address::InterruptEnable(_) => 0xFFFF, + Address::InterruptEnable(()) => 0xFFFF, } } } diff --git a/lib/src/processor/memory/mmio/apu.rs b/lib/src/processor/memory/mmio/apu.rs index 4b8efb1..514563d 100644 --- a/lib/src/processor/memory/mmio/apu.rs +++ b/lib/src/processor/memory/mmio/apu.rs @@ -32,7 +32,7 @@ impl DacSample { } fn mix_channel(&self, sums: f32, volume: u8) -> f32 { - sums * ((volume + 1) as f32 / (8. * 4.)) + sums * (f32::from(volume + 1) / (8. * 4.)) } } diff --git a/lib/src/processor/memory/mmio/apu/channels.rs b/lib/src/processor/memory/mmio/apu/channels.rs index 1327772..af0fe39 100644 --- a/lib/src/processor/memory/mmio/apu/channels.rs +++ b/lib/src/processor/memory/mmio/apu/channels.rs @@ -59,10 +59,10 @@ impl Envelope { self.counter = 0; match self.mode { EnvelopeMode::Increase => { - self.current_volume = self.current_volume.saturating_add(1) + self.current_volume = self.current_volume.saturating_add(1); } EnvelopeMode::Decrease => { - self.current_volume = self.current_volume.saturating_sub(1) + self.current_volume = self.current_volume.saturating_sub(1); } } } @@ -190,7 +190,7 @@ impl PwmChannel { fn dac(&mut self, digital: u8) -> f32 { self.last = digital; - (((digital as f32) * (-2.)) + 1.) * ((self.envelope.current_volume as f32) / 15.) + ((f32::from(digital) * (-2.)) + 1.) * (f32::from(self.envelope.current_volume) / 15.) } pub(super) fn envelope_tick(&mut self) { @@ -206,7 +206,7 @@ impl PwmChannel { self.sweep.counter += 1; if self.sweep.counter % self.sweep.pace == 0 { self.sweep.counter = 0; - let wavelength_diff = self.wavelength / (2_u16.pow(self.sweep.slope as u32)); + let wavelength_diff = self.wavelength / (2_u16.pow(u32::from(self.sweep.slope))); let new_wavelength = match self.sweep.mode { EnvelopeMode::Increase => self.wavelength + wavelength_diff, EnvelopeMode::Decrease => self.wavelength.saturating_sub(wavelength_diff), @@ -280,13 +280,13 @@ impl PwmChannel { } pub(super) fn update_wavelength_low(&mut self, data: u8) { - self.wavelength = (self.wavelength & 0xFF00) | (data as u16); + self.wavelength = (self.wavelength & 0xFF00) | u16::from(data); self.set_wave_timer(); } pub(super) fn update_wavelength_high_and_control(&mut self, data: u8) { self.length_enable = get_bit(data, 6); - self.wavelength = (self.wavelength & 0xFF) | (((data & 0b111) as u16) << 8); + self.wavelength = (self.wavelength & 0xFF) | (u16::from(data & 0b111) << 8); self.set_wave_timer(); if get_bit(data, 7) { self.trigger(); @@ -404,7 +404,7 @@ impl WaveChannel { fn dac(&mut self, digital: u8) -> f32 { if self.dac_enabled && self.volume != ShiftVolumePercent::Zero { self.last = digital; - ((((digital >> self.volume.as_shift_amount()) as f32) * (-2.)) + 1.) / 15. + ((f32::from(digital >> self.volume.as_shift_amount()) * (-2.)) + 1.) / 15. } else { self.last = 0; 0. @@ -453,13 +453,13 @@ impl WaveChannel { } pub(super) fn update_wavelength_low(&mut self, data: u8) { - self.wavelength = (self.wavelength & 0xFF00) | (data as u16); + self.wavelength = (self.wavelength & 0xFF00) | u16::from(data); self.set_wave_timer(); } pub(super) fn update_wavelength_high_and_control(&mut self, data: u8) { self.length_enable = get_bit(data, 6); - self.wavelength = (self.wavelength & 0xFF) | (((data & 0b111) as u16) << 8); + self.wavelength = (self.wavelength & 0xFF) | (u16::from(data & 0b111) << 8); self.set_wave_timer(); if get_bit(data, 7) { self.trigger(); @@ -472,9 +472,7 @@ impl WaveChannel { pub(super) fn update_wave_ram(&mut self, addr: WaveRamAddress, data: u8) { let real_addr = addr.get_local() as usize; - if real_addr >= self.wave_ram.data.len() { - panic!("sent the wrong address to update_wave_ram"); - } + assert!(real_addr < self.wave_ram.data.len(), "sent the wrong address to update_wave_ram"); self.wave_ram.data[real_addr] = data; } @@ -506,8 +504,8 @@ struct Lfsr { impl Lfsr { fn update(&mut self) { - self.interval = (1_u16 << (self.clock_shift as u16)) - .wrapping_mul(1 + (2 * self.clock_divider as u16)) + self.interval = (1_u16 << u16::from(self.clock_shift)) + .wrapping_mul(1 + (2 * u16::from(self.clock_divider))) .wrapping_mul(8); } @@ -601,7 +599,7 @@ impl NoiseChannel { fn dac(&mut self, digital: u8) -> f32 { self.last = digital; - (((digital as f32) * (-2.)) + 1.) * ((self.envelope.current_volume as f32) / 15.) + ((f32::from(digital) * (-2.)) + 1.) * (f32::from(self.envelope.current_volume) / 15.) } pub(super) fn envelope_tick(&mut self) { diff --git a/lib/src/processor/memory/mmio/cgb/vram_dma.rs b/lib/src/processor/memory/mmio/cgb/vram_dma.rs index ccccaea..ba8f9a6 100644 --- a/lib/src/processor/memory/mmio/cgb/vram_dma.rs +++ b/lib/src/processor/memory/mmio/cgb/vram_dma.rs @@ -88,7 +88,7 @@ where let returning = if let Some(cgb_peripherals) = &mut self.cgb_peripherals { match cgb_peripherals.vram_dma.mode { DmaMode::Halt(l) => { - let length = 16 * ((l as u16) + 1); + let length = 16 * (u16::from(l) + 1); copy = Some(( cgb_peripherals.vram_dma.source, cgb_peripherals.vram_dma.destination, @@ -109,7 +109,7 @@ where cgb_peripherals.vram_dma.source += length; cgb_peripherals.vram_dma.destination += length; *progress += 1; - if *progress > (l as u16) { + if *progress > u16::from(l) { cgb_peripherals.vram_dma.mode = DmaMode::Waiting; cgb_peripherals.vram_dma.reset_registers(); } diff --git a/lib/src/processor/memory/mmio/gpu.rs b/lib/src/processor/memory/mmio/gpu.rs index 2e3caee..ca259ce 100644 --- a/lib/src/processor/memory/mmio/gpu.rs +++ b/lib/src/processor/memory/mmio/gpu.rs @@ -192,7 +192,7 @@ where || (self.stat.vblank_interrupt_enabled && (self.stat.mode == DrawMode::VBlank)) || (self.stat.hblank_interrupt_enabled && (self.stat.mode == DrawMode::HBlank)); - interrupts.lcd_stat = this_stat & !self.prev_stat; + interrupts.lcd_stat = this_stat && !self.prev_stat; self.prev_stat = this_stat; interrupts } @@ -202,7 +202,7 @@ where } pub(crate) fn set_vram(&mut self, address: VramAddress, data: u8) { - self.vram.set(address, data) + self.vram.set(address, data); } pub(crate) fn get_oam(&self, address: OamAddress) -> u8 { @@ -215,7 +215,7 @@ where pub(crate) fn set_oam(&mut self, address: OamAddress, data: u8) { if self.stat.mode == DrawMode::VBlank || self.stat.mode == DrawMode::HBlank { - self.oam.set(address, data) + self.oam.set(address, data); } } @@ -359,7 +359,7 @@ where let tile_row = object_row % 8; let tile_addr = (TiledataArea::D8000 .get_addr(object.tile_index + if object_row >= 8 { 1 } else { 0 }) - + (tile_row as u16 * 2)) + + (u16::from(tile_row) * 2)) .unwrap(); let bank = if self.is_cgb_mode() { object.flags.cgb_vram_bank @@ -416,7 +416,7 @@ where layer_window.set( buffer_index + (2 * HEIGHT * WIDTH), colour.rgb_bytes(cgb_data).into(), - ) + ); } } } @@ -443,7 +443,7 @@ where continue; } - let tilemap_column = (tile_line_x / 8) as u16; + let tilemap_column = u16::from(tile_line_x / 8); let tilemap_addr = tilemap.get_addr(row_addr + (tilemap_column)); let attributes = if self.is_cgb_mode() { @@ -465,7 +465,7 @@ where self.vram .get_with_bank(tilemap_addr, VramBank::Bank0) .unwrap(), - ) + tiledata_offset as u16) + ) + u16::from(tiledata_offset)) .unwrap(); let lsbs = self @@ -503,7 +503,7 @@ where layer_window.set( (scanline as usize * WIDTH) + x + if is_bg { 0 } else { HEIGHT * WIDTH }, colour.rgb_bytes(cgb_data).into(), - ) + ); } } } diff --git a/lib/src/processor/memory/mmio/gpu/cgb.rs b/lib/src/processor/memory/mmio/gpu/cgb.rs index e0300b3..57fd0f2 100644 --- a/lib/src/processor/memory/mmio/gpu/cgb.rs +++ b/lib/src/processor/memory/mmio/gpu/cgb.rs @@ -68,7 +68,7 @@ impl CgbPalette { fn set_data(&mut self, data: u8) { self.data[self.index as usize] = data; if self.auto_increment { - self.index = (self.index + 1) & 0b111111 + self.index = (self.index + 1) & 0b111111; } } diff --git a/lib/src/processor/memory/mmio/gpu/layer_window.rs b/lib/src/processor/memory/mmio/gpu/layer_window.rs index baae290..49e6cfb 100644 --- a/lib/src/processor/memory/mmio/gpu/layer_window.rs +++ b/lib/src/processor/memory/mmio/gpu/layer_window.rs @@ -41,7 +41,7 @@ where .sender .send(RendererMessage::display_message(new_buffer)) { - Ok(_) => { + Ok(()) => { for val in self.buffer.iter_mut() { *val = get_blank_colour(cgb); } diff --git a/lib/src/processor/memory/mmio/gpu/tile_window.rs b/lib/src/processor/memory/mmio/gpu/tile_window.rs index 40ffd45..071d26a 100644 --- a/lib/src/processor/memory/mmio/gpu/tile_window.rs +++ b/lib/src/processor/memory/mmio/gpu/tile_window.rs @@ -79,7 +79,7 @@ where .sender .send(RendererMessage::display_message(self.buffer.clone())) { - Ok(_) => Some(self), + Ok(()) => Some(self), Err(_) => None, } } diff --git a/lib/src/processor/memory/mmio/gpu/types.rs b/lib/src/processor/memory/mmio/gpu/types.rs index d262ff7..555edce 100644 --- a/lib/src/processor/memory/mmio/gpu/types.rs +++ b/lib/src/processor/memory/mmio/gpu/types.rs @@ -41,9 +41,9 @@ pub(super) enum TiledataArea { impl TiledataArea { pub(super) fn get_addr(&self, addr: u8) -> VramAddress { match self { - TiledataArea::D8000 => (0x8000 + ((addr as u16) * 16)).try_into().unwrap(), + TiledataArea::D8000 => (0x8000 + (u16::from(addr) * 16)).try_into().unwrap(), TiledataArea::D9000 => 0x9000_u16 - .wrapping_add_signed((as_signed(addr) as i16) * 16) + .wrapping_add_signed(i16::from(as_signed(addr)) * 16) .try_into() .unwrap(), } @@ -105,7 +105,7 @@ pub struct Colour(pub u8, pub u8, pub u8); impl From for u32 { fn from(value: Colour) -> Self { - let (r, g, b) = (value.0 as u32, value.1 as u32, value.2 as u32); + let (r, g, b) = (u32::from(value.0), u32::from(value.1), u32::from(value.2)); (r << 16) | (g << 8) | b } } @@ -335,7 +335,7 @@ impl Vram { match self { Vram::Dmg { inner } => inner[address.get_local() as usize] = data, Vram::Cgb { inner, index } => { - inner[*index as usize][address.get_local() as usize] = data + inner[*index as usize][address.get_local() as usize] = data; } } } diff --git a/lib/src/processor/memory/rom.rs b/lib/src/processor/memory/rom.rs index 141195a..09a6df2 100644 --- a/lib/src/processor/memory/rom.rs +++ b/lib/src/processor/memory/rom.rs @@ -119,7 +119,7 @@ pub enum RomSize { } impl RomSize { - pub fn from(val: u8) -> Option { + #[must_use] pub fn from(val: u8) -> Option { match val { 0x00 => Some(Self::B2), 0x01 => Some(Self::B4), @@ -137,7 +137,7 @@ impl RomSize { } } - pub fn size_bytes(&self) -> usize { + #[must_use] pub fn size_bytes(&self) -> usize { (match self { RomSize::B2 => 2, RomSize::B4 => 4, @@ -177,7 +177,7 @@ impl RamSize { } } - pub fn size_bytes(&self) -> usize { + #[must_use] pub fn size_bytes(&self) -> usize { match self { RamSize::B2 => 2 * KB, RamSize::B8 => 8 * KB, @@ -370,7 +370,7 @@ impl Rom { } } - pub fn get_title(&self) -> &String { + #[must_use] pub fn get_title(&self) -> &String { &self.title } @@ -398,7 +398,7 @@ impl Rom { self.mbc.can_rumble() } - pub fn mbc_type(&self) -> String { + #[must_use] pub fn mbc_type(&self) -> String { self.mbc.mbc_type() } diff --git a/lib/src/processor/memory/rom/licensee.rs b/lib/src/processor/memory/rom/licensee.rs index dfbe02a..fc8db41 100644 --- a/lib/src/processor/memory/rom/licensee.rs +++ b/lib/src/processor/memory/rom/licensee.rs @@ -134,7 +134,7 @@ pub enum LicenseeCode { } impl LicenseeCode { - pub fn from_header(old_licensee_code: u8, new_code: [u8; 2]) -> Self { + #[must_use] pub fn from_header(old_licensee_code: u8, new_code: [u8; 2]) -> Self { match old_licensee_code { 0x00 => Self::None, 0x01 => Self::Nintendo, diff --git a/lib/src/processor/memory/rom/mbcs/mbc3.rs b/lib/src/processor/memory/rom/mbcs/mbc3.rs index 6593c59..7e44ec2 100644 --- a/lib/src/processor/memory/rom/mbcs/mbc3.rs +++ b/lib/src/processor/memory/rom/mbcs/mbc3.rs @@ -51,15 +51,15 @@ impl Rtc { fn set_register(&mut self, rtc_register: &RtcRegister, data: u8) { let seconds_offset = match rtc_register { - RtcRegister::Seconds => data as i64 - self.get_register(&RtcRegister::Seconds) as i64, + RtcRegister::Seconds => i64::from(data) - i64::from(self.get_register(&RtcRegister::Seconds)), RtcRegister::Minutes => { - (data as i64 - self.get_register(&RtcRegister::Minutes) as i64) * 60 + (i64::from(data) - i64::from(self.get_register(&RtcRegister::Minutes))) * 60 } RtcRegister::Hours => { - (data as i64 - self.get_register(&RtcRegister::Hours) as i64) * 60 * 60 + (i64::from(data) - i64::from(self.get_register(&RtcRegister::Hours))) * 60 * 60 } RtcRegister::DayCounterLsb => { - (data as i64 - self.get_register(&RtcRegister::DayCounterLsb) as i64) * 60 * 60 * 24 + (i64::from(data) - i64::from(self.get_register(&RtcRegister::DayCounterLsb))) * 60 * 60 * 24 } RtcRegister::Misc => 0, }; @@ -112,7 +112,7 @@ impl Mbc3 { rom_size: rom_size.size_bytes(), ram, ram_bank: RamBank::Ram(0), - ram_size: ram_size.map(|s| s.size_bytes()).unwrap_or(0), + ram_size: ram_size.map_or(0, |s| s.size_bytes()), ram_enabled: false, rtc: if rtc { Some(Rtc::default()) } else { None }, } diff --git a/lib/src/processor/memory/rom/mbcs/mbc5.rs b/lib/src/processor/memory/rom/mbcs/mbc5.rs index d11011c..e94da1b 100644 --- a/lib/src/processor/memory/rom/mbcs/mbc5.rs +++ b/lib/src/processor/memory/rom/mbcs/mbc5.rs @@ -40,7 +40,7 @@ impl Mbc5 { rom_size: rom_size.size_bytes(), ram, ram_bank: 0, - ram_size: ram_size.map(|s| s.size_bytes()).unwrap_or(0), + ram_size: ram_size.map_or(0, |s| s.size_bytes()), ram_enabled: false, rumble, is_rumbling: false, @@ -82,14 +82,14 @@ impl Mbc for Mbc5 { 0x0..0x2000 => { self.ram_enabled = (data & 0xF) == 0xA; } - 0x2000..0x3000 => self.rom_bank = (self.rom_bank & 0x100) | (data as u16), - 0x3000..0x4000 => self.rom_bank = (self.rom_bank & 0xFF) | ((data as u16 & 0b1) << 8), + 0x2000..0x3000 => self.rom_bank = (self.rom_bank & 0x100) | u16::from(data), + 0x3000..0x4000 => self.rom_bank = (self.rom_bank & 0xFF) | ((u16::from(data) & 0b1) << 8), 0x4000..0x6000 => { if self.rumble { self.is_rumbling = get_bit(data, 3); self.ram_bank = data & 0x7; } else { - self.ram_bank = data & 0xF + self.ram_bank = data & 0xF; } } 0x6000..0x8000 => {} diff --git a/lib/src/processor/memory/rom/mbcs/pocketcamera.rs b/lib/src/processor/memory/rom/mbcs/pocketcamera.rs index 3d8dfdc..2512077 100644 --- a/lib/src/processor/memory/rom/mbcs/pocketcamera.rs +++ b/lib/src/processor/memory/rom/mbcs/pocketcamera.rs @@ -133,7 +133,7 @@ where } 0x2000..0x4000 => { if data < 0x40 { - self.rom_bank = data + self.rom_bank = data; } } 0x4000..0x6000 => { diff --git a/lib/src/processor/mod.rs b/lib/src/processor/mod.rs index c01990c..932a67c 100644 --- a/lib/src/processor/mod.rs +++ b/lib/src/processor/mod.rs @@ -223,10 +223,10 @@ impl SplitRegister for u16 { } fn set_low(&mut self, val: u8) { - *self = (*self & !0xff) | val as u16; + *self = (*self & !0xff) | u16::from(val); } fn set_high(&mut self, val: u8) { - *self = (*self & !0xff00) | (val as u16) << 8; + *self = (*self & !0xff00) | u16::from(val) << 8; } } diff --git a/xtask/src/args.rs b/xtask/src/args.rs index 1c07cb2..d87156c 100644 --- a/xtask/src/args.rs +++ b/xtask/src/args.rs @@ -1,6 +1,6 @@ use clap::Parser; -use crate::types::*; +use crate::types::{Architecture, Binary, Platform, Renderer}; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 577720a..3473ea5 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,8 +1,8 @@ use clap::Parser; use strum::IntoEnumIterator; -use args::*; -use types::*; +use args::{Args, BuildArgs, Commands, RunArgs}; +use types::{Architecture, Binary, CouldntSetOnceLock, Platform, Renderer, get_triple}; mod args; mod types; @@ -295,7 +295,7 @@ fn cargo_exec( println!("Building {package} with {renderer} renderer for target {triple}"); let args=format!("{verb} -q -p {package} --target {triple} {release} --no-default-features -F {renderer} --message-format=json-render-diagnostics"); - let args = args.split_whitespace().map(|s| s.to_string()); + let args = args.split_whitespace().map(std::string::ToString::to_string); let args = if let Some(additional_flags) = additional_flags { args.chain(additional_flags).collect::>() } else { @@ -338,8 +338,8 @@ fn cargo_exec( Ok( cargo_metadata::Message::parse_stream(std::io::BufReader::new(output)).inspect(move |v| { match v { - Ok(cargo_metadata::Message::BuildScriptExecuted(_)) - | Ok(cargo_metadata::Message::CompilerArtifact(_)) => { + Ok(cargo_metadata::Message::BuildScriptExecuted(_) | +cargo_metadata::Message::CompilerArtifact(_)) => { if let Some(pb) = pb.as_mut() { pb.inc(); } @@ -382,7 +382,7 @@ fn build_vst( } // we need the &str to live for this whole function - let triple_str = triple.map(|t| t.to_string()); + let triple_str = triple.map(std::string::ToString::to_string); if platform != Platform::Mac { args.push("--target"); args.push(triple_str.as_ref().unwrap().as_str()); @@ -428,8 +428,8 @@ fn build_vst( for v in cargo_metadata::Message::parse_stream(std::io::BufReader::new(output)) { match v { - Ok(cargo_metadata::Message::BuildScriptExecuted(_)) - | Ok(cargo_metadata::Message::CompilerArtifact(_)) => { + Ok(cargo_metadata::Message::BuildScriptExecuted(_) | +cargo_metadata::Message::CompilerArtifact(_)) => { if pb.as_ref().is_some_and(|pb| pb.is_finish) { pb = build_plan_iter.next().map(|(arch, num)| { let mut pb = pbr::ProgressBar::new(num.try_into().unwrap()); diff --git a/xtask/src/types.rs b/xtask/src/types.rs index f0da08b..b032fef 100644 --- a/xtask/src/types.rs +++ b/xtask/src/types.rs @@ -131,7 +131,7 @@ impl std::error::Error for CouldntSetOnceLock { None } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "description() is deprecated; use Display" }