forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust-lang#8214 cmp_owned suggestion flips the comparison
- Loading branch information
1 parent
27845a9
commit 5b6ec8c
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// run-rustfix | ||
|
||
use std::fmt::{self, Display}; | ||
|
||
fn main() { | ||
let a = Foo; | ||
|
||
if a != "bar" { | ||
println!("foo"); | ||
} | ||
|
||
if a != "bar" { | ||
println!("foo"); | ||
} | ||
} | ||
|
||
struct Foo; | ||
|
||
impl Display for Foo { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "foo") | ||
} | ||
} | ||
|
||
impl PartialEq<&str> for Foo { | ||
fn eq(&self, other: &&str) -> bool { | ||
"foo" == *other | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// run-rustfix | ||
|
||
use std::fmt::{self, Display}; | ||
|
||
fn main() { | ||
let a = Foo; | ||
|
||
if a.to_string() != "bar" { | ||
println!("foo"); | ||
} | ||
|
||
if "bar" != a.to_string() { | ||
println!("foo"); | ||
} | ||
} | ||
|
||
struct Foo; | ||
|
||
impl Display for Foo { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "foo") | ||
} | ||
} | ||
|
||
impl PartialEq<&str> for Foo { | ||
fn eq(&self, other: &&str) -> bool { | ||
"foo" == *other | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error: this creates an owned instance just for comparison | ||
--> $DIR/comparison_flip.rs:8:8 | ||
| | ||
LL | if a.to_string() != "bar" { | ||
| ^^^^^^^^^^^^^ help: try: `a` | ||
| | ||
= note: `-D clippy::cmp-owned` implied by `-D warnings` | ||
|
||
error: this creates an owned instance just for comparison | ||
--> $DIR/comparison_flip.rs:12:17 | ||
| | ||
LL | if "bar" != a.to_string() { | ||
| ---------^^^^^^^^^^^^^ | ||
| | | ||
| help: try: `a != "bar"` | ||
|
||
error: aborting due to 2 previous errors | ||
|