Skip to content
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

Don't use can_eq in derive(..) suggestion for missing method #111516

Merged
merged 1 commit into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2090,20 +2090,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`.