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 lint suggestion does not compile #2795

Closed
zhangsoledad opened this issue May 24, 2018 · 2 comments
Closed

op_ref lint suggestion does not compile #2795

zhangsoledad opened this issue May 24, 2018 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@zhangsoledad
Copy link

zhangsoledad commented May 24, 2018

fn main() {
    let target = 3;
    let sample = vec![1,2,3,4,5];
    let _found = sample.iter().find(|&v| v < &target);
}

Clippy suggests the following change:

 --> src/main.rs:4:42
  |
4 |     let _found = sample.iter().find(|&v| v < &target);
  |                                          ^^^^-------
  |                                              |
  |                                              help: use the right value directly: `target`
  |
  = note: #[warn(op_ref)] on by default
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.204/index.html#op_ref

which would not compile:

error[E0308]: mismatched types
 --> src/main.rs:4:46
  |
4 |     let _found = sample.iter().find(|&v| v < target);
  |                                              ^^^^^^
  |                                              |
  |                                              expected reference, found integral variable
  |                                              help: consider borrowing here: `&target`
  |
  = note: expected type `&_`
             found type `{integer}`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

rust-toolchain: 1.28.0-nightly (71e87be 2018-05-22)
clippy: 0.0.204(e7a3e03)

@oli-obk
Copy link
Contributor

oli-obk commented May 24, 2018

Yea, we need to handle multiple deref levels... and suggest to deref the left side instead

@phansch phansch added the C-bug Category: Clippy is not doing the correct thing label May 31, 2018
@phansch phansch added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Apr 19, 2019
@phansch phansch added the L-suggestion Lint: Improving, adding or fixing lint suggestions label Aug 24, 2019
@flip1995
Copy link
Member

flip1995 commented Oct 9, 2019

Duplicate of #2597

@flip1995 flip1995 marked this as a duplicate of #2597 Oct 9, 2019
@flip1995 flip1995 closed this as completed Oct 9, 2019
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

4 participants