diff options
Diffstat (limited to 'src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs new file mode 100644 index 000000000..662673abb --- /dev/null +++ b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs @@ -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 + } +} |