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 <jinankjain@microsoft.com>
This commit is contained in:
Jinank Jain 2025-04-02 07:51:34 +00:00
parent ea4693a091
commit b686a5bb24

View file

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