-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #110877 - compiler-errors:binop-err, r=cjgillot
Provide better type hints when a type doesn't support a binary operator For example, when checking whether `vec![A] == vec![A]` holds, we first evaluate the LHS's ty, then probe for any `PartialEq` implementations for that. If none is found, we report an error by evaluating `Vec<A>: PartialEq<?0>` for fulfillment errors, but the RHS is not yet evaluated and remains an inference variable `?0`! To fix this, we evaluate the RHS and equate it to that RHS infer var `?0`, so that we are able to provide more detailed fulfillment errors for why `Vec<A>: PartialEq<Vec<A>>` doesn't hold (namely, the nested obligation `A: PartialEq<A>` doesn't hold). Fixes #95285 Fixes #110867
- Loading branch information
Showing
23 changed files
with
215 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
struct X; | ||
//~^ HELP consider annotating `X` with `#[derive(PartialEq)]` | ||
let xs = [X, X, X]; | ||
let eq = xs == [X, X, X]; | ||
//~^ ERROR binary operation `==` cannot be applied to type `[X; 3]` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0369]: binary operation `==` cannot be applied to type `[X; 3]` | ||
--> $DIR/eq-arr.rs:5:17 | ||
| | ||
LL | let eq = xs == [X, X, X]; | ||
| -- ^^ --------- [X; 3] | ||
| | | ||
| [X; 3] | ||
| | ||
note: an implementation of `PartialEq` might be missing for `X` | ||
--> $DIR/eq-arr.rs:2:5 | ||
| | ||
LL | struct X; | ||
| ^^^^^^^^ must implement `PartialEq` | ||
help: consider annotating `X` with `#[derive(PartialEq)]` | ||
| | ||
LL + #[derive(PartialEq)] | ||
LL | struct X; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0369`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fn main() { | ||
#[derive(Debug)] | ||
enum Foo { | ||
//~^ HELP consider annotating `Foo` with `#[derive(PartialEq)]` | ||
Bar, | ||
Qux, | ||
} | ||
|
||
let vec1 = vec![Foo::Bar, Foo::Qux]; | ||
let vec2 = vec![Foo::Bar, Foo::Qux]; | ||
assert_eq!(vec1, vec2); | ||
//~^ ERROR binary operation `==` cannot be applied to type `Vec<Foo>` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0369]: binary operation `==` cannot be applied to type `Vec<Foo>` | ||
--> $DIR/eq-vec.rs:11:5 | ||
| | ||
LL | assert_eq!(vec1, vec2); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| Vec<Foo> | ||
| Vec<Foo> | ||
| | ||
note: an implementation of `PartialEq` might be missing for `Foo` | ||
--> $DIR/eq-vec.rs:3:5 | ||
| | ||
LL | enum Foo { | ||
| ^^^^^^^^ must implement `PartialEq` | ||
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: consider annotating `Foo` with `#[derive(PartialEq)]` | ||
| | ||
LL + #[derive(PartialEq)] | ||
LL | enum Foo { | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0369`. |
Oops, something went wrong.