-
Notifications
You must be signed in to change notification settings - Fork 63
clippy: fix cast_lossless lint #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xtqqczze
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
xtqqczze:clippy/cast_lossless
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,7 +215,7 @@ fn multiply_mix(x: u64, y: u64) -> u64 { | |
| )) { | ||
| // We compute the full u64 x u64 -> u128 product, this is a single mul | ||
| // instruction on x86-64, one mul plus one mulhi on ARM64. | ||
| 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; | ||
|
Comment on lines
-218
to
220
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 let (lo, hi) = x.carrying_mul(y, 0); |
||
|
|
||
|
|
@@ -239,8 +239,8 @@ fn multiply_mix(x: u64, y: u64) -> u64 { | |
| let hy = (y >> 32) as u32; | ||
|
|
||
| // u32 x u32 -> u64 the low bits of one with the high bits of the other. | ||
| let afull = (lx as u64).wrapping_mul(hy as u64); | ||
| let bfull = (hx as u64).wrapping_mul(ly as u64); | ||
| let afull = u64::from(lx).wrapping_mul(u64::from(hy)); | ||
| let bfull = u64::from(hx).wrapping_mul(u64::from(ly)); | ||
|
|
||
| // Combine, swapping low/high of one of them so the upper bits of the | ||
| // product of one combine with the lower bits of the other. | ||
|
|
@@ -271,14 +271,14 @@ fn hash_bytes(bytes: &[u8]) -> u64 { | |
| s0 ^= u64::from_le_bytes(bytes[0..8].try_into().unwrap()); | ||
| s1 ^= u64::from_le_bytes(bytes[len - 8..].try_into().unwrap()); | ||
| } else if len >= 4 { | ||
| s0 ^= u32::from_le_bytes(bytes[0..4].try_into().unwrap()) as u64; | ||
| s1 ^= u32::from_le_bytes(bytes[len - 4..].try_into().unwrap()) as u64; | ||
| s0 ^= u64::from(u32::from_le_bytes(bytes[0..4].try_into().unwrap())); | ||
| s1 ^= u64::from(u32::from_le_bytes(bytes[len - 4..].try_into().unwrap())); | ||
| } else if len > 0 { | ||
| let lo = bytes[0]; | ||
| let mid = bytes[len / 2]; | ||
| let hi = bytes[len - 1]; | ||
| s0 ^= lo as u64; | ||
| s1 ^= ((hi as u64) << 8) | mid as u64; | ||
| s0 ^= u64::from(lo); | ||
| s1 ^= (u64::from(hi) << 8) | u64::from(mid); | ||
| } | ||
| } else { | ||
| // Handle bulk (can partially overlap with suffix). | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the number of other
ascasts 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.