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

op_ref: Following lint leads to unconditional recursion #7572

Closed
LeCyberDucky opened this issue Aug 16, 2021 · 0 comments · Fixed by #8298
Closed

op_ref: Following lint leads to unconditional recursion #7572

LeCyberDucky opened this issue Aug 16, 2021 · 0 comments · Fixed by #8298
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@LeCyberDucky
Copy link

Lint name: op_ref

I tried this code:

use std::ops::Mul;

#[derive(Clone, Copy)]
struct Vec3D {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

impl Mul<&Vec3D> for Vec3D {
    type Output = f64;

    fn mul(self, rhs: &Vec3D) -> Self::Output {
        self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
    }
}

impl Mul<Vec3D> for Vec3D {
    type Output = f64;

    fn mul(self, rhs: Vec3D) -> Self::Output {
        self * &rhs
    }
}

fn main() {
    let a = Vec3D{x: 1.0, y: 2.0, z: 3.0};
    let b = &Vec3D{x: 1.0, y: 2.0, z: 3.0};
    println!("{}", a * b);
    println!("{}", a * a);
}

The lint suggests removing the ampersand in the Mul<Vec3D> for Vec3D implementation. Doing that, however, leads to a warning about unconditional recursion, and, naturally, it causes the program to not function correctly.

Meta

  • cargo clippy -V: clippy 0.1.56 (2d2bc94 2021-08-15)
  • rustc -Vv:
rustc 1.56.0-nightly (2d2bc94c8 2021-08-15)
binary: rustc
commit-hash: 2d2bc94c8c3aa778e191f80261c726e4777439f1
commit-date: 2021-08-15
host: x86_64-pc-windows-msvc
release: 1.56.0-nightly
LLVM version: 12.0.1
@LeCyberDucky LeCyberDucky 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 Aug 16, 2021
@camsteffen camsteffen added the E-medium Call for participation: Medium difficulty level problem and requires some initial experience. label Aug 23, 2021
@bors bors closed this as completed in fff8e78 Jan 18, 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 E-medium Call for participation: Medium difficulty level problem and requires some initial experience. 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