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 invalid recommendation #1665

Closed
ghost opened this issue Apr 9, 2017 · 0 comments · Fixed by #1671
Closed

op_ref invalid recommendation #1665

ghost opened this issue Apr 9, 2017 · 0 comments · Fixed by #1671

Comments

@ghost
Copy link

ghost commented Apr 9, 2017

Here is my situation:

#[allow(dead_code)]
fn eg() {
    let a = "a".to_string();
    let b = "a";

    if b < &a {
        println!("OK");
    }
}
warning: taken reference of right operand
 --> src/lib.rs:6:8
  |
6 |     if b < &a {
  |        ^^^^^^
  |
  = note: #[warn(op_ref)] on by default
help: dereference the left operand instead
  |     if *b < a {
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#op_ref

After applying the recommendation...

#[allow(dead_code)]
fn eg() {
    let a = "a".to_string();
    let b = "a";

    if *b < a {
        println!("OK");
    }
}
error[E0308]: mismatched types
 --> src/lib.rs:6:13
  |
6 |     if *b < a {
  |             ^ expected str, found struct `std::string::String`
  |
  = note: expected type `str`
             found type `std::string::String`

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

Successfully merging a pull request may close this issue.

0 participants