Add clippy::cast_possible_wrap to the lint set
#135
Merged
+2
−1
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.