Fix new clippy lints

Change-Id: I9d4519b4d6a4b01663b43988614e045b5cbd702e
This commit is contained in:
abnormalmaps
2025-09-23 16:02:39 -04:00
parent 1f8125cbe0
commit 58b66ae345
13 changed files with 21 additions and 18 deletions

View File

@@ -528,7 +528,7 @@ fn show_app_picker_gui(
}
}
fn update_scale_hack_buttons(env: &mut Environment, buttons: &[id], value: Option<NonZeroU32>) {
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,

View File

@@ -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);

View File

@@ -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<u8> {
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]);

View File

@@ -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();

View File

@@ -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,

View File

@@ -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::<u8>::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::<u8>::with_capacity(new_size);
for chunk in processed_data.chunks(4) {

View File

@@ -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 {

View File

@@ -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,

View File

@@ -110,7 +110,7 @@ pub fn pthread_attr_setstacksize(
attr: MutPtr<pthread_attr_t>,
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);

View File

@@ -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();

View File

@@ -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;

View File

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

View File

@@ -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();
}