-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Diagnostics: suggest using from_str when calling parse on a type that implements FromStr #77843
Copy link
Copy link
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Problem
I find myself confusing the
parseandfrom_strmethods quite often. Take for example:error[E0599]: no function or associated item named `parse` found for struct `connection_string::JdbcString` in the current scope --> src\connector\mssql.rs:363:55 | 363 | let mut jdbc = connection_string::JdbcString::parse(input)?; | ^^^^^ function or associated item not found in `connection_string::JdbcString`parsedoesn't exist onJdbcString;from_strdoes. So the way to fix it would be to write:Solution
It'd be great if the diagnostic could detect if
parsewas called on a type that implementsFromStrand suggest to usefrom_strinstead:error[E0599]: no function or associated item named `parse` found for struct `connection_string::JdbcString` in the current scope --> src\connector\mssql.rs:363:55 | 363 | let mut jdbc = connection_string::JdbcString::parse(input)?; | ^^^^^ function or associated item not found in `connection_string::JdbcString` | | | help: did you mean to call `connection_string::JdbcString::from_str`?