diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-03-01 05:49:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-01 05:49:51 +0100 |
| commit | 51e09764411a5882cd210d2a205ec425b7194413 (patch) | |
| tree | dce390e49f1cf64b48a404183ac83391a86145c4 /tests | |
| parent | 91eb721cbc11755b459330718785f79e8dd45ff8 (diff) | |
| parent | 9cd1de573bbd48a1d5785dfc90bfffb78814c4ed (diff) | |
| download | rust-51e09764411a5882cd210d2a205ec425b7194413.tar.gz rust-51e09764411a5882cd210d2a205ec425b7194413.zip | |
Rollup merge of #137171 - makai410:swapping-e0277, r=compiler-errors
Suggest swapping equality on E0277 Closes: #132695 .
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/suggestions/partialeq_suggest_swap_on_e0277.rs | 11 | ||||
| -rw-r--r-- | tests/ui/suggestions/partialeq_suggest_swap_on_e0277.stderr | 24 |
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/suggestions/partialeq_suggest_swap_on_e0277.rs b/tests/ui/suggestions/partialeq_suggest_swap_on_e0277.rs new file mode 100644 index 00000000000..2ebbed3c740 --- /dev/null +++ b/tests/ui/suggestions/partialeq_suggest_swap_on_e0277.rs @@ -0,0 +1,11 @@ +struct T(String); + +impl PartialEq<String> for T { + fn eq(&self, other: &String) -> bool { + &self.0 == other + } +} + +fn main() { + String::from("Girls Band Cry") == T(String::from("Girls Band Cry")); //~ can't compare `String` with `T` [E0277] +} diff --git a/tests/ui/suggestions/partialeq_suggest_swap_on_e0277.stderr b/tests/ui/suggestions/partialeq_suggest_swap_on_e0277.stderr new file mode 100644 index 00000000000..ebe103ef19a --- /dev/null +++ b/tests/ui/suggestions/partialeq_suggest_swap_on_e0277.stderr @@ -0,0 +1,24 @@ +error[E0277]: can't compare `String` with `T` + --> $DIR/partialeq_suggest_swap_on_e0277.rs:10:36 + | +LL | String::from("Girls Band Cry") == T(String::from("Girls Band Cry")); + | ^^ no implementation for `String == T` + | + = help: the trait `PartialEq<T>` is not implemented for `String` + = help: the following other types implement trait `PartialEq<Rhs>`: + `String` implements `PartialEq<&str>` + `String` implements `PartialEq<ByteStr>` + `String` implements `PartialEq<ByteString>` + `String` implements `PartialEq<Cow<'_, str>>` + `String` implements `PartialEq<str>` + `String` implements `PartialEq` + = note: `T` implements `PartialEq<String>` +help: consider swapping the equality + | +LL - String::from("Girls Band Cry") == T(String::from("Girls Band Cry")); +LL + T(String::from("Girls Band Cry")) == String::from("Girls Band Cry"); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. |
