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

erasing_op and identity_op should only be triggered for internal #7210

Closed
Kannen opened this issue May 12, 2021 · 0 comments · Fixed by #8204
Closed

erasing_op and identity_op should only be triggered for internal #7210

Kannen opened this issue May 12, 2021 · 0 comments · Fixed by #8204
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Kannen
Copy link

Kannen commented May 12, 2021

Lint name:
- erasing_op
- identity_op

I tried this code:

struct L(i32);
struct Meter;
impl core::ops::Mul<Meter> for  i32 {
    type Output = L;
    fn mul(self,_:Meter) -> L {
        L(self)
    }
}
fn check() {
  let _ = 0 * Meter;  //=> Fire clippy::erasing_op
  let _ = 1 * Meter;  //=> Fire clippy::identity_op
}

Multiply by 0 is not an erasing operation as the type is changed.
Multiply by 1 is not an identity operation as the type is changed.

I suppose that the lint erasing_op may only fire for where 0*x is 0:

let a = AType::new(...);

 let res: i32 = 0 * a; //the result is of the type of the 0
assert!(res;0);  //and the result is 0 <=> this is an erasing_op

And for erasing_op only where 1*x is x (1*x and x should have the same state): e.g:

  let a = AType::new(...);
  let res: AType = 1* a; //the result is of the type of a
  assert_same_binary_representation!(res;a);  //and the result is a

Meta

  • cargo clippy -V: clippy 0.1.54 (881c1ac 2021-05-08)
  • rustc -Vv:
    rustc 1.54.0-nightly (881c1ac40 2021-05-08)
    binary: rustc
    commit-hash: 881c1ac408d93bb7adaa3a51dabab9266e82eee8
    commit-date: 2021-05-08
    host: x86_64-unknown-linux-gnu
    release: 1.54.0-nightly
    LLVM version: 12.0.0
    
@Kannen Kannen added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 12, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label May 13, 2021
bors added a commit that referenced this issue Jan 2, 2022
[`erasing_op`] lint ignored when operation `Output` type is different from the type of constant `0`

fixes #7210

changelog:
[`erasing_op`] lint ignored when operation `Output` type is different from the type of constant `0`
@bors bors closed this as completed in 8419108 Jan 2, 2022
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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants