-
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 towards replacing from_str_radix
with str::parse
when the radix is 10
#6713
Comments
If this lint makes sense, I'd like to try implementing it myself! |
I believe this lint makes sense. We can easily change its category to
You can take this issue up and it seems like you've already found our Zulip. Could you comment And welcome to clippy 🙃 |
@rustbot label +A-lint +T-middle |
Thanks! Yeah I'll assign it to myself. |
@rustbot claim |
Thank you 🙃 can also include the
This should not be a problem if you only check for the literal Feel free to ask here or on Zulip if you have any more questions :) |
What it does
The lint suggests replacing e.g.
u16::from_str_radix(&string, 10)
withstring.parse()
.(Obviously, it could also be any other primitive with such associated function).
Categories (optional)
clippy::style
.What is the advantage of the recommended code over the original code?
The resulting code is shorter, easier to read and doesn't involve using
10
as a magic number.Drawbacks
Using
str::parse
instead, the user might have to specify types in some cases.Example
Could be written as:
(In a more complicated use case, the type of
num
will probably be inferred.)The text was updated successfully, but these errors were encountered: