-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
lint unnecessary literal casts #6116
Comments
Better to suggest: 1_u32 |
This would be currently linted by The lint could be improved though to generate suggestions as the one you gave. |
I think the lints serve different purposes. I |
Yes |
Hi, I'd be glad to give this a shot ! |
When testing my implementation, I noticed that there is some overlap with a previously existing lint that flags int literals that are casted to a float type. Would it be suitable to just extend the aforementioned lint so that it become "casting number literal to <cast_to> is unnecessary" ? If not, what would be a good way to handle the overlap ? |
@geoffreycopin I think what you suggest makes sense as that lint was already extended in #3842 to add the float cases. Even if later there's a decision to not enhance that lint, your code should go in that module to be able to handle the overlap. |
Lint unnecessary int-to-int and float-to-float casts This is an implementation of a lint that detects unnecessary casts of number literals, as discussed here: #6116 --- changelog: lint unnecessary as-casts of literals when they could be written using literal syntax.
Lint unnecessary int-to-int and float-to-float casts This is an implementation of a lint that detects unnecessary casts of number literals, as discussed here: #6116 --- changelog: lint unnecessary as-casts of literals when they could be written using literal syntax.
Fixed by #6187 |
Add a note to `as_conversions` I have seen a couple of examples where there are some misunderstandings of `as_conversions` ([1](#5890 (comment)), [2](#6116 (comment)) and [3](#6428)). This PR adds the note that explains its purpose and relationship with other `as` related casts. Open question: should I list every related lints for discoverbility, or just suggest how to find these? I chose the former because there's no way to list only and all `as` related lints (e.g. on All the Clippt Lints, 'cast' includes some noises, but `cast_` excludes some) even though I cannot guarantee the list will be updated to include future changes. --- changelog: Add a note to the document of `as_conversions`
What it does
Lints unnecessary as-casts of literals when they could be written using literal syntax.
Categories (optional)
clippy::style
What is the advantage of the recommended code over the original code
Drawbacks
None.
Example
Could be written as:
1u32
The text was updated successfully, but these errors were encountered: