-
Notifications
You must be signed in to change notification settings - Fork 35
lint: enable clippy cast lints #405
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -300,14 +300,22 @@ impl fmt::Display for U256 { | |
| // Divide by 10, starting at the most significant bytes | ||
| for byte in &mut bytes { | ||
| let value = carry * 256 + u32::from(*byte); | ||
| *byte = (value / 10) as u8; | ||
| // `carry` is the previous iteration's `value % 10`, so it is at | ||
| // most 9 and `value` is at most 9 * 256 + 255 = 2559. The | ||
| // quotient is therefore at most 255 and fits in a `u8`. | ||
| #[allow(clippy::cast_possible_truncation)] | ||
| { | ||
| *byte = (value / 10) as u8; | ||
| } | ||
| carry = value % 10; | ||
|
|
||
| if *byte != 0 { | ||
| is_zero = false; | ||
| } | ||
| } | ||
|
|
||
| // `carry` is a remainder modulo 10, so it is at most 9. | ||
| #[allow(clippy::cast_possible_truncation)] | ||
| digits.push(carry as u8); | ||
| } | ||
|
|
||
|
|
@@ -335,7 +343,11 @@ impl FromStr for U256 { | |
| // Add to the least significant bytes first | ||
| for byte in bytes.iter_mut().rev() { | ||
| let value = u32::from(*byte) * 10 + carry; | ||
| *byte = (value % 256) as u8; | ||
| // A remainder modulo 256 is at most 255, so it fits in a `u8`. | ||
| #[allow(clippy::cast_possible_truncation)] | ||
| { | ||
| *byte = (value % 256) as u8; | ||
|
Contributor
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. In 724f851: This is just confusing. We should write
Contributor
Author
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. Yeah, I think let me fix these and then I'll undraft it |
||
| } | ||
| carry = value / 256; | ||
| } | ||
| if 0 < carry { | ||
|
|
||
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.
In 724f851:
We should use
u8::try_fromandunwrapif we really believe this is impossible.