vello_cpu: Fix clippy::cast_possible_wrap in Gaussian blur#1364
Merged
tomcur merged 2 commits intolinebender:mainfrom Jan 19, 2026
Merged
vello_cpu: Fix clippy::cast_possible_wrap in Gaussian blur#1364tomcur merged 2 commits intolinebender:mainfrom
clippy::cast_possible_wrap in Gaussian blur#1364tomcur merged 2 commits intolinebender:mainfrom
Conversation
Fixed by adding a reasonable limitation on `MAX_KERNEL_SIZE` (checked at compile time), 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, along with `clippy::cast_sign_loss` (going from signed to unsigned), but that's for another time.
tomcur
commented
Jan 15, 2026
Comment on lines
+38
to
+47
| #[cfg(test)] | ||
| const _: () = const { | ||
| if MAX_KERNEL_SIZE.is_multiple_of(2) { | ||
| panic!("`MAX_KERNEL_SIZE` must be odd"); | ||
| } | ||
| if MAX_KERNEL_SIZE > u8::MAX as usize { | ||
| panic!("`MAX_KERNEL_SIZE` must be less than or equal to `u8::MAX`"); | ||
| } | ||
| }; | ||
|
|
Member
Author
There was a problem hiding this comment.
To ensure we don't accidentally break our own promise later!
tomcur
added a commit
to tomcur/linebender.github.io
that referenced
this pull request
Jan 15, 2026
`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.
tomcur
added a commit
to linebender/linebender.github.io
that referenced
this pull request
Jan 16, 2026
`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 (and I have not proposed adding it here). For the interested reader, rust-lang/rust-clippy#9231 has some further discussion of these lints.
grebmeg
approved these changes
Jan 18, 2026
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.
Fixed by adding a reasonable limitation on
MAX_KERNEL_SIZE, and storing the kernel size as au8instead ofusize.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).