Skip to content

Conversation

samueltardieu
Copy link
Member

@samueltardieu samueltardieu commented May 13, 2025

This lint detects parsing of string literals into IP addresses when they are known correct.

changelog: [parsed_string_literals]: new lint

Inspired by this Zulip comment.

@rustbot
Copy link
Collaborator

rustbot commented May 13, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 13, 2025
@Jarcho
Copy link
Contributor

Jarcho commented May 14, 2025

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.

@samueltardieu
Copy link
Member Author

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

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 14, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

This comment has been minimized.

@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch 2 times, most recently from ceb8d7f to 938d056 Compare May 21, 2025 20:50
@samueltardieu
Copy link
Member Author

Rebased to take advantage of the new diagnostic items.

What about clippy::parsed_string_literals as a name?

@Jarcho
Copy link
Contributor

Jarcho commented May 21, 2025

That sounds like a good name.

@Jarcho
Copy link
Contributor

Jarcho commented May 21, 2025

@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch from 938d056 to ead8755 Compare May 21, 2025 22:07
@samueltardieu samueltardieu changed the title unnecessary_ip_addr_parse: new lint parsed_string_literals: new lint May 21, 2025
@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch from ead8755 to 67212c0 Compare May 24, 2025 09:15
@samueltardieu
Copy link
Member Author

Amended to avoid a useless string allocation during diagnostic production (and version number).

@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch 2 times, most recently from 77fc5d0 to a1dac58 Compare May 25, 2025 17:29
@samueltardieu
Copy link
Member Author

Added numerical/boolean types as well.

@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch 2 times, most recently from 6fb6b92 to 9c05182 Compare May 26, 2025 09:00
@samueltardieu samueltardieu requested a review from Jarcho May 28, 2025 13:59
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 28, 2025
@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch 2 times, most recently from b0fa40c to fc3dd92 Compare May 29, 2025 20:14
@samueltardieu
Copy link
Member Author

I've leveraged the existing clippy_utils::source::str_literal_to_char_literal to ensure that the original representation of a character literal is preserved when possible.

@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch from fc3dd92 to 42a298b Compare May 29, 2025 20:16
@rustbot

This comment has been minimized.

@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch from 42a298b to d7ce0e4 Compare June 5, 2025 23:56
@samueltardieu
Copy link
Member Author

@Jarcho Anything preventing this lint from being merged? It got a +1 on the FCP.

This lint detects parsing of string literals into primitive types or
IP addresses when they are known correct.
@samueltardieu samueltardieu force-pushed the unnecessary-ip-addr-parse branch from d7ce0e4 to 56bae3b Compare June 21, 2025 13:04
@samueltardieu
Copy link
Member Author

Updated Rust version to 1.90.0.

@samueltardieu
Copy link
Member Author

Ping @Jarcho

1 similar comment
@samueltardieu
Copy link
Member Author

Ping @Jarcho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants