lint: enable clippy cast lints - #405
Draft
stringhandler wants to merge 1 commit into
Draft
Conversation
cast_possible_wrap and cast_sign_loss have no hits at all. Turn them on. cast_possible_truncation had four hits, all provably safe by construction; annotate them at the site instead of allowing the lint crate-wide, so the existing 'every cast should contain a code comment' convention is enforced rather than aspirational.
apoelstra
reviewed
Sep 1, 2026
| // Jets take a handful of parameters at most, so the index stays well | ||
| // inside `u8` (and inside the a-z range this names them from). | ||
| #[allow(clippy::cast_possible_truncation)] | ||
| let identifier = (b'a' + i as u8) as char; |
Contributor
There was a problem hiding this comment.
In 724f851:
We should use u8::try_from and unwrap if we really believe this is impossible.
apoelstra
reviewed
Sep 1, 2026
| // 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.
In 724f851:
This is just confusing. We should write *byte = value as u8 and whitelist the lint with "truncation is deliberate".
Contributor
Author
There was a problem hiding this comment.
Yeah, I think let me fix these and then I'll undraft it
stringhandler
marked this pull request as draft
September 1, 2026 11:57
Contributor
|
I think the ones in the division code are probably fine to leave as casts. But if you want to make them use |
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.
cast_possible_wrap and cast_sign_loss have no hits at all. Turn them on.
cast_possible_truncation had four hits, all provably safe by construction; annotate them at the site instead of allowing the lint crate-wide, so the existing 'every cast should contain a code comment' convention is enforced rather than aspirational.
LLM suggested and generated