From 58b66ae3452b9680f7a484a2341ecadb045eae64 Mon Sep 17 00:00:00 2001 From: abnormalmaps Date: Tue, 23 Sep 2025 16:02:39 -0400 Subject: [PATCH] Fix new clippy lints Change-Id: I9d4519b4d6a4b01663b43988614e045b5cbd702e --- src/app_picker.rs | 2 +- src/audio.rs | 12 ++++++++---- src/debug.rs | 2 +- src/dyld.rs | 2 +- src/environment.rs | 2 +- src/frameworks/audio_toolbox/audio_queue.rs | 4 ++-- src/frameworks/core_animation/ca_layer.rs | 3 +-- src/frameworks/foundation/ns_string.rs | 2 +- src/libc/pthread/thread.rs | 2 +- src/mach_o.rs | 2 +- src/mem.rs | 2 +- src/mem/allocator.rs | 2 +- src/stack.rs | 2 +- 13 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/app_picker.rs b/src/app_picker.rs index b6265983e..0ca40994c 100644 --- a/src/app_picker.rs +++ b/src/app_picker.rs @@ -528,7 +528,7 @@ fn show_app_picker_gui( } } fn update_scale_hack_buttons(env: &mut Environment, buttons: &[id], value: Option) { - update_quick_option_buttons(env, buttons, value.map_or(0, |v| (v.get() as usize))); + update_quick_option_buttons(env, buttons, value.map_or(0, |v| v.get() as usize)); } fn update_orientation_buttons( env: &mut Environment, diff --git a/src/audio.rs b/src/audio.rs index 3809a6bea..7b95c2b15 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -250,8 +250,10 @@ impl AudioFile { match self.0 { AudioFileInner::Wave(_) => { let bytes_per_sample = self.bytes_per_sample(); - assert!(offset % bytes_per_sample == 0); - assert!(u64::try_from(buffer.len()).unwrap() % bytes_per_sample == 0); + assert!(offset.is_multiple_of(bytes_per_sample)); + assert!(u64::try_from(buffer.len()) + .unwrap() + .is_multiple_of(bytes_per_sample)); let sample_count = u64::try_from(buffer.len()).unwrap() / bytes_per_sample; let sample_count: usize = sample_count.try_into().unwrap(); @@ -287,8 +289,10 @@ impl AudioFile { AudioFileInner::Caf(_) => { // variable size not implemented let packet_size = self.packet_size_fixed(); - assert!(offset % u64::from(packet_size) == 0); - assert!(u64::try_from(buffer.len()).unwrap() % u64::from(packet_size) == 0); + assert!(offset.is_multiple_of(packet_size.into())); + assert!(u64::try_from(buffer.len()) + .unwrap() + .is_multiple_of(packet_size.into())); let packet_count = u64::try_from(buffer.len()).unwrap() / u64::from(packet_size); diff --git a/src/debug.rs b/src/debug.rs index 43ea0a0bd..1184ba9b8 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -21,7 +21,7 @@ pub fn write_ppm(path: &str, width: u32, height: u32, pixels: &[u8]) { /// Convert RGBA8 pixel data to RGB8 pixel data by discarding alpha component. /// Useful with [write_ppm] for example. pub fn rgba8_to_rgb8(pixels: &[u8]) -> Vec { - assert!(pixels.len() % 4 == 0); + assert!(pixels.len().is_multiple_of(4)); let mut res = Vec::with_capacity((pixels.len() / 4) * 3); for rgba in pixels.chunks(4) { res.extend_from_slice(&rgba[..3]); diff --git a/src/dyld.rs b/src/dyld.rs index bbd7b688c..24bbeb1fc 100644 --- a/src/dyld.rs +++ b/src/dyld.rs @@ -656,7 +656,7 @@ impl Dyld { let info = stubs.dyld_indirect_symbol_info.as_ref().unwrap(); let offset = svc_pc - stubs.addr; - assert!(offset % info.entry_size == 0); + assert!(offset.is_multiple_of(info.entry_size)); let idx = (offset / info.entry_size) as usize; let symbol = info.indirect_undef_symbols[idx].as_deref().unwrap(); diff --git a/src/environment.rs b/src/environment.rs index e23c1f3ef..6ef162a52 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -687,7 +687,7 @@ impl Environment { ) -> ThreadId { let stack_alloc = self.mem.alloc(stack_size); let stack_high_addr = stack_alloc.to_bits() + stack_size; - assert!(stack_high_addr % 4 == 0); + assert!(stack_high_addr.is_multiple_of(4)); self.threads.push(Thread { active: true, diff --git a/src/frameworks/audio_toolbox/audio_queue.rs b/src/frameworks/audio_toolbox/audio_queue.rs index 1aee15fe5..8e482d56e 100644 --- a/src/frameworks/audio_toolbox/audio_queue.rs +++ b/src/frameworks/audio_toolbox/audio_queue.rs @@ -500,7 +500,7 @@ pub fn decode_buffer( match format.format_id { kAudioFormatAppleIMA4 => { - assert!(data_slice.len() % 34 == 0); + assert!(data_slice.len().is_multiple_of(34)); let mut out_pcm = Vec::::with_capacity((data_slice.len() / 34) * 64 * 2); let packets = data_slice.chunks(34); @@ -595,7 +595,7 @@ pub fn decode_buffer( (2, 16) => al::AL_FORMAT_STEREO16, (2, 32) => { assert!((format.format_flags & kAudioFormatFlagIsSignedInteger) != 0); - assert!(processed_data.len() % 4 == 0); + assert!(processed_data.len().is_multiple_of(4)); let new_size = (processed_data.len() / 4) * 2; // size from 32-bit to 16-bit let mut new_processed_data = Vec::::with_capacity(new_size); for chunk in processed_data.chunks(4) { diff --git a/src/frameworks/core_animation/ca_layer.rs b/src/frameworks/core_animation/ca_layer.rs index 0e365047d..128b80e3c 100644 --- a/src/frameworks/core_animation/ca_layer.rs +++ b/src/frameworks/core_animation/ca_layer.rs @@ -333,10 +333,9 @@ pub const CLASSES: ClassExports = objc_classes! { let int_width = size.width.round() as GuestUSize; let int_height = size.height.round() as GuestUSize; - let need_new_context = cg_context.is_none_or(|existing| ( + let need_new_context = cg_context.is_none_or(|existing| CGBitmapContextGetWidth(env, existing) != int_width || CGBitmapContextGetHeight(env, existing) != int_height - ) ); let cg_context = if need_new_context { if let Some(old_context) = cg_context { diff --git a/src/frameworks/foundation/ns_string.rs b/src/frameworks/foundation/ns_string.rs index b39c6b98d..8a8befe53 100644 --- a/src/frameworks/foundation/ns_string.rs +++ b/src/frameworks/foundation/ns_string.rs @@ -136,7 +136,7 @@ impl StringHostObject { NSUTF16StringEncoding | NSUTF16BigEndianStringEncoding | NSUTF16LittleEndianStringEncoding => { - assert!(bytes.len() % 2 == 0); + assert!(bytes.len().is_multiple_of(2)); let is_big_endian = match encoding { NSUTF16BigEndianStringEncoding => true, diff --git a/src/libc/pthread/thread.rs b/src/libc/pthread/thread.rs index 5b3588687..648d6b00a 100644 --- a/src/libc/pthread/thread.rs +++ b/src/libc/pthread/thread.rs @@ -110,7 +110,7 @@ pub fn pthread_attr_setstacksize( attr: MutPtr, stacksize: GuestUSize, ) -> i32 { - if attr.is_null() || stacksize < PTHREAD_STACK_MIN || stacksize % PAGE_SIZE != 0 { + if attr.is_null() || stacksize < PTHREAD_STACK_MIN || stacksize.is_multiple_of(PAGE_SIZE) { return EINVAL; } check_magic!(env, attr, MAGIC_ATTR); diff --git a/src/mach_o.rs b/src/mach_o.rs index 9d2187803..9b4a75310 100644 --- a/src/mach_o.rs +++ b/src/mach_o.rs @@ -644,7 +644,7 @@ impl MachO { }; let dyld_indirect_symbol_info = dyld_entry_size.map(|entry_size| { let indirect_start = section.reserved1 as usize; - assert!(size % entry_size == 0); + assert!(size.is_multiple_of(entry_size)); let indirect_count = (size / entry_size) as usize; let indirects = &mut indirect_undef_symbols[indirect_start..][..indirect_count]; let syms = indirects.iter_mut().map(|sym| sym.take()).collect(); diff --git a/src/mem.rs b/src/mem.rs index 461f1ea34..eca51fe95 100644 --- a/src/mem.rs +++ b/src/mem.rs @@ -323,7 +323,7 @@ impl Mem { // segments they shouldn't be able to. Adding that would fix // this, along with removing this special case. assert!(self.null_segment_size == 0); - assert!(new_null_segment_size % 0x1000 == 0); + assert!(new_null_segment_size.is_multiple_of(0x1000)); self.allocator .reserve(allocator::Chunk::new(0, new_null_segment_size)); self.null_segment_size = new_null_segment_size; diff --git a/src/mem/allocator.rs b/src/mem/allocator.rs index cc7a4e026..66304219d 100644 --- a/src/mem/allocator.rs +++ b/src/mem/allocator.rs @@ -334,7 +334,7 @@ impl Allocator { } fn align(size: GuestUSize, align: GuestUSize) -> GuestUSize { - if size % align != 0 { + if size.is_multiple_of(align) { size + align - (size % align) } else { size diff --git a/src/stack.rs b/src/stack.rs index de80bd0b6..c6d8fda03 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -107,7 +107,7 @@ pub fn prep_stack_for_start( // mem.cstr_at_utf8(MutPtr::from_bits(mem.read((stack_ptr + 4).cast()))) //); - assert!(stack_height % 4 == 0); // ensure padding worked properly + assert!(stack_height.is_multiple_of(4)); // ensure padding worked properly cpu.regs_mut()[Cpu::SP] = stack_ptr.to_bits(); }