From 3b1bdea1dd16ea0c80144cec89afcc90792aecca Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Thu, 17 Jul 2025 17:47:24 +0300 Subject: [PATCH] maint: fix clippy warnings --- boot/yboot/src/initrd.rs | 2 +- boot/yboot/src/mem.rs | 2 +- kernel/arch/aarch64/build.rs | 2 +- kernel/arch/aarch64/src/mem/mod.rs | 1 + kernel/arch/x86/src/gdt.rs | 6 +- kernel/build.rs | 6 +- kernel/driver/acpi/src/mem.rs | 6 ++ kernel/driver/block/nvme/src/queue.rs | 2 +- kernel/driver/block/scsi/src/lib.rs | 14 ++-- kernel/driver/block/scsi/src/transport.rs | 2 +- kernel/driver/bus/pci/src/lib.rs | 4 +- kernel/driver/bus/pci/src/space/mod.rs | 2 +- .../bus/usb/src/class_driver/mass_storage.rs | 2 +- kernel/driver/bus/usb/src/class_driver/mod.rs | 2 +- kernel/driver/fs/fat32/src/data.rs | 3 +- kernel/driver/fs/fat32/src/directory.rs | 4 +- kernel/driver/fs/fat32/src/lib.rs | 1 + kernel/driver/fs/memfs/src/tar.rs | 2 +- kernel/driver/net/core/src/interface.rs | 2 +- kernel/driver/net/core/src/l3/mod.rs | 4 +- kernel/driver/net/core/src/socket/config.rs | 2 +- .../net/core/src/socket/local/packet.rs | 6 +- kernel/driver/net/core/src/socket/raw.rs | 4 +- kernel/driver/net/rtl81xx/src/rtl8139.rs | 16 ++--- kernel/driver/net/stmmac/src/ring.rs | 2 +- kernel/driver/usb/xhci/src/pipe.rs | 4 +- kernel/driver/usb/xhci/src/regs/mod.rs | 6 +- kernel/driver/virtio/core/src/lib.rs | 1 + kernel/lib/device-tree/src/driver/tree.rs | 8 +-- kernel/libk/libk-mm/interface/src/device.rs | 9 +++ kernel/libk/libk-mm/src/lib.rs | 8 +++ kernel/libk/libk-util/src/string.rs | 3 + kernel/libk/src/debug/ring.rs | 2 +- kernel/libk/src/device/block/partition/mbr.rs | 4 +- kernel/libk/src/device/display/fb_console.rs | 2 +- kernel/libk/src/dma.rs | 6 ++ kernel/libk/src/task/process.rs | 2 +- kernel/libk/src/task/runtime/executor.rs | 2 +- kernel/libk/src/task/thread.rs | 4 +- kernel/libk/src/vfs/file/mod.rs | 4 +- kernel/src/arch/aarch64/boot/mod.rs | 2 +- kernel/src/arch/aarch64/gic/gicv2m.rs | 2 +- kernel/src/arch/riscv64/boot/mod.rs | 2 +- kernel/src/arch/x86_64/exception.rs | 4 +- kernel/src/arch/x86_64/mod.rs | 16 ++--- kernel/src/device/clock/bcm2835_aux.rs | 2 +- kernel/src/device/clock/jh7110_aoncrg.rs | 2 +- kernel/src/device/clock/jh7110_syscrg.rs | 2 +- lib/abi-serde/src/impls/base.rs | 8 +-- lib/abi/src/net/types/mod.rs | 2 +- lib/abi/src/process/exit.rs | 6 +- lib/libyalloc/src/bucket.rs | 4 +- lib/runtime/build.rs | 2 +- userspace/dyn-loader/src/main.rs | 6 +- .../graphics/colors/src/bin/colors-bar.rs | 1 + userspace/graphics/colors/src/main.rs | 3 +- userspace/graphics/term/src/attr.rs | 2 +- userspace/graphics/term/src/main.rs | 4 +- userspace/graphics/term/src/state.rs | 24 +++---- .../lib/libcolors/src/application/window.rs | 2 +- userspace/lib/uipc/src/lib.rs | 5 +- userspace/lib/ygglibc/build.rs | 4 +- userspace/lib/ygglibc/src/env.rs | 2 +- .../lib/ygglibc/src/headers/libgen/mod.rs | 2 +- .../ygglibc/src/headers/stdio/printf/float.rs | 2 +- .../lib/ygglibc/src/headers/strings/mod.rs | 1 + .../lib/ygglibc/src/headers/wctype/alpha.rs | 10 +-- .../lib/ygglibc/src/headers/wctype/casecmp.rs | 5 +- .../lib/ygglibc/src/headers/wctype/mod.rs | 2 +- .../lib/ygglibc/src/headers/wctype/punct.rs | 5 +- userspace/lib/ygglibc/src/io/managed.rs | 10 +-- userspace/lib/ygglibc/src/panic.rs | 2 +- userspace/lib/ygglibc/src/process.rs | 2 +- userspace/lib/ygglibc/src/signal.rs | 6 +- userspace/lib/ygglibc/src/util.rs | 1 + userspace/netutils/src/dhcp_client.rs | 6 +- userspace/sysutils/src/top.rs | 61 ++++++++-------- userspace/tools/md2txt/src/setting.rs | 13 ++-- userspace/tools/shell/src/command/eval.rs | 16 ++--- userspace/tools/shell/src/command/mod.rs | 3 +- userspace/tools/shell/src/main.rs | 2 +- userspace/tools/shell/src/readline.rs | 12 ++-- userspace/tools/strace/src/format.rs | 29 ++++---- userspace/tools/strace/src/tracer.rs | 69 ++++++++++--------- 84 files changed, 269 insertions(+), 261 deletions(-) diff --git a/boot/yboot/src/initrd.rs b/boot/yboot/src/initrd.rs index 77d5bdb4..46edb2b7 100644 --- a/boot/yboot/src/initrd.rs +++ b/boot/yboot/src/initrd.rs @@ -25,7 +25,7 @@ pub fn load_somewhere( let file_info: &FileInfo = file.get_info(&mut info_buffer).unwrap(); let size = file_info.file_size(); - let page_count = (size + 0xFFF) / 0x1000; + let page_count = size.div_ceil(0x1000); let base = bs.allocate_pages( AllocateType::MaxAddress(MAXIMUM_ADDRESS), diff --git a/boot/yboot/src/mem.rs b/boot/yboot/src/mem.rs index 272bc87b..1240c964 100644 --- a/boot/yboot/src/mem.rs +++ b/boot/yboot/src/mem.rs @@ -66,7 +66,7 @@ impl MemoryDescriptorExt for MemoryDescriptor { } } -pub fn memory_map(bs: &BootServices) -> Result { +pub fn memory_map(bs: &BootServices) -> Result, Error> { bs.memory_map(unsafe { &mut MMAP_BUFFER.data }) } diff --git a/kernel/arch/aarch64/build.rs b/kernel/arch/aarch64/build.rs index 21c01357..cae74b05 100644 --- a/kernel/arch/aarch64/build.rs +++ b/kernel/arch/aarch64/build.rs @@ -5,7 +5,7 @@ fn build_fp_context_obj() { let out_dir = env::var("OUT_DIR").unwrap(); - println!("cargo:rerun-if-changed={}", FP_CONTEXT_S); + println!("cargo:rerun-if-changed={FP_CONTEXT_S}"); cc::Build::new() .out_dir(&out_dir) diff --git a/kernel/arch/aarch64/src/mem/mod.rs b/kernel/arch/aarch64/src/mem/mod.rs index d18d2fcf..38d9d3b7 100644 --- a/kernel/arch/aarch64/src/mem/mod.rs +++ b/kernel/arch/aarch64/src/mem/mod.rs @@ -1,3 +1,4 @@ +#![allow(clippy::missing_safety_doc)] use aarch64_cpu::{ asm::barrier, registers::{MAIR_EL1, SCTLR_EL1, TCR_EL1}, diff --git a/kernel/arch/x86/src/gdt.rs b/kernel/arch/x86/src/gdt.rs index 65a0533f..bb9a8054 100644 --- a/kernel/arch/x86/src/gdt.rs +++ b/kernel/arch/x86/src/gdt.rs @@ -1,5 +1,5 @@ #[allow(dead_code)] -#[repr(packed)] +#[repr(C, packed)] pub struct Entry { pub limit_lo: u16, pub base_lo: u16, @@ -10,7 +10,7 @@ pub struct Entry { } #[allow(dead_code)] -#[repr(packed)] +#[repr(C, packed)] pub struct Pointer { pub limit: u16, pub offset: usize, @@ -121,7 +121,7 @@ mod imp { use super::{Entry, Pointer}; #[allow(dead_code)] - #[repr(packed)] + #[repr(C, packed)] pub struct Tss { _0: u32, rsp0: u64, diff --git a/kernel/build.rs b/kernel/build.rs index b5fe8a4e..e1912380 100644 --- a/kernel/build.rs +++ b/kernel/build.rs @@ -15,7 +15,7 @@ fn build_x86_64() { const DEFAULT_8086_AS: &str = "nasm"; const AP_BOOTSTRAP_S: &str = "src/arch/x86_64/boot/ap_boot.S"; - println!("cargo:rerun-if-changed={}", AP_BOOTSTRAP_S); + println!("cargo:rerun-if-changed={AP_BOOTSTRAP_S}"); let out_dir = env::var("OUT_DIR").unwrap(); let assembler = env::var("AS8086").unwrap_or(DEFAULT_8086_AS.to_owned()); @@ -35,7 +35,7 @@ fn build_x86_64() { if !output.status.success() { io::stderr().write_all(&output.stderr).ok(); - panic!("{}: could not assemble {}", assembler, AP_BOOTSTRAP_S); + panic!("{assembler}: could not assemble {AP_BOOTSTRAP_S}"); } } @@ -93,6 +93,6 @@ fn main() { "x86_64" => build_x86_64(), "aarch64" => (), "riscv64" => (), - _ => panic!("Unknown target arch: {:?}", arch), + _ => panic!("Unknown target arch: {arch:?}"), } } diff --git a/kernel/driver/acpi/src/mem.rs b/kernel/driver/acpi/src/mem.rs index b3f7019b..01bd18df 100644 --- a/kernel/driver/acpi/src/mem.rs +++ b/kernel/driver/acpi/src/mem.rs @@ -35,6 +35,9 @@ unsafe impl Allocator for AcpiAllocator { } // TODO don't map memory as device if not necessary +/// # Safety +/// +/// Allows direct reads from physical memory, unsafe pub unsafe fn read_memory(address: PhysicalAddress) -> T { let io = unsafe { DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap() }; @@ -49,6 +52,9 @@ pub unsafe fn read_memory(address: PhysicalAddress) -> T { } } +/// # Safety +/// +/// Allows direct writes to physical memory, unsafe pub unsafe fn write_memory(address: PhysicalAddress, value: T) { let io = unsafe { DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap() }; diff --git a/kernel/driver/block/nvme/src/queue.rs b/kernel/driver/block/nvme/src/queue.rs index 633b5796..3aa4254d 100644 --- a/kernel/driver/block/nvme/src/queue.rs +++ b/kernel/driver/block/nvme/src/queue.rs @@ -129,7 +129,7 @@ impl PrpList { list: None, }), _ => { - let count = (size + 0xFFF) / 0x1000; + let count = size.div_ceil(0x1000); let list = DmaBuffer::new_slice_with(dma, |i| base.add((i + 1) * 0x1000), count - 1) .map_err(NvmeError::MemoryError)?; diff --git a/kernel/driver/block/scsi/src/lib.rs b/kernel/driver/block/scsi/src/lib.rs index 6d0ad86c..6173462c 100644 --- a/kernel/driver/block/scsi/src/lib.rs +++ b/kernel/driver/block/scsi/src/lib.rs @@ -71,10 +71,10 @@ impl ScsiEnclosure { // Probe LUNs for i in 0..lun_count { - if this.probe_lun(i as u8).await { - if let Ok(unit) = ScsiUnit::setup(this.clone(), i as u8).await { - *this.units[i].write() = Some(unit); - } + if this.probe_lun(i as u8).await + && let Ok(unit) = ScsiUnit::setup(this.clone(), i as u8).await + { + *this.units[i].write() = Some(unit); } } @@ -117,11 +117,7 @@ impl ScsiEnclosure { attempts -= 1; } - if attempts == 0 { - false - } else { - true - } + attempts != 0 } async fn poll(self: &Arc) { diff --git a/kernel/driver/block/scsi/src/transport.rs b/kernel/driver/block/scsi/src/transport.rs index 68bedd93..549dc7fe 100644 --- a/kernel/driver/block/scsi/src/transport.rs +++ b/kernel/driver/block/scsi/src/transport.rs @@ -44,7 +44,7 @@ impl ScsiTransportWrapper { return Err(Error::InvalidArgument); } let lba_bytes = (lba as u32).to_be_bytes(); - let lba_count = (lba_count as u16).to_be_bytes(); + let lba_count = lba_count.to_be_bytes(); // Issue a READ (10) command let request_buffer = [ 0x28, diff --git a/kernel/driver/bus/pci/src/lib.rs b/kernel/driver/bus/pci/src/lib.rs index f83ede26..9cf330a3 100644 --- a/kernel/driver/bus/pci/src/lib.rs +++ b/kernel/driver/bus/pci/src/lib.rs @@ -1,7 +1,7 @@ //! PCI/PCIe bus interfaces #![no_std] #![feature(let_chains, decl_macro)] -#![allow(clippy::missing_transmute_annotations)] +#![allow(clippy::missing_transmute_annotations, clippy::identity_op)] extern crate alloc; @@ -466,7 +466,7 @@ impl PciBusManager { for segment in this.segments.iter_mut() { for device in segment.devices.iter_mut() { let mut device = device.lock(); - if !f(&mut *device)? { + if !f(&mut device)? { return Ok(()); } } diff --git a/kernel/driver/bus/pci/src/space/mod.rs b/kernel/driver/bus/pci/src/space/mod.rs index 9035627a..6b8326bf 100644 --- a/kernel/driver/bus/pci/src/space/mod.rs +++ b/kernel/driver/bus/pci/src/space/mod.rs @@ -374,7 +374,7 @@ pub trait PciConfigurationSpace { /// Locates a capability within this configuration space fn capability(&self) -> Option> { self.capability_iter().find_map(|(id, offset, len)| { - if id.map_or(false, |id| id == C::ID) && C::check(self, offset, len) { + if id == Some(C::ID) && C::check(self, offset, len) { Some(C::data(self, offset, len)) } else { None diff --git a/kernel/driver/bus/usb/src/class_driver/mass_storage.rs b/kernel/driver/bus/usb/src/class_driver/mass_storage.rs index 9d0728a8..c820a91c 100644 --- a/kernel/driver/bus/usb/src/class_driver/mass_storage.rs +++ b/kernel/driver/bus/usb/src/class_driver/mass_storage.rs @@ -131,7 +131,7 @@ impl Bbb { &mut self, buffer: DmaSliceMut<'_, MaybeUninit>, ) -> Result { - if buffer.len() == 0 { + if buffer.is_empty() { return Ok(0); } let len = self diff --git a/kernel/driver/bus/usb/src/class_driver/mod.rs b/kernel/driver/bus/usb/src/class_driver/mod.rs index 6979aa45..2040759c 100644 --- a/kernel/driver/bus/usb/src/class_driver/mod.rs +++ b/kernel/driver/bus/usb/src/class_driver/mod.rs @@ -36,7 +36,7 @@ async fn extract_class_info(device: &UsbDeviceAccess) -> Result= 1 { + if !config_info.interfaces.is_empty() { let if_info = &config_info.interfaces[0]; let class = if device_info.device_class == UsbDeviceClass::FromInterface { diff --git a/kernel/driver/fs/fat32/src/data.rs b/kernel/driver/fs/fat32/src/data.rs index 7a57f62b..96e42d26 100644 --- a/kernel/driver/fs/fat32/src/data.rs +++ b/kernel/driver/fs/fat32/src/data.rs @@ -160,8 +160,7 @@ impl Fat32FsInfo { let signature0 = &self.bytes[0..4]; let signature1 = &self.bytes[484..488]; - signature0 == &Self::SIGNATURE0.to_le_bytes() - && signature1 == &Self::SIGNATURE1.to_le_bytes() + signature0 == Self::SIGNATURE0.to_le_bytes() && signature1 == Self::SIGNATURE1.to_le_bytes() } } diff --git a/kernel/driver/fs/fat32/src/directory.rs b/kernel/driver/fs/fat32/src/directory.rs index cd255584..f2428e3f 100644 --- a/kernel/driver/fs/fat32/src/directory.rs +++ b/kernel/driver/fs/fat32/src/directory.rs @@ -303,7 +303,7 @@ impl CommonImpl for DirectoryNode { } fn metadata(&self, _node: &NodeRef) -> Result { - Ok(self.metadata.clone()) + Ok(self.metadata) } fn set_metadata(&self, _node: &NodeRef, _metadata: &Metadata) -> Result<(), Error> { @@ -357,7 +357,7 @@ impl DirectoryImpl for DirectoryNode { } fn len(&self, _node: &NodeRef) -> Result { - Ok((self.size_bytes.unwrap_or(0) as u32 / DIRENT_SIZE as u32) as usize) + Ok((self.size_bytes.unwrap_or(0) / DIRENT_SIZE as u32) as usize) } } diff --git a/kernel/driver/fs/fat32/src/lib.rs b/kernel/driver/fs/fat32/src/lib.rs index fb60a060..480de9ec 100644 --- a/kernel/driver/fs/fat32/src/lib.rs +++ b/kernel/driver/fs/fat32/src/lib.rs @@ -54,6 +54,7 @@ impl Fat32Fs { ) -> Result { let mut cached = true; for option in options { + #[allow(clippy::single_match)] match option { FilesystemMountOption::Sync => cached = false, _ => (), diff --git a/kernel/driver/fs/memfs/src/tar.rs b/kernel/driver/fs/memfs/src/tar.rs index 8f2c236d..fb6a8d76 100644 --- a/kernel/driver/fs/memfs/src/tar.rs +++ b/kernel/driver/fs/memfs/src/tar.rs @@ -16,7 +16,7 @@ pub(crate) struct TarIterator<'a> { zero_blocks: usize, } -#[repr(packed)] +#[repr(C, packed)] pub(crate) struct TarEntry { pub name: TarString<100>, pub mode: OctalField<8>, diff --git a/kernel/driver/net/core/src/interface.rs b/kernel/driver/net/core/src/interface.rs index 71c87521..f558675e 100644 --- a/kernel/driver/net/core/src/interface.rs +++ b/kernel/driver/net/core/src/interface.rs @@ -127,7 +127,7 @@ pub fn register_interface( NetworkInterfaceType::Ethernet => { static LAST_ETHERNET_ID: AtomicUsize = AtomicUsize::new(0); let eth_id = LAST_ETHERNET_ID.fetch_add(1, Ordering::SeqCst); - format!("eth{}", eth_id).into_boxed_str() + format!("eth{eth_id}").into_boxed_str() } NetworkInterfaceType::Loopback => "lo".into(), }; diff --git a/kernel/driver/net/core/src/l3/mod.rs b/kernel/driver/net/core/src/l3/mod.rs index 0be38381..2ecf2b0e 100644 --- a/kernel/driver/net/core/src/l3/mod.rs +++ b/kernel/driver/net/core/src/l3/mod.rs @@ -133,7 +133,7 @@ impl Route { pub fn insert(route: Self) -> Result<(), Error> { // TODO check for conflicts - log::debug!("Add route: {}", route); + log::debug!("Add route: {route}"); ROUTES.write().push(route); Ok(()) } @@ -143,7 +143,7 @@ impl fmt::Display for Route { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{} ", self.subnet)?; if let Some(gw) = self.gateway { - write!(f, " via {}", gw)?; + write!(f, " via {gw}")?; } Ok(()) } diff --git a/kernel/driver/net/core/src/socket/config.rs b/kernel/driver/net/core/src/socket/config.rs index 6da75275..5982fc08 100644 --- a/kernel/driver/net/core/src/socket/config.rs +++ b/kernel/driver/net/core/src/socket/config.rs @@ -262,7 +262,7 @@ fn describe_route(route: &Route) -> RouteInfo { interface_name: interface.name.clone(), interface_id: route.interface, subnet: route.subnet, - gateway: route.gateway.map(Into::into), + gateway: route.gateway, } } diff --git a/kernel/driver/net/core/src/socket/local/packet.rs b/kernel/driver/net/core/src/socket/local/packet.rs index d54f9924..1c10d1c0 100644 --- a/kernel/driver/net/core/src/socket/local/packet.rs +++ b/kernel/driver/net/core/src/socket/local/packet.rs @@ -110,9 +110,9 @@ impl LocalPacketSocket { /// /// 1. If this socket is bound to a name, the name will be used /// 2. Otherwise: - /// 2.1. If `remote` is "known" by this socket, the address in the table will be used - /// 2.2. Otherwise, this socket is "paired" with the remote by generating a new anonymous - /// address unique to that socket + /// 2.1. If `remote` is "known" by this socket, the address in the table will be used + /// 2.2. Otherwise, this socket is "paired" with the remote by generating a new anonymous + /// address unique to that socket fn get_send_info( self: &Arc, remote: &OwnedAddress, diff --git a/kernel/driver/net/core/src/socket/raw.rs b/kernel/driver/net/core/src/socket/raw.rs index b7695122..567914e7 100644 --- a/kernel/driver/net/core/src/socket/raw.rs +++ b/kernel/driver/net/core/src/socket/raw.rs @@ -81,7 +81,7 @@ impl RawSocket { }; for id in ids { - if except.map_or(false, |i| i == *id) { + if except == Some(*id) { continue; } @@ -210,7 +210,7 @@ impl Socket for RawSocket { if message.payload.len() > 1024 { return Err(Error::InvalidArgument); } - let mut builder = TxPacketBuilder::new(&*interface, message.payload.len())?; + let mut builder = TxPacketBuilder::new(&interface, message.payload.len())?; builder.push_bytes(message.payload)?; // false to prevent loopback builder.transmit(Some(self.id))?; diff --git a/kernel/driver/net/rtl81xx/src/rtl8139.rs b/kernel/driver/net/rtl81xx/src/rtl8139.rs index 2fbc420a..24bb96f6 100644 --- a/kernel/driver/net/rtl81xx/src/rtl8139.rs +++ b/kernel/driver/net/rtl81xx/src/rtl8139.rs @@ -320,14 +320,14 @@ impl InterruptHandler for Rtl8139 { let rx_len_1 = unsafe { rx.buffer[rx_pos + 3].assume_init() }; let rx_len = u16::from_le_bytes([rx_len_0, rx_len_1]) as usize; - if rx_len >= 16 { - if let Ok(mut packet_buf) = DmaBuffer::new_uninit_slice(&*self.dma, rx_len) { - packet_buf.copy_from_slice(&rx.buffer[rx_pos + 4..rx_pos + rx_len + 4]); - let packet_buf = unsafe { DmaBuffer::assume_init_slice(packet_buf) }; - // let packet_buf = unsafe { packet_buf.assume_init_slice() }; - let packet = RxPacket::new(packet_buf, 0, nic); - ygg_driver_net_core::receive_packet(packet).ok(); - } + if rx_len >= 16 + && let Ok(mut packet_buf) = DmaBuffer::new_uninit_slice(&*self.dma, rx_len) + { + packet_buf.copy_from_slice(&rx.buffer[rx_pos + 4..rx_pos + rx_len + 4]); + let packet_buf = unsafe { DmaBuffer::assume_init_slice(packet_buf) }; + // let packet_buf = unsafe { packet_buf.assume_init_slice() }; + let packet = RxPacket::new(packet_buf, 0, nic); + ygg_driver_net_core::receive_packet(packet).ok(); } // rx_len + 4, aligned to 4 bytes diff --git a/kernel/driver/net/stmmac/src/ring.rs b/kernel/driver/net/stmmac/src/ring.rs index 342c823a..3de58cee 100644 --- a/kernel/driver/net/stmmac/src/ring.rs +++ b/kernel/driver/net/stmmac/src/ring.rs @@ -197,7 +197,7 @@ impl RxRing { let index = self.rd % self.entries.len(); let entry = &mut self.entries[index]; - if let Some(_) = entry.rx_completed() { + if entry.rx_completed().is_some() { // Grab the current buffer (the one just written to by the DMA), replace it // with the newly allocated one, and mark the descriptor as DMA-owned again let new_buffer = DmaBuffer::new_uninit_slice(dma, 4096)?; diff --git a/kernel/driver/usb/xhci/src/pipe.rs b/kernel/driver/usb/xhci/src/pipe.rs index 45008a25..d5ae0041 100644 --- a/kernel/driver/usb/xhci/src/pipe.rs +++ b/kernel/driver/usb/xhci/src/pipe.rs @@ -143,14 +143,14 @@ impl UsbControlPipe for ControlPipe { setup: ControlTransferSetup, buffer: &[u8], ) -> Result { - let mut dma_buffer = + let dma_buffer = DmaBuffer::from_slice(&*self.xhci.dma, buffer).map_err(UsbError::MemoryError)?; self.ring .control_transfer( self.xhci.as_ref(), setup, - ControlDataStage::Out(&mut dma_buffer), + ControlDataStage::Out(&dma_buffer), ) .await } diff --git a/kernel/driver/usb/xhci/src/regs/mod.rs b/kernel/driver/usb/xhci/src/regs/mod.rs index 20de0684..2034b76c 100644 --- a/kernel/driver/usb/xhci/src/regs/mod.rs +++ b/kernel/driver/usb/xhci/src/regs/mod.rs @@ -161,9 +161,9 @@ pub fn portsc_to_neutral( portsc.bitand(RO_MASK | RWS_MASK) } -impl Into for PortNumber { - fn into(self) -> u8 { - self.0 +impl From for u8 { + fn from(value: PortNumber) -> Self { + value.0 } } diff --git a/kernel/driver/virtio/core/src/lib.rs b/kernel/driver/virtio/core/src/lib.rs index 85b7491e..cb39ce34 100644 --- a/kernel/driver/virtio/core/src/lib.rs +++ b/kernel/driver/virtio/core/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::new_without_default)] #![no_std] extern crate alloc; diff --git a/kernel/lib/device-tree/src/driver/tree.rs b/kernel/lib/device-tree/src/driver/tree.rs index 0ca2ddae..fec06cb1 100644 --- a/kernel/lib/device-tree/src/driver/tree.rs +++ b/kernel/lib/device-tree/src/driver/tree.rs @@ -131,7 +131,7 @@ impl Node { let inner = self .device - .or_init_with(|| match Self::probe_single(&self, &mut cx) { + .or_init_with(|| match Self::probe_single(self, &mut cx) { Some(probed) => NodeDevice::Present(probed), None => NodeDevice::Missing, }); @@ -270,11 +270,9 @@ impl Node { } fn make_init_context(&self) -> DeviceInitContext { - let cx = DeviceInitContext { + DeviceInitContext { dma_allocator: Arc::new(DummyDmaAllocator), - }; - - cx + } } /// Returns an iterator over the node's children diff --git a/kernel/libk/libk-mm/interface/src/device.rs b/kernel/libk/libk-mm/interface/src/device.rs index a2d7543a..11403a29 100644 --- a/kernel/libk/libk-mm/interface/src/device.rs +++ b/kernel/libk/libk-mm/interface/src/device.rs @@ -44,6 +44,9 @@ pub trait DevicePageTableLevel { None } + /// # Safety + /// + /// Removes validity of memory regions, unsafe. unsafe fn remove_mapping(&mut self, base: usize, page_count: usize) { let base_index = (base - Self::VIRTUAL_BASE) / Self::Level::SIZE; for i in 0..page_count { @@ -62,6 +65,9 @@ impl DevicePageManager { Self { normal, large } } + /// # Safety + /// + /// Provides ability to map arbitrary ranges of memory, unsafe. pub unsafe fn map_device_pages( &mut self, base: PhysicalAddress, @@ -112,6 +118,9 @@ impl DevicePageManager { } } + /// # Safety + /// + /// Removes validity of memory regions, unsafe. pub unsafe fn unmap_device_pages( &mut self, mapping: &RawDeviceMemoryMapping, diff --git a/kernel/libk/libk-mm/src/lib.rs b/kernel/libk/libk-mm/src/lib.rs index 1f819542..69db9c7f 100644 --- a/kernel/libk/libk-mm/src/lib.rs +++ b/kernel/libk/libk-mm/src/lib.rs @@ -135,6 +135,10 @@ impl PageBox { Ok(result) } + /// # Safety + /// + /// Unsafe: converts a raw physical address back into a [PageBox]. Only intended to be used + /// for allocations previously converted to [PhysicalAddress] via [PageBox::into_physical_raw]. pub unsafe fn from_physical_raw(address: PhysicalAddress) -> PageBox { PageBox::from_physical_raw_in(address) } @@ -249,6 +253,10 @@ impl> PageBox { Ok(result) } + /// # Safety + /// + /// Unsafe: converts a raw physical address back into a [PageBox]. Only intended to be used + /// for allocations previously converted to [PhysicalAddress] via [PageBox::into_physical_raw]. pub unsafe fn from_physical_raw_in(address: PhysicalAddress) -> PageBox { let page_count = size_of::().div_ceil(L3_PAGE_SIZE); let value = address.virtualize() as *mut T; diff --git a/kernel/libk/libk-util/src/string.rs b/kernel/libk/libk-util/src/string.rs index 838eb831..65a2b2cb 100644 --- a/kernel/libk/libk-util/src/string.rs +++ b/kernel/libk/libk-util/src/string.rs @@ -24,6 +24,9 @@ impl Utf16LeStr { Ok(unsafe { Self::from_utf16le_unchecked(raw) }) } + /// # Safety + /// + /// Does not validate the validity of the UTF-16 sequence. pub unsafe fn from_utf16le_unchecked(raw: &[u8]) -> &Self { core::mem::transmute(raw) } diff --git a/kernel/libk/src/debug/ring.rs b/kernel/libk/src/debug/ring.rs index 1f45f048..b652811d 100644 --- a/kernel/libk/src/debug/ring.rs +++ b/kernel/libk/src/debug/ring.rs @@ -200,7 +200,7 @@ impl log::Log for RingLoggerSink { let result = if record.target() == ":raw" || record.target() == ":program" { write!(write, "{}", record.args()) } else { - write!(write, "{}\n", record.args()) + writeln!(write, "{}", record.args()) }; if let Ok(()) = result { diff --git a/kernel/libk/src/device/block/partition/mbr.rs b/kernel/libk/src/device/block/partition/mbr.rs index 2537a690..89f4683a 100644 --- a/kernel/libk/src/device/block/partition/mbr.rs +++ b/kernel/libk/src/device/block/partition/mbr.rs @@ -26,9 +26,9 @@ pub(crate) async fn probe_mbr(dev: &Arc) -> Result(); - entries[i] = bytemuck::pod_read_unaligned(&mbr[s..s + size_of::()]); + *entry = bytemuck::pod_read_unaligned(&mbr[s..s + size_of::()]); } let mut partitions = vec![]; diff --git a/kernel/libk/src/device/display/fb_console.rs b/kernel/libk/src/device/display/fb_console.rs index 0d5d0593..00c0ceb2 100644 --- a/kernel/libk/src/device/display/fb_console.rs +++ b/kernel/libk/src/device/display/fb_console.rs @@ -65,7 +65,7 @@ impl DisplayConsole for FramebufferConsole { let cw = inner.char_width; let ch = inner.char_height; - let bytes_per_line = (font.width() as usize + 7) / 8; + let bytes_per_line = (font.width() as usize).div_ceil(8); let mut iter = state.buffer.flush_rows(); diff --git a/kernel/libk/src/dma.rs b/kernel/libk/src/dma.rs index 7a6a0369..45857321 100644 --- a/kernel/libk/src/dma.rs +++ b/kernel/libk/src/dma.rs @@ -151,6 +151,9 @@ impl DmaBuffer { }) } + /// # Safety + /// + /// Same precautions apply as for [MaybeUninit]. pub unsafe fn assume_init(buffer: DmaBuffer>) -> DmaBuffer { let host_pointer = buffer.host_pointer; let host_physical = buffer.host_physical; @@ -169,6 +172,9 @@ impl DmaBuffer { } } + /// # Safety + /// + /// Same precautions apply as for [MaybeUninit]. pub unsafe fn assume_init_slice(buffer: DmaBuffer<[MaybeUninit]>) -> DmaBuffer<[T]> { let host_pointer = buffer.host_pointer; let host_physical = buffer.host_physical; diff --git a/kernel/libk/src/task/process.rs b/kernel/libk/src/task/process.rs index 1945e539..9a9cafac 100644 --- a/kernel/libk/src/task/process.rs +++ b/kernel/libk/src/task/process.rs @@ -222,7 +222,7 @@ impl Process { let id = thread.id; if let Some(sysfs_node) = self.sysfs_node.read().as_ref() { - thread.add_sysfs_node(&sysfs_node); + thread.add_sysfs_node(sysfs_node); } inner.register_thread(thread.clone()); diff --git a/kernel/libk/src/task/runtime/executor.rs b/kernel/libk/src/task/runtime/executor.rs index 011f6c34..1eb7b7c4 100644 --- a/kernel/libk/src/task/runtime/executor.rs +++ b/kernel/libk/src/task/runtime/executor.rs @@ -20,7 +20,7 @@ pub fn enqueue(task: Arc) -> Result<(), Error> { /// Spawns a background worker to execute the tasks from the global queue pub fn spawn_async_worker(index: usize) -> Result<(), Error> { - let name = format!("[async-worker-{}]", index); + let name = format!("[async-worker-{index}]"); let thread = Thread::new_kthread( name, diff --git a/kernel/libk/src/task/thread.rs b/kernel/libk/src/task/thread.rs index 4fe107fc..024d6c24 100644 --- a/kernel/libk/src/task/thread.rs +++ b/kernel/libk/src/task/thread.rs @@ -318,7 +318,7 @@ impl Thread { /// Returns `true` if the thread is a child of given process pub fn is_child_of(&self, pid: ProcessId) -> bool { - self.process.map_or(false, |p| p == pid) + self.process == Some(pid) } /// Returns the thread's parent process reference @@ -513,7 +513,7 @@ impl Thread { /// Returns `true` if the thread is a tracee of given process pub fn is_tracee_of(&self, pid: ProcessId) -> bool { - self.debug.lock().tracer.map_or(false, |p| p == pid) + self.debug.lock().tracer == Some(pid) } pub fn attach_trace(&self, tracer: ProcessId) -> Result<(), Error> { diff --git a/kernel/libk/src/vfs/file/mod.rs b/kernel/libk/src/vfs/file/mod.rs index 4292d06a..8c68410d 100644 --- a/kernel/libk/src/vfs/file/mod.rs +++ b/kernel/libk/src/vfs/file/mod.rs @@ -86,7 +86,7 @@ enum FileInner { Char(CharFile), Socket(SocketWrapper), AnonymousPipe(PipeEnd), - Poll(FdPoll), + Poll(Arc), Timer(TimerFile), SharedMemory(Arc), PtySlave(TerminalHalfWrapper), @@ -134,7 +134,7 @@ impl File { /// Constructs a new poll channel file pub fn new_poll_channel() -> Arc { - Self::from_inner(FileInner::Poll(FdPoll::new())) + Self::from_inner(FileInner::Poll(Arc::new(FdPoll::new()))) } /// Creates a buffer of shared memory and associates a [File] with it diff --git a/kernel/src/arch/aarch64/boot/mod.rs b/kernel/src/arch/aarch64/boot/mod.rs index 93293988..83647e21 100644 --- a/kernel/src/arch/aarch64/boot/mod.rs +++ b/kernel/src/arch/aarch64/boot/mod.rs @@ -53,7 +53,7 @@ unsafe extern "C" fn relocate_kernel(image_base: i64, rela_start: usize, rela_en let value = match rela.r_info as u32 { abi::R_AARCH64_RELATIVE => rela.r_addend + image_base, - _ => loop {}, + _ => ArchitectureImpl::halt(), }; slot.write_volatile(value); diff --git a/kernel/src/arch/aarch64/gic/gicv2m.rs b/kernel/src/arch/aarch64/gic/gicv2m.rs index b943c556..8fb41723 100644 --- a/kernel/src/arch/aarch64/gic/gicv2m.rs +++ b/kernel/src/arch/aarch64/gic/gicv2m.rs @@ -168,7 +168,7 @@ impl InterruptHandler for Gicv2m { impl MessageInterruptController for Gicv2m { fn handle_msi(&self, _vector: usize) { - loop {} + todo!() } fn register_msi_range( diff --git a/kernel/src/arch/riscv64/boot/mod.rs b/kernel/src/arch/riscv64/boot/mod.rs index 9a471cbf..04b28115 100644 --- a/kernel/src/arch/riscv64/boot/mod.rs +++ b/kernel/src/arch/riscv64/boot/mod.rs @@ -51,7 +51,7 @@ unsafe extern "C" fn relocate_kernel(image_base: i64, rela_start: usize, rela_en let value = match rela.r_info as u32 { abi::R_RISCV_RELATIVE => rela.r_addend + image_base, - _ => loop {}, + _ => ArchitectureImpl::halt(), }; slot.write_volatile(value); diff --git a/kernel/src/arch/x86_64/exception.rs b/kernel/src/arch/x86_64/exception.rs index 6d80cd8d..aa0f89e1 100644 --- a/kernel/src/arch/x86_64/exception.rs +++ b/kernel/src/arch/x86_64/exception.rs @@ -60,7 +60,7 @@ impl ExceptionKind { /// Exception table entry #[allow(dead_code)] #[derive(Clone, Copy)] -#[repr(packed)] +#[repr(C, packed)] pub struct Entry { base_lo: u16, selector: u16, @@ -72,7 +72,7 @@ pub struct Entry { } #[allow(dead_code)] -#[repr(packed)] +#[repr(C, packed)] struct Pointer { limit: u16, offset: usize, diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 59d09a06..b8809864 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -302,15 +302,13 @@ impl X86_64 { if let Err(error) = ygg_driver_acpi::switch_to_acpi(acpi) { log::error!("ACPI initialization error: {error:?}"); - } else { - if let Err(error) = - ygg_driver_acpi::add_event_handler(&FixedEvent::POWER_BUTTON, |_| { - log::info!("Power button pressed!"); - EventAction::Nothing - }) - { - log::error!("Couldn't set ACPI power button handler: {error:?}"); - } + } else if let Err(error) = + ygg_driver_acpi::add_event_handler(&FixedEvent::POWER_BUTTON, |_| { + log::info!("Power button pressed!"); + EventAction::Nothing + }) + { + log::error!("Couldn't set ACPI power button handler: {error:?}"); } if let Ok(mcfg) = acpi.find_table::() { diff --git a/kernel/src/device/clock/bcm2835_aux.rs b/kernel/src/device/clock/bcm2835_aux.rs index 10c9a4af..dcfa8d2b 100644 --- a/kernel/src/device/clock/bcm2835_aux.rs +++ b/kernel/src/device/clock/bcm2835_aux.rs @@ -58,7 +58,7 @@ impl ClockController for Bcm2835Aux { regs.AUX_ENABLES.modify(AUX_ENABLES::MU_ENABLE::SET); Ok(()) } - None => loop {}, + None => todo!(), _ => Err(Error::InvalidArgument), } } diff --git a/kernel/src/device/clock/jh7110_aoncrg.rs b/kernel/src/device/clock/jh7110_aoncrg.rs index 8c47f014..92d68563 100644 --- a/kernel/src/device/clock/jh7110_aoncrg.rs +++ b/kernel/src/device/clock/jh7110_aoncrg.rs @@ -98,7 +98,7 @@ impl Aoncrg { use ClockParent::*; use ClockRegister::*; - const CLOCK_MAP: &[(&'static str, ClockRegister)] = &[ + const CLOCK_MAP: &[(&str, ClockRegister)] = &[ /* 0 */ ("clk_osc", FixedDiv(4, Ext(PARENT_OSC))), /* 1 */ ("clk_aon_apb_func", Unimp), /* 2 */ ("clk_gmac5_ahb", Gate(31, Ext(PARENT_STG_AXIAHB))), diff --git a/kernel/src/device/clock/jh7110_syscrg.rs b/kernel/src/device/clock/jh7110_syscrg.rs index 88c5dc7b..142743c5 100644 --- a/kernel/src/device/clock/jh7110_syscrg.rs +++ b/kernel/src/device/clock/jh7110_syscrg.rs @@ -80,7 +80,7 @@ impl Syscrg { } fn map_clock_index(index: u32) -> Option<(&'static str, ClockRegister)> { - const CLOCKS: &[(&'static str, ClockRegister)] = &const { + const CLOCKS: &[(&str, ClockRegister)] = &const { use ClockParent::*; use ClockRegister::*; diff --git a/lib/abi-serde/src/impls/base.rs b/lib/abi-serde/src/impls/base.rs index 0fa559f5..235ef5fe 100644 --- a/lib/abi-serde/src/impls/base.rs +++ b/lib/abi-serde/src/impls/base.rs @@ -55,8 +55,8 @@ impl<'de> Deserialize<'de> for () { impl Serialize for [T; N] { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { - for i in 0..N { - self[i].serialize(serializer)?; + for item in self[0..N].iter() { + item.serialize(serializer)?; } Ok(()) } @@ -65,8 +65,8 @@ impl Serialize for [T; N] { impl<'de, const N: usize, T: Deserialize<'de>> Deserialize<'de> for [T; N] { fn deserialize>(deserializer: &mut D) -> Result { let mut array = [const { MaybeUninit::uninit() }; N]; - for i in 0..N { - array[i].write(Deserialize::deserialize(deserializer)?); + for item in array[0..N].iter_mut() { + item.write(Deserialize::deserialize(deserializer)?); } Ok(unsafe { MaybeUninit::array_assume_init(array) }) } diff --git a/lib/abi/src/net/types/mod.rs b/lib/abi/src/net/types/mod.rs index 226248de..8e37e0b8 100644 --- a/lib/abi/src/net/types/mod.rs +++ b/lib/abi/src/net/types/mod.rs @@ -46,7 +46,7 @@ impl fmt::Display for MacAddress { if i != 0 { write!(f, ":")?; } - write!(f, "{:02X}", octet)?; + write!(f, "{octet:02X}")?; } Ok(()) diff --git a/lib/abi/src/process/exit.rs b/lib/abi/src/process/exit.rs index 7ada815d..4b2b493b 100644 --- a/lib/abi/src/process/exit.rs +++ b/lib/abi/src/process/exit.rs @@ -90,12 +90,12 @@ impl SyscallRegister for ExitCode { impl Serialize for ExitCode { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { - match self { - &Self::Exited(status) => { + match *self { + Self::Exited(status) => { serializer.write_u8(0)?; status.serialize(serializer) } - &Self::BySignal(signal) => { + Self::BySignal(signal) => { serializer.write_u8(1)?; signal.serialize(serializer) } diff --git a/lib/libyalloc/src/bucket.rs b/lib/libyalloc/src/bucket.rs index 76de22a2..03898b3a 100644 --- a/lib/libyalloc/src/bucket.rs +++ b/lib/libyalloc/src/bucket.rs @@ -25,8 +25,8 @@ where Assert<{ M % 64 == 0 }>: IsTrue, { pub fn new() -> Option> { - let data_page_count = (M * N + 0xFFF) / 0x1000; - let info_page_count = (size_of::() + 0xFFF) / 0x1000; + let data_page_count = (M * N).div_ceil(0x1000); + let info_page_count = size_of::().div_ceil(0x1000); let data = P::map_pages(data_page_count)?; let info = P::map_pages(info_page_count)?; diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs index a26d4677..c8bf3260 100644 --- a/lib/runtime/build.rs +++ b/lib/runtime/build.rs @@ -7,7 +7,7 @@ use abi_generator::{ }; fn add_file<'a>(build: &'a mut cc::Build, name: &'a str) -> &'a mut cc::Build { - println!("cargo:rerun-if-changed={}", name); + println!("cargo:rerun-if-changed={name}"); build.file(name) } diff --git a/userspace/dyn-loader/src/main.rs b/userspace/dyn-loader/src/main.rs index 9a964374..83637582 100644 --- a/userspace/dyn-loader/src/main.rs +++ b/userspace/dyn-loader/src/main.rs @@ -7,7 +7,11 @@ naked_functions, let_chains )] -#![allow(clippy::new_without_default, clippy::missing_transmute_annotations)] +#![allow( + clippy::new_without_default, + clippy::missing_transmute_annotations, + clippy::identity_op +)] use std::{fs, mem::MaybeUninit, os::yggdrasil::real_binary_path, path::Path, process::ExitCode}; diff --git a/userspace/graphics/colors/src/bin/colors-bar.rs b/userspace/graphics/colors/src/bin/colors-bar.rs index 61e9aaf7..6d0615f5 100644 --- a/userspace/graphics/colors/src/bin/colors-bar.rs +++ b/userspace/graphics/colors/src/bin/colors-bar.rs @@ -27,6 +27,7 @@ static CURRENT_WORKSPACE: AtomicUsize = AtomicUsize::new(0); const WHITE: u32 = 0xFFFFFFFF; const BLACK: u32 = 0xFF000000; +#[allow(clippy::too_many_arguments)] fn draw_string( dt: &mut [u32], font: &PcScreenFont, diff --git a/userspace/graphics/colors/src/main.rs b/userspace/graphics/colors/src/main.rs index 2daf45c1..5371e8a5 100644 --- a/userspace/graphics/colors/src/main.rs +++ b/userspace/graphics/colors/src/main.rs @@ -1,4 +1,5 @@ #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os, rustc_private))] +#![allow(clippy::single_match, clippy::collapsible_else_if)] #![feature(map_many_mut, iter_chain)] use std::{ @@ -48,7 +49,7 @@ pub struct Server<'a> { _pd: PhantomData<&'a ()>, } -impl<'a> Server<'a> { +impl Server<'_> { fn new() -> Result { Ok(Self { input_state: InputState::default(), diff --git a/userspace/graphics/term/src/attr.rs b/userspace/graphics/term/src/attr.rs index 65100dce..b1079a50 100644 --- a/userspace/graphics/term/src/attr.rs +++ b/userspace/graphics/term/src/attr.rs @@ -73,7 +73,7 @@ impl<'de> Deserialize<'de> for Color { { struct V; - impl<'de> Visitor<'de> for V { + impl Visitor<'_> for V { type Value = Color; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/userspace/graphics/term/src/main.rs b/userspace/graphics/term/src/main.rs index 219756b8..6fd36dc4 100644 --- a/userspace/graphics/term/src/main.rs +++ b/userspace/graphics/term/src/main.rs @@ -78,6 +78,7 @@ impl DrawState { } } + #[allow(clippy::too_many_arguments)] fn draw_character( dt: &mut [u32], cx: usize, @@ -110,7 +111,6 @@ impl DrawState { return; } - let c = cell.char as char; let font = match (cell.attrs.bold, cell.attrs.italic) { (true, true) => &fonts.bold_italic, (false, true) => &fonts.italic, @@ -118,7 +118,7 @@ impl DrawState { (false, false) => &fonts.regular, }; - font.map_glyph(c, |x, y, v| { + font.map_glyph(cell.char, |x, y, v| { let v = v.min(1.0); let r = blend(fg.r, bg.r, v); let g = blend(fg.g, bg.g, v); diff --git a/userspace/graphics/term/src/state.rs b/userspace/graphics/term/src/state.rs index 557b209d..6c961b5e 100644 --- a/userspace/graphics/term/src/state.rs +++ b/userspace/graphics/term/src/state.rs @@ -83,14 +83,12 @@ impl Utf8Decoder { let ch = str.chars().next().unwrap(); self.len = 0; Some(ch) + } else if self.len == 4 { + // Got 4 bytes and could not decode a single character + self.len = 0; + Some('\u{25A1}') } else { - if self.len == 4 { - // Got 4 bytes and could not decode a single character - self.len = 0; - Some('\u{25A1}') - } else { - None - } + None } } } @@ -284,7 +282,7 @@ impl State { fn update_fg_color(&mut self) { if let Some(fg_index) = self.fg_index { - self.attributes.fg = Color::from_escape(&*CONFIG, self.attributes.bold, fg_index) + self.attributes.fg = Color::from_escape(&CONFIG, self.attributes.bold, fg_index) .unwrap_or(self.default_attributes.fg); } } @@ -345,7 +343,7 @@ impl State { } _ => { self.buffer - .set_cell(self.cursor, GridCell::new(ch as char, self.attributes)); + .set_cell(self.cursor, GridCell::new(ch, self.attributes)); self.cursor.col += 1; true } @@ -378,7 +376,7 @@ impl State { fn handle_ctlseq(&mut self, byte: u8, c: char) -> bool { let redraw = match c { - 'h' if byte == b'?' => match self.esc_args.get(0).copied().unwrap_or(0) { + 'h' if byte == b'?' => match self.esc_args.first().copied().unwrap_or(0) { 25 => { // Cursor visible self.cursor_visible = true; @@ -391,7 +389,7 @@ impl State { } _ => false, }, - 'l' if byte == b'?' => match self.esc_args.get(0).copied().unwrap_or(0) { + 'l' if byte == b'?' => match self.esc_args.first().copied().unwrap_or(0) { 25 => { // Cursor not visible self.cursor_visible = false; @@ -408,7 +406,7 @@ impl State { _ => false, }, 'q' => { - match self.esc_args.get(0).copied().unwrap_or(0) { + match self.esc_args.first().copied().unwrap_or(0) { 3 | 4 => self.cursor_style = CursorStyle::Underline, 5 | 6 => self.cursor_style = CursorStyle::Bar, _ => self.cursor_style = CursorStyle::Block, @@ -500,7 +498,7 @@ impl State { if vt_color == 9 { self.attributes.bg = self.default_attributes.bg; } else { - self.attributes.bg = Color::from_escape(&*CONFIG, false, vt_color) + self.attributes.bg = Color::from_escape(&CONFIG, false, vt_color) .unwrap_or(self.default_attributes.bg); } false diff --git a/userspace/lib/libcolors/src/application/window.rs b/userspace/lib/libcolors/src/application/window.rs index 7e1e0772..0fc2b52e 100644 --- a/userspace/lib/libcolors/src/application/window.rs +++ b/userspace/lib/libcolors/src/application/window.rs @@ -44,7 +44,7 @@ pub struct Window<'a> { on_key_released: Box, } -impl<'a> Window<'a> { +impl Window<'_> { pub fn new_with_info(application: &Application, info: CreateWindowInfo) -> Result { let mut connection = application.connection.lock().unwrap(); diff --git a/userspace/lib/uipc/src/lib.rs b/userspace/lib/uipc/src/lib.rs index c1fb4a98..274f332d 100644 --- a/userspace/lib/uipc/src/lib.rs +++ b/userspace/lib/uipc/src/lib.rs @@ -35,10 +35,7 @@ pub struct Receiver { impl Error { pub fn is_would_block(&self) -> bool { - match self { - Self::Io(error) if error.kind() == io::ErrorKind::WouldBlock => true, - _ => false, - } + matches!(self, Self::Io(error) if error.kind() == io::ErrorKind::WouldBlock) } } diff --git a/userspace/lib/ygglibc/build.rs b/userspace/lib/ygglibc/build.rs index 4b695ba3..85860d18 100644 --- a/userspace/lib/ygglibc/build.rs +++ b/userspace/lib/ygglibc/build.rs @@ -72,7 +72,7 @@ fn generate_header(config_path: impl AsRef, header_output: impl AsRef) { }; command - .arg(format!("--target={}-unknown-none", arch)) + .arg(format!("--target={arch}-unknown-none")) .arg("-nostdlib") .arg("-fPIC") .arg("-c"); diff --git a/userspace/lib/ygglibc/src/env.rs b/userspace/lib/ygglibc/src/env.rs index 62e6f47f..5e3c4cdf 100644 --- a/userspace/lib/ygglibc/src/env.rs +++ b/userspace/lib/ygglibc/src/env.rs @@ -229,7 +229,7 @@ pub fn handle_kernel_argument(arg: usize) -> Vec { args.push(c_arg); } - if let Some(arg0) = args.get(0) { + if let Some(arg0) = args.first() { let invocation_name_str = arg0.to_str().unwrap(); let invocation_name = arg0.clone(); let invocation_name_short_str = diff --git a/userspace/lib/ygglibc/src/headers/libgen/mod.rs b/userspace/lib/ygglibc/src/headers/libgen/mod.rs index 1ca6acce..22a8f35e 100644 --- a/userspace/lib/ygglibc/src/headers/libgen/mod.rs +++ b/userspace/lib/ygglibc/src/headers/libgen/mod.rs @@ -10,7 +10,7 @@ unsafe extern "C" fn basename(path: *mut c_char) -> *mut c_char { return DOT; } let path_str = path.cast_const().ensure_str(); - if path_str == "" { + if path_str.is_empty() { DOT } else if path_str == "/" { path diff --git a/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs b/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs index 11fc474e..aa4c0166 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs @@ -56,7 +56,7 @@ fn fmt_float_exp( } fn fmt_float_string(val: c_double, precision: usize) -> String { - let string = format!("{:.p$}", val, p = precision); + let string = format!("{val:.precision$}"); // TODO trim string } diff --git a/userspace/lib/ygglibc/src/headers/strings/mod.rs b/userspace/lib/ygglibc/src/headers/strings/mod.rs index fcdccb42..5b70e6da 100644 --- a/userspace/lib/ygglibc/src/headers/strings/mod.rs +++ b/userspace/lib/ygglibc/src/headers/strings/mod.rs @@ -24,6 +24,7 @@ unsafe extern "C" fn strcasecmp_l( todo!() } +#[allow(clippy::unnecessary_cast)] #[no_mangle] unsafe extern "C" fn strncasecmp(s1: *const c_char, s2: *const c_char, n: usize) -> c_int { if s1.is_null() { diff --git a/userspace/lib/ygglibc/src/headers/wctype/alpha.rs b/userspace/lib/ygglibc/src/headers/wctype/alpha.rs index 41c34415..4013dd69 100644 --- a/userspace/lib/ygglibc/src/headers/wctype/alpha.rs +++ b/userspace/lib/ygglibc/src/headers/wctype/alpha.rs @@ -6,12 +6,12 @@ use core::ffi::c_uchar; pub fn is(wc: usize) -> c_uchar { if wc < 0x20000 { - return (table[(table[wc >> 8] as usize) * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1; + (table[(table[wc >> 8] as usize) * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1 + } else if wc < 0x2fffe { + 1 + } else { + 0 } - if wc < 0x2fffe { - return 1; - } - return 0; } const table: [c_uchar; 3904] = [ diff --git a/userspace/lib/ygglibc/src/headers/wctype/casecmp.rs b/userspace/lib/ygglibc/src/headers/wctype/casecmp.rs index bd229414..197ba8a8 100644 --- a/userspace/lib/ygglibc/src/headers/wctype/casecmp.rs +++ b/userspace/lib/ygglibc/src/headers/wctype/casecmp.rs @@ -370,7 +370,7 @@ pub fn casemap(mut c: u32, dir: i32) -> wint_t { /* lookup entry in two-level base-6 table */ let mut v: c_uint = tab[(tab[b as usize] as u32 * 86 + x) as usize] as c_uint; let mt: [c_uint; 3] = [2048, 342, 57]; - v = (v * mt[y as usize] >> 11) % 6; + v = (v * (mt[y as usize] >> 11)) % 6; /* use the bit vector out of the tables as an index into * a block-specific set of rules and decode the rule into @@ -413,5 +413,6 @@ pub fn casemap(mut c: u32, dir: i32) -> wint_t { xn -= xn / 2; } } - return c0; + + c0 } diff --git a/userspace/lib/ygglibc/src/headers/wctype/mod.rs b/userspace/lib/ygglibc/src/headers/wctype/mod.rs index af4c44ee..05bba93b 100644 --- a/userspace/lib/ygglibc/src/headers/wctype/mod.rs +++ b/userspace/lib/ygglibc/src/headers/wctype/mod.rs @@ -78,7 +78,7 @@ unsafe extern "C" fn iswlower(wc: wint_t) -> c_int { #[no_mangle] unsafe extern "C" fn iswprint(wc: wint_t) -> c_int { if wc < 0xff { - c_int::from((wc + 1 & 0x7f) >= 0x21) + c_int::from(((wc + 1) & 0x7f) >= 0x21) } else if wc < 0x2028 || wc.wrapping_sub(0x202a) < 0xd800 - 0x202a || wc.wrapping_sub(0xe000) < 0xfff9 - 0xe000 diff --git a/userspace/lib/ygglibc/src/headers/wctype/punct.rs b/userspace/lib/ygglibc/src/headers/wctype/punct.rs index 3ae44ded..7521df49 100644 --- a/userspace/lib/ygglibc/src/headers/wctype/punct.rs +++ b/userspace/lib/ygglibc/src/headers/wctype/punct.rs @@ -7,9 +7,10 @@ use core::ffi::c_uchar; pub fn is(wc: usize) -> c_uchar { if wc < 0x20000 { - return (table[(table[wc >> 8] as usize) * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1; + (table[(table[wc >> 8] as usize) * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1 + } else { + 0 } - return 0; } const table: [c_uchar; 4000] = [ diff --git a/userspace/lib/ygglibc/src/io/managed.rs b/userspace/lib/ygglibc/src/io/managed.rs index 75679b60..4ba41e97 100644 --- a/userspace/lib/ygglibc/src/io/managed.rs +++ b/userspace/lib/ygglibc/src/io/managed.rs @@ -300,10 +300,7 @@ impl FILE { } unsafe fn reading_locked(&self) -> bool { - !self.flags.contains(FileFlags::WRITE) - || self - .last_operation - .map_or(false, |op| op == Direction::Read) + !self.flags.contains(FileFlags::WRITE) || self.last_operation == Some(Direction::Read) } pub fn reading(&self) -> bool { @@ -311,10 +308,7 @@ impl FILE { } unsafe fn writing_locked(&self) -> bool { - !self.flags.contains(FileFlags::WRITE) - || self - .last_operation - .map_or(false, |op| op == Direction::Write) + !self.flags.contains(FileFlags::WRITE) || self.last_operation == Some(Direction::Write) } pub fn writing(&self) -> bool { diff --git a/userspace/lib/ygglibc/src/panic.rs b/userspace/lib/ygglibc/src/panic.rs index a1ab2d33..a44edfb4 100644 --- a/userspace/lib/ygglibc/src/panic.rs +++ b/userspace/lib/ygglibc/src/panic.rs @@ -89,7 +89,7 @@ fn panic_handler(pi: &core::panic::PanicInfo) -> ! { if this == 0 { writeln!(printer, "* Main thread panicked *").ok(); } else { - writeln!(printer, "* Thread {} panicked*", this).ok(); + writeln!(printer, "* Thread {this} panicked*").ok(); } } diff --git a/userspace/lib/ygglibc/src/process.rs b/userspace/lib/ygglibc/src/process.rs index da105559..c6cbf8c8 100644 --- a/userspace/lib/ygglibc/src/process.rs +++ b/userspace/lib/ygglibc/src/process.rs @@ -109,7 +109,7 @@ unsafe extern "C" fn __assert_fail(file: *const c_char, line: c_int, message: *c } .unwrap_or("???"); - writeln!(err, "Assertion failed: '{}' at {}:{}", expr, file, line).ok(); + writeln!(err, "Assertion failed: '{expr}' at {file}:{line}").ok(); abort() } diff --git a/userspace/lib/ygglibc/src/signal.rs b/userspace/lib/ygglibc/src/signal.rs index e0de7f53..821b86a9 100644 --- a/userspace/lib/ygglibc/src/signal.rs +++ b/userspace/lib/ygglibc/src/signal.rs @@ -43,7 +43,7 @@ fn signal_handler(signal: Signal) { } pub unsafe fn set(sig: c_int, handler: sig_handler_t) -> EResult { - if sig < 0 || sig >= SIGNAL_MAX { + if !(0..SIGNAL_MAX).contains(&sig) { return EResult::Err(Errno::EINVAL); } @@ -55,12 +55,12 @@ pub unsafe fn set(sig: c_int, handler: sig_handler_t) -> EResult _ if address == __sig_terminate as usize => todo!(), _ if address == __sig_ignore as usize => todo!(), // This is safe: handler essentially has the same type, just in a wrapper - _ => core::mem::transmute(handler), + _ => handler, }; let old = table[sig as usize].replace(handler); let old = match old { - Some(old) => core::mem::transmute(old), + Some(old) => old, None => __sig_terminate as sig_handler_t, }; EResult::Ok(old) diff --git a/userspace/lib/ygglibc/src/util.rs b/userspace/lib/ygglibc/src/util.rs index d89e4783..d06fd801 100644 --- a/userspace/lib/ygglibc/src/util.rs +++ b/userspace/lib/ygglibc/src/util.rs @@ -15,6 +15,7 @@ use crate::{ pub trait Pointer { type Pointee; + #[allow(clippy::wrong_self_convention)] fn is_null(self) -> bool; } diff --git a/userspace/netutils/src/dhcp_client.rs b/userspace/netutils/src/dhcp_client.rs index aae1e3f7..df824545 100644 --- a/userspace/netutils/src/dhcp_client.rs +++ b/userspace/netutils/src/dhcp_client.rs @@ -242,9 +242,7 @@ impl DhcpMessage { } fn as_dhcp_acknowledge(&self, requested_address: Ipv4Addr) -> Option<()> { - let Some(ty) = self.message_type() else { - return None; - }; + let ty = self.message_type()?; if ty != DhcpMessageType::Acknowledge { return None; @@ -555,7 +553,7 @@ fn configure_address(interface: &str, offer: DhcpOffer) -> Result<(), Error> { netconf.add_route( interface, SubnetAddr::V4(SubnetV4Addr::UNSPECIFIED), - Some(router_address.into()) + Some(router_address.into()), )?; Ok(()) } diff --git a/userspace/sysutils/src/top.rs b/userspace/sysutils/src/top.rs index eef9e296..d8ab9acd 100644 --- a/userspace/sysutils/src/top.rs +++ b/userspace/sysutils/src/top.rs @@ -165,43 +165,38 @@ impl State { let hint_style = Style::default().bg(Color::Blue).fg(Color::White); let key_style = Style::default().bg(Color::Cyan).fg(Color::Black); - let rows = self - .processes - .iter() - .enumerate() - .map(|(i, process)| { - let style = if i == self.selection { - selected_style - } else { - normal_style - }; + let rows = self.processes.iter().enumerate().flat_map(|(i, process)| { + let style = if i == self.selection { + selected_style + } else { + normal_style + }; - let mut rows = vec![Row::new(vec![ - Cell::from(format!("{}", process.pid)), - Cell::from(""), - Cell::from(process.name.as_str()), - ]) - .height(1) - .style(style)]; + let mut rows = vec![Row::new(vec![ + Cell::from(format!("{}", process.pid)), + Cell::from(""), + Cell::from(process.name.as_str()), + ]) + .height(1) + .style(style)]; - if self.expanded.contains(&process.pid) { - let count = process.threads.len(); - for (i, thread) in process.threads.iter().enumerate() { - let ch = if i == count - 1 { "└" } else { "├" }; - rows.push( - Row::new(vec![ - Cell::from(ch), - Cell::from(format!("{}", thread.tid)), - Cell::from(thread.name.as_str()), - ]) - .style(style), - ); - } + if self.expanded.contains(&process.pid) { + let count = process.threads.len(); + for (i, thread) in process.threads.iter().enumerate() { + let ch = if i == count - 1 { "└" } else { "├" }; + rows.push( + Row::new(vec![ + Cell::from(ch), + Cell::from(format!("{}", thread.tid)), + Cell::from(thread.name.as_str()), + ]) + .style(style), + ); } + } - rows - }) - .flatten(); + rows + }); let header = Row::new(vec![ Cell::from("PID"), diff --git a/userspace/tools/md2txt/src/setting.rs b/userspace/tools/md2txt/src/setting.rs index e7bcc6ce..3ff33569 100644 --- a/userspace/tools/md2txt/src/setting.rs +++ b/userspace/tools/md2txt/src/setting.rs @@ -363,11 +363,8 @@ impl TerminalTypesetter { } fn increment_list_index(&mut self) { - if let Some(last) = self.list_stack.last_mut() { - match last { - ListStyle::Numbered(index) => *index += 1, - _ => (), - } + if let Some(ListStyle::Numbered(index)) = self.list_stack.last_mut() { + *index += 1; } } @@ -436,11 +433,11 @@ impl Typesetter for TerminalTypesetter { self.hard_break(false); self.indent += 1; if let Some(last) = self.list_stack.last() { - match last { - &ListStyle::Bullet(p) => { + match *last { + ListStyle::Bullet(p) => { self.line.prefix.push(p); } - &ListStyle::Numbered(n) => { + ListStyle::Numbered(n) => { self.line.prefix.push_str(&format!("{n}.")); } } diff --git a/userspace/tools/shell/src/command/eval.rs b/userspace/tools/shell/src/command/eval.rs index b738dace..37b912d2 100644 --- a/userspace/tools/shell/src/command/eval.rs +++ b/userspace/tools/shell/src/command/eval.rs @@ -63,7 +63,7 @@ fn evaluate_conditional_body( env: &mut Environment, ) -> (Outcome, Option) { while let Expression::Not(inner) = body { - body = &*inner; + body = inner; } let status = match body { Expression::Binary(BinaryOperator::Equal, lhs, rhs) @@ -109,7 +109,7 @@ pub fn evaluate_conditional( conditional: &ConditionalExpression, env: &mut Environment, ) -> (Outcome, Option) { - evaluate_conditional_body(&*conditional.body, env) + evaluate_conditional_body(&conditional.body, env) } pub fn evaluate(expression: &Expression, env: &mut Environment) -> (Outcome, Option) { @@ -119,7 +119,7 @@ pub fn evaluate(expression: &Expression, env: &mut Environment) -> (Outcome, Opt let mut setenvs = vec![]; expanded.elements.retain_mut(|e| { if e.words.is_empty() { - setenvs.extend(e.envs.drain(..)); + setenvs.append(&mut e.envs); } !e.words.is_empty() }); @@ -169,7 +169,7 @@ pub fn evaluate(expression: &Expression, env: &mut Environment) -> (Outcome, Opt }, // TODO redirects Expression::For(for_expression) => { - let list = ExpandedPipelineElement::from_syntax(env, &*for_expression.list); + let list = ExpandedPipelineElement::from_syntax(env, &for_expression.list); env.push_environment(); for word in list.words { env.insert_current_literal(for_expression.variable, word); @@ -183,23 +183,23 @@ pub fn evaluate(expression: &Expression, env: &mut Environment) -> (Outcome, Opt (Outcome::ok(), None) } Expression::Binary(BinaryOperator::And, lhs, rhs) => { - let (lhs, exit) = evaluate(&*lhs, env); + let (lhs, exit) = evaluate(lhs, env); if exit.is_some() { return (lhs, exit); } if lhs.is_success() { - evaluate(&*rhs, env) + evaluate(rhs, env) } else { (lhs, exit) } } Expression::Binary(BinaryOperator::Or, lhs, rhs) => { - let (lhs, exit) = evaluate(&*lhs, env); + let (lhs, exit) = evaluate(lhs, env); if exit.is_some() { return (lhs, exit); } if !lhs.is_success() { - evaluate(&*rhs, env) + evaluate(rhs, env) } else { (lhs, exit) } diff --git a/userspace/tools/shell/src/command/mod.rs b/userspace/tools/shell/src/command/mod.rs index be8d5cf9..a073312e 100644 --- a/userspace/tools/shell/src/command/mod.rs +++ b/userspace/tools/shell/src/command/mod.rs @@ -20,8 +20,7 @@ impl ExpandedPipelineElement { let mut words: Vec<_> = element .words .iter() - .map(|word| env.expand(word)) - .flatten() + .flat_map(|word| env.expand(word)) .collect(); let mut envs = vec![]; diff --git a/userspace/tools/shell/src/main.rs b/userspace/tools/shell/src/main.rs index ccefc0e1..99283965 100644 --- a/userspace/tools/shell/src/main.rs +++ b/userspace/tools/shell/src/main.rs @@ -118,7 +118,7 @@ fn run(mut input: ShellInput, env: &mut Environment) -> Result<(), Error> { continue; } - command_text.push_str(&line.trim_matches([' ', '\t'])); + command_text.push_str(line.trim_matches([' ', '\t'])); let expr = match syntax::parse::parse_toplevel(&command_text) { Ok(("" | "\n", expr)) => expr, Ok((rest, _)) => { diff --git a/userspace/tools/shell/src/readline.rs b/userspace/tools/shell/src/readline.rs index de0b66cb..119df743 100644 --- a/userspace/tools/shell/src/readline.rs +++ b/userspace/tools/shell/src/readline.rs @@ -23,14 +23,12 @@ impl Utf8Decoder { let ch = str.chars().next().unwrap(); self.len = 0; Some(ch) + } else if self.len == 4 { + // Got 4 bytes and could not decode a single character + self.len = 0; + Some('\u{25A1}') } else { - if self.len == 4 { - // Got 4 bytes and could not decode a single character - self.len = 0; - Some('\u{25A1}') - } else { - None - } + None } } } diff --git a/userspace/tools/strace/src/format.rs b/userspace/tools/strace/src/format.rs index 13230ace..312ec4c6 100644 --- a/userspace/tools/strace/src/format.rs +++ b/userspace/tools/strace/src/format.rs @@ -1,6 +1,10 @@ use std::fmt::Write; -use runtime::{abi::SyscallFunction, abi_lib::SyscallRegister, rt::io::{OpenOptions, SeekFrom}}; +use runtime::{ + abi::SyscallFunction, + abi_lib::SyscallRegister, + rt::io::{OpenOptions, SeekFrom}, +}; use crate::tracer::{CommandTracer, SyscallTrace}; @@ -36,14 +40,14 @@ enum Result { struct Formatter { fun: &'static str, args: &'static [Arg], - res: Result + res: Result, } impl Formatter { const EMPTY: Self = Self { fun: "", args: &[], - res: Result::None + res: Result::None, }; } @@ -53,6 +57,7 @@ macro_rules! formatter_list { $($syscall:ident => $name:ident ($($arg:ident),* $(,)?) $(-> $result:ident)?),+ $(,)? ] ) => { + #[allow(clippy::needless_update)] const FORMATTERS: [Option; SYSCALL_MAX] = const { let mut array = [None; SYSCALL_MAX]; @@ -258,9 +263,7 @@ impl Arg { Arg::Hex => Some((format!("{:#x}", args[0]), 1)), Arg::Oct => Some((format!("{:#o}", args[0]), 1)), #[cfg(any(rust_analyzer, target_pointer_width = "64"))] - Arg::U64Dec => { - Some((format!("{}", args[0]), 1)) - } + Arg::U64Dec => Some((format!("{}", args[0]), 1)), Arg::Bool => { let result = if args[0] == 0 { "false".into() @@ -335,9 +338,7 @@ impl Arg { }; Some((result, 1)) } - Arg::Todo => { - Some(("...".into(), 1)) - } + Arg::Todo => Some(("...".into(), 1)), } } } @@ -359,14 +360,8 @@ impl Result { format!("{result:#x}") } } - Self::ResUnit => { - if result == 0 { - "" - } else { - "" - }.into() - } - _ => return None + Self::ResUnit => if result == 0 { "" } else { "" }.into(), + _ => return None, }) } } diff --git a/userspace/tools/strace/src/tracer.rs b/userspace/tools/strace/src/tracer.rs index 87b12925..d1139019 100644 --- a/userspace/tools/strace/src/tracer.rs +++ b/userspace/tools/strace/src/tracer.rs @@ -88,7 +88,8 @@ impl CommandTracer { } pub fn read_word(&mut self, address: usize) -> io::Result { - debug_control::(self.tid, &mut self.buffer, &address).map_err(io::Error::from) + debug_control::(self.tid, &mut self.buffer, &address) + .map_err(io::Error::from) } pub fn read_memory(&mut self, mut address: usize, buffer: &mut [u8]) -> io::Result<()> { @@ -185,41 +186,41 @@ impl SyscallTrace { #[cfg(any(target_arch = "riscv64", rust_analyzer))] impl SyscallTrace { fn from_parts(entry: &EnteredSyscall, exit_regs: &SavedFrame, exit: SystemTime) -> Self { - let function = entry.regs.an[0] as usize; + let function = entry.regs.an[0]; let args = [ - entry.regs.an[1] as usize, - entry.regs.an[2] as usize, - entry.regs.an[3] as usize, - entry.regs.an[4] as usize, - entry.regs.an[5] as usize, - entry.regs.an[6] as usize, + entry.regs.an[1], + entry.regs.an[2], + entry.regs.an[3], + entry.regs.an[4], + entry.regs.an[5], + entry.regs.an[6], ]; - let result = exit_regs.an[0] as usize; - let entry = entry.timestamp; - - Self { - entry, - exit, - function, - args, - result - } - } -} - -#[cfg(any(target_arch = "aarch64", rust_analyzer))] -impl SyscallTrace { - fn from_parts(entry: &EnteredSyscall, exit_regs: &SavedFrame, exit: SystemTime) -> Self { - let function = entry.regs.gp_regs[8]; - let args = [ - entry.regs.gp_regs[0] as usize, - entry.regs.gp_regs[1] as usize, - entry.regs.gp_regs[2] as usize, - entry.regs.gp_regs[3] as usize, - entry.regs.gp_regs[4] as usize, - entry.regs.gp_regs[5] as usize, - ]; - let result = exit_regs.gp_regs[0] as usize; + let result = exit_regs.an[0]; + let entry = entry.timestamp; + + Self { + entry, + exit, + function, + args, + result, + } + } +} + +#[cfg(any(target_arch = "aarch64", rust_analyzer))] +impl SyscallTrace { + fn from_parts(entry: &EnteredSyscall, exit_regs: &SavedFrame, exit: SystemTime) -> Self { + let function = entry.regs.gp_regs[8]; + let args = [ + entry.regs.gp_regs[0], + entry.regs.gp_regs[1], + entry.regs.gp_regs[2], + entry.regs.gp_regs[3], + entry.regs.gp_regs[4], + entry.regs.gp_regs[5], + ]; + let result = exit_regs.gp_regs[0]; let entry = entry.timestamp; Self {