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

Incorrect suspicious_op_assign_impl #5255

Closed
kjeremy opened this issue Mar 2, 2020 · 2 comments · Fixed by #5424
Closed

Incorrect suspicious_op_assign_impl #5255

kjeremy opened this issue Mar 2, 2020 · 2 comments · Fixed by #5424
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@kjeremy
Copy link

kjeremy commented Mar 2, 2020

The following triggers this lint and probably should not
https://github.com/rust-analyzer/rust-analyzer/blob/39a9e42bf8d363e83d92bedf0ad07e95a42b1602/crates/rust-analyzer/src/semantic_tokens.rs#L68

clippy 0.0.212 (69f99e7 2019-12-14)

@kjeremy
Copy link
Author

kjeremy commented Mar 2, 2020

@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Mar 3, 2020
@jpospychala
Copy link
Contributor

jpospychala commented Apr 5, 2020

The issue here is that AssignOp kind is ignored, but expression's top level operator is checked when triggering the lint.

Basic solution is to ignore all operators in expression if it's is part of AssignOp.

But it's also noticeable that AssignOp kind is not looked at while it should so lint doesn't detect following mistake:

impl AddAssign for Foo {
    fn add_assign(&mut self, other: Foo) {
        *self -= other;
    }
}

but it detects this one:

impl AddAssign for Foo {
    fn add_assign(&mut self, other: Foo) {
        *self = *self - other ;
    }
}

flip1995 added a commit to flip1995/rust-clippy that referenced this issue Apr 7, 2020
…l, r=flip1995

Incorrect suspicious_op_assign_impl

fixes rust-lang#5255

changelog: In suspicious_op_assign_impl ignore all operators in expression if it's part of AssignOp
@bors bors closed this as completed in 8fc592a Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants