-
Notifications
You must be signed in to change notification settings - Fork 1.8k
parsed_string_literals: new lint
#14794
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?
parsed_string_literals: new lint
#14794
Conversation
|
Is there any reason to limit linting this to just ip addresses? Any call to parse on a string literal has the same issue regardless of the type. The suggestion would have to be specialised per type so it could only exist for a subset of cases. Possibly a config to ignore specific types, but I'm not sure if this would be needed. |
|
I guess this could be extended, but at this stage I'm not sure we should make a generic lint for this. Specialized lints can be collectively renamed into a more generic one if we don't see one of them being disabled in isolation. I'd be more comfortable with a separate lint for the time being. In any case, I'll suspend this PR until rust-lang/rust#140976 is merged and synced to Clippy (hopefully tomorrow). @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
ceb8d7f to
938d056
Compare
|
Rebased to take advantage of the new diagnostic items. What about |
|
That sounds like a good name. |
938d056 to
ead8755
Compare
unnecessary_ip_addr_parse: new lintparsed_string_literals: new lint
ead8755 to
67212c0
Compare
|
Amended to avoid a useless string allocation during diagnostic production (and version number). |
77fc5d0 to
a1dac58
Compare
|
Added numerical/boolean types as well. |
6fb6b92 to
9c05182
Compare
b0fa40c to
fc3dd92
Compare
|
I've leveraged the existing |
fc3dd92 to
42a298b
Compare
2c22b5f to
588007e
Compare
| try_parse::<$ty>( | ||
| lit, | ||
| Some(stringify!($ty)), | ||
| explicit_type.map(|ty| snippet_with_applicability(cx, ty.span, "_", &mut app)) |
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.
A snippet isn't needed here and it's the slowest available option. The fastest thing to do is match the type down to a single segment path and compare the symbol.
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.
Done, and .with_source_text() is used whenever possible at lint emission type to limit the number of copies.
588007e to
e8f3f64
Compare
e8f3f64 to
6257caf
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6257caf to
6fccef3
Compare
This comment has been minimized.
This comment has been minimized.
6fccef3 to
463acf7
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Anything needs to be modified? |
463acf7 to
aa94d54
Compare
aa94d54 to
16dd9db
Compare
|
(second push was to update a test comment now that we don't use type from |
16dd9db to
f092032
Compare
|
Changes in the recent push:
|
This comment has been minimized.
This comment has been minimized.
This lint detects parsing of string literals into primitive types or IP addresses when they are known correct.
f092032 to
362a075
Compare
This lint detects parsing of string literals into IP addresses when they are known correct.
changelog: [
parsed_string_literals]: new lintInspired by this Zulip comment.