From 6aebef2168ed9e4f7a8759fa8d01cd87d14f2deb Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Fri, 13 Feb 2026 10:22:51 -0800 Subject: [PATCH] enable clippy lints for libkernel --- Cargo.toml | 7 +++++++ libkernel/Cargo.toml | 3 +++ libkernel/src/arch/arm64/memory/pg_tables.rs | 10 +++++----- libkernel/src/arch/arm64/memory/pg_tear_down.rs | 2 +- libkernel/src/arch/arm64/memory/pg_walk.rs | 2 +- libkernel/src/fs/filesystems/ext4/mod.rs | 2 +- libkernel/src/fs/filesystems/fat32/bpb.rs | 10 +++------- libkernel/src/memory/allocators/slab/slab.rs | 2 +- libkernel/src/memory/kbuf.rs | 2 +- libkernel/src/memory/permissions.rs | 2 +- libkernel/src/sync/mpsc.rs | 2 +- src/main.rs | 2 -- 12 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a77ec3e..d434ecf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,10 @@ [workspace] members = ["libkernel", "usertest"] +[workspace.lints.clippy] +semicolon_if_nothing_returned = "warn" +uninlined_format_args = "warn" + [package] name = "moss" version = "0.1.0" @@ -32,3 +36,6 @@ smp = [] strip = true opt-level = "z" codegen-units = 1 + +[lints] +workspace = true diff --git a/libkernel/Cargo.toml b/libkernel/Cargo.toml index 409608b..f4d6425 100644 --- a/libkernel/Cargo.toml +++ b/libkernel/Cargo.toml @@ -18,3 +18,6 @@ intrusive-collections = { version = "0.9.7", default-features = false } [dev-dependencies] rand = "0.9.1" tokio = { version = "1.47.1", features = ["full"] } + +[lints] +workspace = true diff --git a/libkernel/src/arch/arm64/memory/pg_tables.rs b/libkernel/src/arch/arm64/memory/pg_tables.rs index e7344bc..80c3ba6 100644 --- a/libkernel/src/arch/arm64/memory/pg_tables.rs +++ b/libkernel/src/arch/arm64/memory/pg_tables.rs @@ -323,19 +323,19 @@ where PM: PageTableMapper, { if attrs.phys.size() != attrs.virt.size() { - Err(MapError::SizeMismatch)? + Err(MapError::SizeMismatch)?; } if attrs.phys.size() < PAGE_SIZE { - Err(MapError::TooSmall)? + Err(MapError::TooSmall)?; } if !attrs.phys.is_page_aligned() { - Err(MapError::PhysNotAligned)? + Err(MapError::PhysNotAligned)?; } if !attrs.virt.is_page_aligned() { - Err(MapError::VirtNotAligned)? + Err(MapError::VirtNotAligned)?; } while attrs.virt.size() > 0 { @@ -442,7 +442,7 @@ where // Zero out the new table before use. ctx.mapper.with_page_table(new_pa, |new_pgtable| { - core::ptr::write_bytes(new_pgtable.as_ptr_mut() as *mut _ as *mut u8, 0, PAGE_SIZE) + core::ptr::write_bytes(new_pgtable.as_ptr_mut() as *mut _ as *mut u8, 0, PAGE_SIZE); })?; // Set the descriptor at the current level to point to the new table. diff --git a/libkernel/src/arch/arm64/memory/pg_tear_down.rs b/libkernel/src/arch/arm64/memory/pg_tear_down.rs index 9f0bf90..1192b8e 100644 --- a/libkernel/src/arch/arm64/memory/pg_tear_down.rs +++ b/libkernel/src/arch/arm64/memory/pg_tear_down.rs @@ -96,7 +96,7 @@ impl RecursiveTeardownWalker for L3Table { deallocator(addr); } } - })? + })?; } Ok(()) diff --git a/libkernel/src/arch/arm64/memory/pg_walk.rs b/libkernel/src/arch/arm64/memory/pg_walk.rs index 52c7ffc..a948a25 100644 --- a/libkernel/src/arch/arm64/memory/pg_walk.rs +++ b/libkernel/src/arch/arm64/memory/pg_walk.rs @@ -71,7 +71,7 @@ where T::NextLevel::walk(next_desc.cast(), sub_region, ctx, modifier)?; } else if desc.is_valid() { - Err(MapError::NotL3Mapped)? + Err(MapError::NotL3Mapped)?; } else { // Permit sparse mappings. continue; diff --git a/libkernel/src/fs/filesystems/ext4/mod.rs b/libkernel/src/fs/filesystems/ext4/mod.rs index b0f7bcb..a00476d 100644 --- a/libkernel/src/fs/filesystems/ext4/mod.rs +++ b/libkernel/src/fs/filesystems/ext4/mod.rs @@ -63,7 +63,7 @@ impl From for KernelError { ext4_view::Ext4Error::NotADirectory => KernelError::Fs(FsError::NotADirectory), ext4_view::Ext4Error::Corrupt(_) => KernelError::Fs(FsError::InvalidFs), e => { - error!("Unmapped EXT4 error: {:?}", e); + error!("Unmapped EXT4 error: {e:?}"); KernelError::Other("EXT4 error") } } diff --git a/libkernel/src/fs/filesystems/fat32/bpb.rs b/libkernel/src/fs/filesystems/fat32/bpb.rs index 1b2d88d..71b409a 100644 --- a/libkernel/src/fs/filesystems/fat32/bpb.rs +++ b/libkernel/src/fs/filesystems/fat32/bpb.rs @@ -65,8 +65,7 @@ impl BiosParameterBlock { 512 | 1024 | 2048 | 4096 => {} // Good! _ => { warn!( - "Bytes per sector {} is not a valid value (must be 512, 1024, 2048, or 4096).", - bytes_per_sector + "Bytes per sector {bytes_per_sector} is not a valid value (must be 512, 1024, 2048, or 4096)." ); return Err(FsError::InvalidFs.into()); } @@ -75,10 +74,7 @@ impl BiosParameterBlock { if !bpb.bytes_per_sector.is_power_of_two() { let bytes_per_sector = bpb.bytes_per_sector; - warn!( - "Bytes per sector 0x{:X} not a power of two.", - bytes_per_sector - ); + warn!("Bytes per sector 0x{bytes_per_sector:X} not a power of two.",); return Err(FsError::InvalidFs.into()); } @@ -93,7 +89,7 @@ impl BiosParameterBlock { if !bpb.root_cluster.is_valid() { let root_cluster = bpb.root_cluster; - warn!("Root cluster {} < 2.", root_cluster); + warn!("Root cluster {root_cluster} < 2."); return Err(FsError::InvalidFs.into()); } diff --git a/libkernel/src/memory/allocators/slab/slab.rs b/libkernel/src/memory/allocators/slab/slab.rs index e6506eb..76d3343 100644 --- a/libkernel/src/memory/allocators/slab/slab.rs +++ b/libkernel/src/memory/allocators/slab/slab.rs @@ -51,7 +51,7 @@ impl Slab { u16::MAX } else { (i + 1) as u16 - }) + }); } } diff --git a/libkernel/src/memory/kbuf.rs b/libkernel/src/memory/kbuf.rs index 5eccc06..b03a3b4 100644 --- a/libkernel/src/memory/kbuf.rs +++ b/libkernel/src/memory/kbuf.rs @@ -64,7 +64,7 @@ impl, C: CpuOps> KBufCore { |inner| &mut inner.write_waiters, |inner| if inner.buf.is_full() { None } else { Some(()) }, ) - .await + .await; } /// Pushes a value of type `T` into the buffer. If the buffer is full, this diff --git a/libkernel/src/memory/permissions.rs b/libkernel/src/memory/permissions.rs index c1e4240..ce78160 100644 --- a/libkernel/src/memory/permissions.rs +++ b/libkernel/src/memory/permissions.rs @@ -200,7 +200,7 @@ impl fmt::Display for PtePermissions { '-' }; - write!(f, "{}{}{} {}", r, w_or_c, x, user) + write!(f, "{r}{w_or_c}{x} {user}") } } diff --git a/libkernel/src/sync/mpsc.rs b/libkernel/src/sync/mpsc.rs index 71ecbd0..0f47db5 100644 --- a/libkernel/src/sync/mpsc.rs +++ b/libkernel/src/sync/mpsc.rs @@ -66,7 +66,7 @@ impl Drop for Reciever { state.recv_gone = true; WakeupType::None - }) + }); } } diff --git a/src/main.rs b/src/main.rs index 7f689a7..1c8541f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,6 @@ #![feature(used_with_arg)] #![feature(likely_unlikely)] #![feature(box_as_ptr)] -#![warn(clippy::semicolon_if_nothing_returned)] -#![warn(clippy::uninlined_format_args)] use alloc::{ boxed::Box,