clippy: fix cast_lossless lint - #71
Open
xtqqczze wants to merge 1 commit into
Open
Conversation
xtqqczze
force-pushed
the
clippy/cast_lossless
branch
from
July 24, 2026 13:47
8cd43ba to
32b7469
Compare
Member
|
Is there any motivation behind this? |
Author
|
The change avoids some |
scottmcm
requested changes
Jul 24, 2026
| rust-version = "1.77" | ||
|
|
||
| [workspace.lints.clippy] | ||
| cast_lossless = "warn" |
Member
There was a problem hiding this comment.
Given the number of other as casts here anyway, I don't see much value in this. The lint is pedantic for a reason; if you want to "fix" a pedantic lint I think you need better justification than what it says in the lint, since that wasn't enough to make it warn-by-default even in clippy.
Comment on lines
-218
to
220
| let full = (x as u128).wrapping_mul(y as u128); | ||
| let full = u128::from(x).wrapping_mul(u128::from(y)); | ||
| let lo = full as u64; | ||
| let hi = (full >> 64) as u64; |
Member
There was a problem hiding this comment.
If you want to change something here, I think a much better change would to stop needing all the explicit widening and narrowing in the first place.
The fix for the ases here isn't from, IMHO, but something more like
let (lo, hi) = x.carrying_mul(y, 0);
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.
https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless