Auto merge of #41559 - GuillaumeGomez:partial-eq-msg, r=estebank
Add better error message when == operator is badly used Part of #40660. With the following code: ```rust fn foo<T: PartialEq>(a: &T, b: T) { a == b; } fn main() { foo(&1, 1); } ``` It prints: ``` error[E0277]: the trait bound `&T: std::cmp::PartialEq<T>` is not satisfied --> test.rs:2:5 | 2 | a == b; | ^^^^^^ can't compare `&T` with `T` | = help: the trait `std::cmp::PartialEq<T>` is not implemented for `&T` = help: consider adding a `where &T: std::cmp::PartialEq<T>` bound error: aborting due to previous error ```
This commit is contained in:
commit
2e9139197e
16 changed files with 72 additions and 57 deletions
|
|
@ -11,9 +11,9 @@ error[E0277]: the trait bound `u32: std::ops::Add<impl Foo>` is not satisfied
|
|||
--> $DIR/equality.rs:34:9
|
||||
|
|
||||
34 | n + sum_to(n - 1)
|
||||
| ^^^^^^^^^^^^^^^^^ the trait `std::ops::Add<impl Foo>` is not implemented for `u32`
|
||||
| ^^^^^^^^^^^^^^^^^ no implementation for `u32 + impl Foo`
|
||||
|
|
||||
= note: no implementation for `u32 + impl Foo`
|
||||
= help: the trait `std::ops::Add<impl Foo>` is not implemented for `u32`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/equality.rs:53:18
|
||||
|
|
|
|||
|
|
@ -2,57 +2,57 @@ error[E0277]: the trait bound `{integer}: std::ops::Add<std::option::Option<{int
|
|||
--> $DIR/binops.rs:12:5
|
||||
|
|
||||
12 | 1 + Some(1);
|
||||
| ^^^^^^^^^^^ the trait `std::ops::Add<std::option::Option<{integer}>>` is not implemented for `{integer}`
|
||||
| ^^^^^^^^^^^ no implementation for `{integer} + std::option::Option<{integer}>`
|
||||
|
|
||||
= note: no implementation for `{integer} + std::option::Option<{integer}>`
|
||||
= help: the trait `std::ops::Add<std::option::Option<{integer}>>` is not implemented for `{integer}`
|
||||
|
||||
error[E0277]: the trait bound `usize: std::ops::Sub<std::option::Option<{integer}>>` is not satisfied
|
||||
--> $DIR/binops.rs:13:5
|
||||
|
|
||||
13 | 2 as usize - Some(1);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Sub<std::option::Option<{integer}>>` is not implemented for `usize`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ no implementation for `usize - std::option::Option<{integer}>`
|
||||
|
|
||||
= note: no implementation for `usize - std::option::Option<{integer}>`
|
||||
= help: the trait `std::ops::Sub<std::option::Option<{integer}>>` is not implemented for `usize`
|
||||
|
||||
error[E0277]: the trait bound `{integer}: std::ops::Mul<()>` is not satisfied
|
||||
--> $DIR/binops.rs:14:5
|
||||
|
|
||||
14 | 3 * ();
|
||||
| ^^^^^^ the trait `std::ops::Mul<()>` is not implemented for `{integer}`
|
||||
| ^^^^^^ no implementation for `{integer} * ()`
|
||||
|
|
||||
= note: no implementation for `{integer} * ()`
|
||||
= help: the trait `std::ops::Mul<()>` is not implemented for `{integer}`
|
||||
|
||||
error[E0277]: the trait bound `{integer}: std::ops::Div<&str>` is not satisfied
|
||||
--> $DIR/binops.rs:15:5
|
||||
|
|
||||
15 | 4 / "";
|
||||
| ^^^^^^ the trait `std::ops::Div<&str>` is not implemented for `{integer}`
|
||||
| ^^^^^^ no implementation for `{integer} / &str`
|
||||
|
|
||||
= note: no implementation for `{integer} / &str`
|
||||
= help: the trait `std::ops::Div<&str>` is not implemented for `{integer}`
|
||||
|
||||
error[E0277]: the trait bound `{integer}: std::cmp::PartialEq<std::string::String>` is not satisfied
|
||||
--> $DIR/binops.rs:16:5
|
||||
|
|
||||
16 | 5 < String::new();
|
||||
| ^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialEq<std::string::String>` is not implemented for `{integer}`
|
||||
| ^^^^^^^^^^^^^^^^^ can't compare `{integer}` with `std::string::String`
|
||||
|
|
||||
= note: can't compare `{integer}` with `std::string::String`
|
||||
= help: the trait `std::cmp::PartialEq<std::string::String>` is not implemented for `{integer}`
|
||||
|
||||
error[E0277]: the trait bound `{integer}: std::cmp::PartialOrd<std::string::String>` is not satisfied
|
||||
--> $DIR/binops.rs:16:5
|
||||
|
|
||||
16 | 5 < String::new();
|
||||
| ^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialOrd<std::string::String>` is not implemented for `{integer}`
|
||||
| ^^^^^^^^^^^^^^^^^ can't compare `{integer}` with `std::string::String`
|
||||
|
|
||||
= note: can't compare `{integer}` with `std::string::String`
|
||||
= help: the trait `std::cmp::PartialOrd<std::string::String>` is not implemented for `{integer}`
|
||||
|
||||
error[E0277]: the trait bound `{integer}: std::cmp::PartialEq<std::result::Result<{integer}, _>>` is not satisfied
|
||||
--> $DIR/binops.rs:17:5
|
||||
|
|
||||
17 | 6 == Ok(1);
|
||||
| ^^^^^^^^^^ the trait `std::cmp::PartialEq<std::result::Result<{integer}, _>>` is not implemented for `{integer}`
|
||||
| ^^^^^^^^^^ can't compare `{integer}` with `std::result::Result<{integer}, _>`
|
||||
|
|
||||
= note: can't compare `{integer}` with `std::result::Result<{integer}, _>`
|
||||
= help: the trait `std::cmp::PartialEq<std::result::Result<{integer}, _>>` is not implemented for `{integer}`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -210,18 +210,18 @@ error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied
|
|||
--> $DIR/cast-rfc0401.rs:63:13
|
||||
|
|
||||
63 | let _ = fat_v as *const Foo;
|
||||
| ^^^^^ the trait `std::marker::Sized` is not implemented for `[u8]`
|
||||
| ^^^^^ `[u8]` does not have a constant size known at compile-time
|
||||
|
|
||||
= note: `[u8]` does not have a constant size known at compile-time
|
||||
= help: the trait `std::marker::Sized` is not implemented for `[u8]`
|
||||
= note: required for the cast to the object type `Foo`
|
||||
|
||||
error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
|
||||
--> $DIR/cast-rfc0401.rs:72:13
|
||||
|
|
||||
72 | let _ = a as *const Foo;
|
||||
| ^ the trait `std::marker::Sized` is not implemented for `str`
|
||||
| ^ `str` does not have a constant size known at compile-time
|
||||
|
|
||||
= note: `str` does not have a constant size known at compile-time
|
||||
= help: the trait `std::marker::Sized` is not implemented for `str`
|
||||
= note: required for the cast to the object type `Foo`
|
||||
|
||||
error: casting `&{float}` as `f32` is invalid
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ error[E0277]: the trait bound `I + 'static: std::marker::Sized` is not satisfied
|
|||
--> $DIR/issue-5035-2.rs:14:8
|
||||
|
|
||||
14 | fn foo(_x: K) {} //~ ERROR: `I + 'static: std::marker::Sized` is not satisfied
|
||||
| ^^ the trait `std::marker::Sized` is not implemented for `I + 'static`
|
||||
| ^^ `I + 'static` does not have a constant size known at compile-time
|
||||
|
|
||||
= note: `I + 'static` does not have a constant size known at compile-time
|
||||
= help: the trait `std::marker::Sized` is not implemented for `I + 'static`
|
||||
= note: all local variables must have a statically known size
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ error[E0277]: the trait bound `u32: std::ops::Add<()>` is not satisfied
|
|||
25 | | bar(x,
|
||||
26 | |
|
||||
27 | | y),
|
||||
| |______________^ the trait `std::ops::Add<()>` is not implemented for `u32`
|
||||
| |______________^ no implementation for `u32 + ()`
|
||||
|
|
||||
= note: no implementation for `u32 + ()`
|
||||
= help: the trait `std::ops::Add<()>` is not implemented for `u32`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue