Skip to content
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

Fix FP in inherent_to_string when the function has generic parameters #6771

Merged
merged 1 commit into from
Feb 21, 2021

Conversation

MortenLohne
Copy link
Contributor

Minimal example of the false positive:

struct G;

impl G {
    fn to_string<const _N: usize>(&self) -> String {
        "G.to_string()".to_string()
    }
}

fn main() {
    let g = G;
    g.to_string::<1>();
}

Clippy emits an inherent_to_string warning, and suggests that we implement Display for G instead. However, this is not possible, since the generic parameter _N only exists in this function, not in G itself. This particular example uses const generics, which is where the issue is most likely to come up, but this PR skips the lint if the to_string function has any kind of generic parameters.

changelog: Fix FP in inherent_to_string

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 20, 2021
@flip1995
Copy link
Member

@bors r+

Thanks! And welcome to Clippy 🎉

@bors
Copy link
Collaborator

bors commented Feb 21, 2021

📌 Commit 19a3775 has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Feb 21, 2021

⌛ Testing commit 19a3775 with merge 728f397...

@bors
Copy link
Collaborator

bors commented Feb 21, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 728f397 to master...

@bors bors merged commit 728f397 into rust-lang:master Feb 21, 2021
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.

None yet

4 participants