Skip to content

Commit c5604cd

Browse files
Don't use can_eq in derive suggestion for missing method
1 parent 2a8221d commit c5604cd

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

-14
Original file line numberDiff line numberDiff line change
@@ -2090,20 +2090,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20902090
| sym::Hash
20912091
| sym::Debug => true,
20922092
_ => false,
2093-
} && match trait_pred.trait_ref.substs.as_slice() {
2094-
// Only suggest deriving if lhs == rhs...
2095-
[lhs, rhs] => {
2096-
if let Some(lhs) = lhs.as_type()
2097-
&& let Some(rhs) = rhs.as_type()
2098-
{
2099-
self.can_eq(self.param_env, lhs, rhs)
2100-
} else {
2101-
false
2102-
}
2103-
},
2104-
// Unary ops can always be derived
2105-
[_] => true,
2106-
_ => false,
21072093
};
21082094
if can_derive {
21092095
let self_name = trait_pred.self_ty().to_string();

tests/ui/issues/issue-62375.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ note: an implementation of `PartialEq<fn(()) -> A {A::Value}>` might be missing
1111
|
1212
LL | enum A {
1313
| ^^^^^^ must implement `PartialEq<fn(()) -> A {A::Value}>`
14-
note: the trait `PartialEq` must be implemented
15-
--> $SRC_DIR/core/src/cmp.rs:LL:COL
14+
help: consider annotating `A` with `#[derive(PartialEq)]`
15+
|
16+
LL + #[derive(PartialEq)]
17+
LL | enum A {
18+
|
1619
help: use parentheses to construct this tuple variant
1720
|
1821
LL | a == A::Value(/* () */);
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub struct A;
2+
3+
fn main() {
4+
match () {
5+
_ => match A::partial_cmp() {},
6+
//~^ ERROR the function or associated item `partial_cmp` exists for struct `A`, but its trait bounds were not satisfied
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0599]: the function or associated item `partial_cmp` exists for struct `A`, but its trait bounds were not satisfied
2+
--> $DIR/derive-sugg-arg-arity.rs:5:23
3+
|
4+
LL | pub struct A;
5+
| ------------
6+
| |
7+
| function or associated item `partial_cmp` not found for this struct
8+
| doesn't satisfy `A: Iterator`
9+
| doesn't satisfy `A: PartialOrd<_>`
10+
...
11+
LL | _ => match A::partial_cmp() {},
12+
| ^^^^^^^^^^^ function or associated item cannot be called on `A` due to unsatisfied trait bounds
13+
|
14+
= note: the following trait bounds were not satisfied:
15+
`A: PartialOrd<_>`
16+
which is required by `&A: PartialOrd<&_>`
17+
`A: PartialOrd<_>`
18+
which is required by `&mut A: PartialOrd<&mut _>`
19+
`A: Iterator`
20+
which is required by `&mut A: Iterator`
21+
note: the trait `Iterator` must be implemented
22+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
23+
help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
24+
|
25+
LL + #[derive(PartialEq, PartialOrd)]
26+
LL | pub struct A;
27+
|
28+
29+
error: aborting due to previous error
30+
31+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)