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

Confused by clippy warn(op_ref) #2658

Closed
jgilray opened this issue Apr 11, 2018 · 1 comment
Closed

Confused by clippy warn(op_ref) #2658

jgilray opened this issue Apr 11, 2018 · 1 comment

Comments

@jgilray
Copy link

jgilray commented Apr 11, 2018

I'm confused by the following clippy warning:

warning: taken reference of right operand
  --> src/main.rs:55:31
   |
55 |                   .filter(|d| d <= &p) {  // include divisors of p^2 + 1 up to p
   |                               ^^^^^--
   |                                    |
   |                                    help: use the right value directly: `p`
   |
   = note: #[warn(op_ref)] on by default
   = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.193/index.html#op_ref

please note that the compiler won't let me use "p" in place of "&p". I followed the help link listed above and didn't understand what it was trying to tell me.

Here is the code where the warning occured:

    let sieve = Sieve::new(((PLIM * PLIM) as f64).sqrt() as usize);
    let mut v: Vec<usize> = vec![];
    for p in 1..PLIM {
        for d in Factors::new(&sieve
                  .factor(p*p+1).unwrap()).into_iter()
                  .filter(|d| d <= &p) {  // include divisors of p^2 + 1 up to p
            let r = (p * (p + d) + 1) / d;
            if r < 2_usize.pow(31) {  // ensure that don't exceed std::u64::MAX
                v.push(p * (p + d) * r);
            }
        }                                  
    }
@ghost
Copy link

ghost commented Apr 11, 2018

This is a duplicate of #2597.
The suggestion isn't clear. The lint wants you to deref the d instead of of referencing p.
https://rust-lang-nursery.github.io/rust-clippy/v0.0.193/index.html#op_ref

@oli-obk oli-obk closed this as completed Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants