Add clippy::cast_possible_wrap to the lint set#135
Merged
tomcur merged 1 commit intolinebender:mainfrom Jan 16, 2026
Merged
Conversation
`clippy::cast_possible_wrap` checks for casting an unsigned integer to a signed integer of the same size. If the value is too large to fit in the signed integer, it will wrap around to negative numbers. Such casts will usually be used when doing some math, so scrutiny of the cast is probably welcome. It's similar to the already-enabled `clippy::cast_possible_truncation`. See linebender/vello#1364 for an example where the lint is useful. The similar lint `clippy::cast_sign_loss` more or less does the opposite, triggering for casts from signed to unsigned numeric types. Floats are included in this lint, as they do a saturating cast, making it more likely to have false positives: it triggers 65 times on `vello_common` currently. Perhaps this one should not be added to the canonical lint set.
DJMcNab
approved these changes
Jan 16, 2026
Member
DJMcNab
left a comment
There was a problem hiding this comment.
The important reason for my approval here is that uN::cast_signed are now a more idiomatic way to represent the cases where these semantics are desired.
xStrom
approved these changes
Jan 16, 2026
Member
xStrom
left a comment
There was a problem hiding this comment.
In theory this should detect cases that require extra attention, so it's fine.
The classic Clippy fear is there, that it will be super noisy. However, I ran this against the Xilem repo and didn't get a single hit, Kurbo only got two hits. So perhaps it's not too noisy after all. Let's try it out!
Member
|
See also rust-lang/rust-clippy#16407 |
github-merge-queue bot
pushed a commit
to linebender/vello
that referenced
this pull request
Jan 19, 2026
Fixed by adding a reasonable limitation on `MAX_KERNEL_SIZE`, and storing the kernel size as a `u8` instead of `usize`. The lint itself checks for possible wrapping when going from an unsigned to signed integer, and is not currently in our lint set (hence not triggered on CI). It triggers when manually requested. It probably should be included in the lint set, but that's for another time (linebender/linebender.github.io#135).
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.
clippy::cast_possible_wrapchecks for casting an unsigned integer to a signed integer of the same size. If the value is too large to fit in the signed integer, it will wrap around to negative numbers. Such casts will usually be used when doing some math, so scrutiny of the cast is probably welcome. It's similar to the already-enabledclippy::cast_possible_truncation.See linebender/vello#1364 for an example where the lint is useful.
The similar lint
clippy::cast_sign_lossmore or less does the opposite, triggering for casts from signed to unsigned numeric types. Floats are included in this lint, as they do a saturating cast, making it more likely to have false positives: it triggers 65 times onvello_commoncurrently. Perhaps this one should not be added to the canonical lint set (and I have not proposed adding it here).For the interested reader, rust-lang/rust-clippy#9231 has some further discussion of these lints.