Skip to content

style(lib): Address cast-possible-truncation clippy findings. - #4192

Open
Siech0 wants to merge 1 commit into
hyperium:masterfrom
Siech0:style/address-clippy-cast-possible-truncation
Open

style(lib): Address cast-possible-truncation clippy findings.#4192
Siech0 wants to merge 1 commit into
hyperium:masterfrom
Siech0:style/address-clippy-cast-possible-truncation

Conversation

@Siech0

@Siech0 Siech0 commented Sep 11, 2026

Copy link
Copy Markdown

Towards #4071

@Siech0
Siech0 force-pushed the style/address-clippy-cast-possible-truncation branch 2 times, most recently from 0be7381 to dddbd2e Compare September 11, 2026 15:38
Comment thread src/proto/h1/encode.rs
}
// Ok(_) => Owed at least what we hold, write all of it.
// Err(_) => Owed more than `usize` can represent, write all of it.
Ok(_) | Err(_) => {

@Siech0 Siech0 Sep 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this can just be folded to -> _, but I felt like keeping the separation makes the clarity of why that is the case more obvious.

@Siech0
Siech0 force-pushed the style/address-clippy-cast-possible-truncation branch from dddbd2e to 234d115 Compare September 11, 2026 21:24
Comment thread src/proto/h1/encode.rs
dst.buffer(msg);
!self.is_last
}
#[allow(clippy::cast_possible_truncation, reason="usize::MAX > len > remaining, cast truncation is impossible")]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did an analysis on the assembly using try_from would produce here, and it would be a regression in performance on 32-bit systems. the as cast here does allow the compiler to enforce a more tight invariant and it is completely sound so I allowed it explicitly.

@Siech0
Siech0 force-pushed the style/address-clippy-cast-possible-truncation branch from 234d115 to 3a8f9c3 Compare September 11, 2026 21:40
Comment thread src/proto/h2/ping.rs Outdated
Comment on lines +399 to +400
self.bdp = WindowSize::try_from((bytes * 2).min(BDP_LIMIT as usize))
.unwrap_or(WindowSize::MAX);

@Siech0 Siech0 Sep 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Having the min be within the try_from is 3 instructions faster than having it outside. It remains safe either route.

@Siech0
Siech0 force-pushed the style/address-clippy-cast-possible-truncation branch from 3a8f9c3 to 432e00f Compare September 11, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant