-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #8299 - marekdownar:8214, r=Manishearth
#8214 cmp_owned suggestion flips the comparison changelog: ``[`cmp_owned`]`` fixes #8214 so that the suggestion does not flip the comparison
- Loading branch information
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 | ||
|