-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add better error message when == operator is badly used #41559
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
@GuillaumeGomez you need to update the output of |
Ah thanks! |
416e528
to
be84188
Compare
The output looks way nicer this way. :D (Updated.) |
@@ -559,6 +559,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
trait_ref.to_predicate(), | |||
post_message); | |||
|
|||
let trait_display = format!("{}", trait_ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just let trait_display = trait_ref.to_string();
be84188
to
3f02379
Compare
Updated. |
I thought a better error message should suggest |
Well, I didn't add the where clause, it was already there. |
@GuillaumeGomez Ah I see. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -559,6 +559,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
trait_ref.to_predicate(), | |||
post_message); | |||
|
|||
let trait_display = trait_ref.to_string(); | |||
if trait_display.starts_with("std::cmp::PartialEq") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work with no_std
(as pointed out before to me).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point!
| | ||
= help: the trait `std::cmp::PartialEq<std::string::String>` is not implemented for `{integer}` | ||
= note: can't compare `{integer}` with `std::string::String` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The label and a note have the same text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, didn't look more below. :-/
| | ||
= help: the trait `std::cmp::PartialEq<std::result::Result<{integer}, _>>` is not implemented for `{integer}` | ||
= note: can't compare `{integer}` with `std::result::Result<{integer}, _>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
3f02379
to
a908964
Compare
Updated. |
Label and note seem to have the same text still? @GuillaumeGomez Was that intentional? |
No, I need to fix this. |
a908964
to
88082da
Compare
Updated. |
☔ The latest upstream changes (presumably #41745) made this pull request unmergeable. Please resolve the merge conflicts. |
Any particular reason this isn't a |
@arielb1: I thought about it. So as you prefer. |
@alexcrichton the difference in output at the moment is swapping the note and the label, but I have the same hangup as @arielb1 as I would rather avoid checking paths by string. That being said, @GuillaumeGomez I'd be down with setting |
Ok so we definitely agree on this: If |
88082da
to
7bb85e9
Compare
Ok, updated. Let's see what the CI says. |
trait_ref.self_ty())); | ||
} else { | ||
err.span_label(span, | ||
&*format!("{}the trait `{}` is not implemented for `{}`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is &*
necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'm surprised about it but it seems that it fails otherwise because of the From<&str>
not matching and auto-dereferencing a String
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to use the format!()
directly since #41745
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's since my last rebase that I can't, so not sure...
@GuillaumeGomez the failing files are:
|
@estebank: Ah great, thanks for the list! :) |
7bb85e9
to
747287a
Compare
Updated. |
| | ||
= note: no implementation for `{integer} + std::option::Option<{integer}>` | ||
= help: the trait `std::ops::Add<std::option::Option<{integer}>>` is not implemented for `{integer}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not prevent the merge of this PR, but reading this file I feel the full output of this error should be:
error[E0277]: the trait `std::ops::Add<std::option::Option<{integer}>>` is not implemented for `{integer}`
--> $DIR/binops.rs:12:5
|
12 | 1 + Some(1);
| ^^^^^^^^^^^ no implementation for `{integer} + std::option::Option<{integer}>`
instead of
error[E0277]: the trait bound `{integer}: std::ops::Add<std::option::Option<{integer}>>` is not satisfied
--> $DIR/binops.rs:12:5
|
12 | 1 + Some(1);
| ^^^^^^^^^^^ no implementation for `{integer} + std::option::Option<{integer}>`
|
= help: the trait `std::ops::Add<std::option::Option<{integer}>>` is not implemented for `{integer}`
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate having both in case the user isn't well aware of the Add
and equivalent traits.
What's the current state of this PR please @GuillaumeGomez @estebank? I'm having trouble following :) |
@carols10cents thanks for the ping @GuillaumeGomez can you post the visual diff of one of the modified cfail tests, like this one against the current nightly? I want to make sure that we're not removing information. If the new output looks fine for that, I'll r+. |
Sure. Here it is:
And the old one:
|
@bors r+ |
📌 Commit 747287a has been approved by |
⌛ Testing commit 747287a with merge 2e91391... |
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 ```
☀️ Test successful - status-appveyor, status-travis |
Part of #40660.
With the following code:
It prints: