-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn foo<T: PartialEq>(a: &T, b: T) { | ||
a == b; //~ ERROR E0277 | ||
//~| NOTE 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 | ||
} | ||
|
||
fn main() { | ||
foo(&1, 1); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 |
||
|
||
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 | ||
|
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 aString
.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 #41745There 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...