-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cast_lossless should lint about bool -> integer casts? #7947
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
Comments
@rustbot label +good-first-issue |
alright, i'll have a shot at this |
@rustbot claim |
Looking at the issue description again, I can actually understand why this instance isn't linted, as boolean to integer casts are always lossless. Could you explain why you think this should be linted? 🤔 (Sorry, to only ask that now after I added the label 😅 ) |
I thought this lint was for casts that are always lossless (as written), which is why it's being linted about. It comes from some places in my code where I was doing Same reason it complains about I guess bools are a different type of value, and there are no bools for which casts to integers aren't lossless, whereas only some integers cast to other integers are lossless. So you could argue that |
Okay, that makes sense, thanks for clarifying! I misunderstood the lint at first. I agree that this is a false negative like you reported. The code example in the lint documentation also shows an example where |
No worries, there's a lot of lints related to The docs for
|
Yes, that was the behavior I was thinking about ^^. I always find new lint's in Clippy's collection, it's actually quite cool :) |
Uh oh!
There was an error while loading. Please reload this page.
Lint name:
cast_lossless
I tried this code:
I expected to see this happen: Clippy to complain about the bool -> u8 cast, since it can be replaced with
u8::from(true)
.Instead, this happened: No lint was triggered
The lint description does say it is a cast between numeric types which can be replaced with safe conversion functions, and
bool
isn't strictly a numeric type, butu8::from(bool)
does exist. So it's unclear to me if this warning should be oncast_lossless
or a new lint, but I feel it should exist.Meta
Rust version (
rustc -Vv
):(clippy version 0.1.58 (18bc4be 2021-11-02))
The text was updated successfully, but these errors were encountered: