From b686a5bb24f949e3b201308d69b01e85c14f1ad6 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Wed, 2 Apr 2025 07:51:34 +0000 Subject: [PATCH] vm-allocator: Fix clippy warning for implicit saturating sub Use the builtin function to improve the readability of the code. Warning from beta compiler: error: manual arithmetic check found --> vm-allocator/src/address.rs:151:30 | |let adjust = if alignment > 1 { alignment - 1 } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: replace it with: `alignment.saturating_sub(1)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub = note: `-D clippy::implicit-saturating-sub` implied by `-D warnings` = help: to override `-D warnings` add`#[allow(clippy::implicit_saturating_sub)]` Signed-off-by: Jinank Jain --- vm-allocator/src/address.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm-allocator/src/address.rs b/vm-allocator/src/address.rs index 14e0335cd..a6e11dc63 100644 --- a/vm-allocator/src/address.rs +++ b/vm-allocator/src/address.rs @@ -148,7 +148,7 @@ impl AddressAllocator { if let Some(size_delta) = address.checked_sub(self.align_address(prev_end_address, alignment).raw_value()) { - let adjust = if alignment > 1 { alignment - 1 } else { 0 }; + let adjust = alignment.saturating_sub(1); if size_delta.raw_value() >= req_size { return Some( self.align_address(address.unchecked_sub(req_size + adjust), alignment),