style(lib): Address cast-possible-truncation clippy findings. - #4192
Open
Siech0 wants to merge 1 commit into
Open
style(lib): Address cast-possible-truncation clippy findings.#4192Siech0 wants to merge 1 commit into
Siech0 wants to merge 1 commit into
Conversation
Siech0
force-pushed
the
style/address-clippy-cast-possible-truncation
branch
2 times, most recently
from
September 11, 2026 15:38
0be7381 to
dddbd2e
Compare
Siech0
commented
Sep 11, 2026
| } | ||
| // Ok(_) => Owed at least what we hold, write all of it. | ||
| // Err(_) => Owed more than `usize` can represent, write all of it. | ||
| Ok(_) | Err(_) => { |
Author
There was a problem hiding this comment.
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
force-pushed
the
style/address-clippy-cast-possible-truncation
branch
from
September 11, 2026 21:24
dddbd2e to
234d115
Compare
Siech0
commented
Sep 11, 2026
| dst.buffer(msg); | ||
| !self.is_last | ||
| } | ||
| #[allow(clippy::cast_possible_truncation, reason="usize::MAX > len > remaining, cast truncation is impossible")] |
Author
There was a problem hiding this comment.
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
force-pushed
the
style/address-clippy-cast-possible-truncation
branch
from
September 11, 2026 21:40
234d115 to
3a8f9c3
Compare
Siech0
commented
Sep 11, 2026
Comment on lines
+399
to
+400
| self.bdp = WindowSize::try_from((bytes * 2).min(BDP_LIMIT as usize)) | ||
| .unwrap_or(WindowSize::MAX); |
Author
There was a problem hiding this comment.
Note: Having the min be within the try_from is 3 instructions faster than having it outside. It remains safe either route.
Siech0
force-pushed
the
style/address-clippy-cast-possible-truncation
branch
from
September 11, 2026 21:44
3a8f9c3 to
432e00f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Towards #4071