You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Something along the lines of "you are trying to compare a refference to to Type, try dereferencing first" would be nice, right now it just has the usual PartialEq not implemented.
that would certainly improve things, but in this case the error message could be even more specific and thereby helpful by providing the information about deref-ing, so i would keep it as a separate issue, i think
fnmain(){let x:usize = 3;let y:&usize = &3;if x == y {println!("asdf");}if y == x {println!("asdf");}if3 == &3{println!("asdf");}if&3 == 3{println!("asdf");}}
error[E0308]: mismatched types
--> src/main.rs:4:13
|
4 | if x == y {
| ^
| |
| expected usize, found &usize
| help: consider dereferencing the borrow: `*y`
|
= note: expected type `usize`
found type `&usize`
error[E0277]: the trait bound `&usize: std::cmp::PartialEq<usize>` is not satisfied
--> src/main.rs:7:10
|
7 | if y == x {
| ^^ can't compare `&usize` with `usize`
|
= help: the trait `std::cmp::PartialEq<usize>` is not implemented for `&usize`
error[E0277]: the trait bound `{integer}: std::cmp::PartialEq<&{integer}>` is not satisfied
--> src/main.rs:10:10
|
10 | if 3 == &3 {
| ^^ can't compare `{integer}` with `&{integer}`
|
= help: the trait `std::cmp::PartialEq<&{integer}>` is not implemented for `{integer}`
error[E0277]: the trait bound `&{integer}: std::cmp::PartialEq<{integer}>` is not satisfied
--> src/main.rs:13:11
|
13 | if &3 == 3 {
| ^^ can't compare `&{integer}` with `{integer}`
|
= help: the trait `std::cmp::PartialEq<{integer}>` is not implemented for `&{integer}`
error[E0308]: mismatched types
--> src/main.rs:4:13
|
4 | if x == y {
| ^
| |
| expected usize, found &usize
| help: consider dereferencing the borrow: `*y`
|
= note: expected type `usize`
found type `&usize`
error[E0277]: can't compare `&usize` with `usize`
--> src/main.rs:7:10
|
7 | if y == x {
| ^^ no implementation for `&usize == usize`
|
= help: the trait `std::cmp::PartialEq<usize>` is not implemented for `&usize`
error[E0277]: can't compare `{integer}` with `&{integer}`
--> src/main.rs:10:10
|
10 | if 3 == &3 {
| ^^ no implementation for `{integer} == &{integer}`
|
= help: the trait `std::cmp::PartialEq<&{integer}>` is not implemented for `{integer}`
error[E0277]: can't compare `&{integer}` with `{integer}`
--> src/main.rs:13:11
|
13 | if &3 == 3 {
| ^^ no implementation for `&{integer} == {integer}`
|
= help: the trait `std::cmp::PartialEq<{integer}>` is not implemented for `&{integer}`
Triage: current output is only slightly improved over previous output.
error[E0308]: mismatched types
--> src/main.rs:4:13
|
4 | if x == y {
| ^
| |
| expected `usize`, found `&usize`
| help: consider dereferencing the borrow: `*y`
error[E0277]: can't compare `&usize` with `usize`
--> src/main.rs:7:10
|
7 | if y == x {
| ^^ no implementation for `&usize == usize`
|
= help: the trait `PartialEq<usize>` is not implemented for `&usize`
error[E0277]: can't compare `{integer}` with `&{integer}`
--> src/main.rs:10:10
|
10 | if 3 == &3 {
| ^^ no implementation for `{integer} == &{integer}`
|
= help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}`
error[E0277]: can't compare `&{integer}` with `{integer}`
--> src/main.rs:13:11
|
13 | if &3 == 3 {
| ^^ no implementation for `&{integer} == {integer}`
|
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
It's not clear what should improve to make this better. Should we try to detect if T implements the trait and if so, suggest dereferencing &T?
Should we try to detect if T implements the trait and if so, suggest dereferencing &T?
Yes, I think we should do exactly that. I think that #57621, #52544 and #44695 cover that requirement as well (but lets keep them open and close in one sweep once we fix this).
error[E0308]: mismatched types
--> f16.rs:18:13
|
18 | if x == y {
| ^ expected `usize`, found `&usize`
|
help: consider dereferencing the borrow
|
18 | if x == *y {
| +
error[E0369]: can't compare `&usize` with `usize`
--> f16.rs:21:10
|
21 | if y == x {
| - ^^ - usize
| |
| &usize
|
help: `==` can be applied on `&usize`
|
21 | if y == &x {
| +
help: `==` can be used on `usize`, you can dereference `y`
|
21 | if *y == x {
| +
error[E0277]: can't compare `{integer}` with `&{integer}`
--> f16.rs:24:10
|
24 | if 3 == &3 {
| ^^ no implementation for `{integer} == &{integer}`
|
= help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}`
error[E0277]: can't compare `&{integer}` with `{integer}`
--> f16.rs:27:11
|
27 | if &3 == 3 {
| ^^ no implementation for `&{integer} == {integer}`
|
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
error[E0308]: mismatched types
--> src/main.rs:4:13
|
4 | if x == y {
| - ^ expected `usize`, found `&usize`
| |
| expected because this is `usize`
|
help: consider dereferencing the borrow
|
4 | if x == *y {
| +
error[E0277]: can't compare `&usize` with `usize`
--> src/main.rs:7:10
|
7 | if y == x {
| ^^ no implementation for `&usize == usize`
|
= help: the trait `PartialEq<usize>` is not implemented for `&usize`
= help: the trait `PartialEq` is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `&usize`
error[E0277]: can't compare `{integer}` with `&{integer}`
--> src/main.rs:10:10
|
10 | if 3 == &3 {
| ^^ no implementation for `{integer} == &{integer}`
|
= help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}`
= help: the following other types implement trait `PartialEq<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
error[E0277]: can't compare `&{integer}` with `{integer}`
--> src/main.rs:13:11
|
13 | if &3 == 3 {
| ^^ no implementation for `&{integer} == {integer}`
|
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
= help: the following other types implement trait `PartialEq<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
Activity
estebank commentedon Mar 21, 2017
Would the following output (as proposed in #40565) be enough to make the situation a bit more clear?
iqualfragile commentedon Mar 21, 2017
that would certainly improve things, but in this case the error message could be even more specific and thereby helpful by providing the information about deref-ing, so i would keep it as a separate issue, i think
Auto merge of #41559 - GuillaumeGomez:partial-eq-msg, r=estebank
estebank commentedon Dec 6, 2017
Current output for:
There's room for improvement.
estebank commentedon Mar 8, 2019
Current output
estebank commentedon Sep 26, 2019
CC #45109, #60497, #57621, #52544, #39942, #44695.
1 remaining item
rylev commentedon Dec 9, 2020
Triage: current output is only slightly improved over previous output.
It's not clear what should improve to make this better. Should we try to detect if
Timplements the trait and if so, suggest dereferencing&T?estebank commentedon Jan 12, 2021
Yes, I think we should do exactly that. I think that #57621, #52544 and #44695 cover that requirement as well (but lets keep them open and close in one sweep once we fix this).
estebank commentedon Oct 18, 2021
Output with #90006:
estebank commentedon Nov 17, 2023
Another case that should be accounted for (from #67571):
estebank commentedon Nov 17, 2023
Triage, few changes:
sjwang05 commentedon Nov 28, 2023
I've gotten the output to look like this:
I'll see if I can get Rhs suggestions working.
@rustbot claim
estebank commentedon Nov 28, 2023
@sjwang05 if you make a new ObligationCauseCode you should be able to keep both lhs and rhs in it to do this.
sjwang05 commentedon Nov 29, 2023
Storing the lhs and rhs
HirIds inObligationCauseCode::BinOpdid the trick. Thanks!Auto merge of rust-lang#118431 - sjwang05:issue-44695, r=estebank