Skip to content

Commit

Permalink
Auto merge of #111516 - compiler-errors:issue-111500, r=jackh726
Browse files Browse the repository at this point in the history
Don't use `can_eq` in `derive(..)` suggestion for missing method

Unsatisfied predicates returned from method probe may reference inference vars from that probe, so drop this extra check I added in #110877 for more accurate derive suggestions...

Fixes #111500
  • Loading branch information
bors committed Jun 3, 2023
2 parents 7d5b746 + c5604cd commit 8177591
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
14 changes: 0 additions & 14 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,20 +2110,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| sym::Hash
| sym::Debug => true,
_ => false,
} && match trait_pred.trait_ref.substs.as_slice() {
// Only suggest deriving if lhs == rhs...
[lhs, rhs] => {
if let Some(lhs) = lhs.as_type()
&& let Some(rhs) = rhs.as_type()
{
self.can_eq(self.param_env, lhs, rhs)
} else {
false
}
},
// Unary ops can always be derived
[_] => true,
_ => false,
};
if can_derive {
let self_name = trait_pred.self_ty().to_string();
Expand Down
7 changes: 5 additions & 2 deletions tests/ui/issues/issue-62375.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ note: an implementation of `PartialEq<fn(()) -> A {A::Value}>` might be missing
|
LL | enum A {
| ^^^^^^ must implement `PartialEq<fn(()) -> A {A::Value}>`
note: the trait `PartialEq` must be implemented
--> $SRC_DIR/core/src/cmp.rs:LL:COL
help: consider annotating `A` with `#[derive(PartialEq)]`
|
LL + #[derive(PartialEq)]
LL | enum A {
|
help: use parentheses to construct this tuple variant
|
LL | a == A::Value(/* () */);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/typeck/derive-sugg-arg-arity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub struct A;

fn main() {
match () {
_ => match A::partial_cmp() {},
//~^ ERROR the function or associated item `partial_cmp` exists for struct `A`, but its trait bounds were not satisfied
}
}
31 changes: 31 additions & 0 deletions tests/ui/typeck/derive-sugg-arg-arity.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error[E0599]: the function or associated item `partial_cmp` exists for struct `A`, but its trait bounds were not satisfied
--> $DIR/derive-sugg-arg-arity.rs:5:23
|
LL | pub struct A;
| ------------
| |
| function or associated item `partial_cmp` not found for this struct
| doesn't satisfy `A: Iterator`
| doesn't satisfy `A: PartialOrd<_>`
...
LL | _ => match A::partial_cmp() {},
| ^^^^^^^^^^^ function or associated item cannot be called on `A` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`A: PartialOrd<_>`
which is required by `&A: PartialOrd<&_>`
`A: PartialOrd<_>`
which is required by `&mut A: PartialOrd<&mut _>`
`A: Iterator`
which is required by `&mut A: Iterator`
note: the trait `Iterator` must be implemented
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
|
LL + #[derive(PartialEq, PartialOrd)]
LL | pub struct A;
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

0 comments on commit 8177591

Please sign in to comment.