Skip to content

Commit 6c209d1

Browse files
committed
Add notes for missing PartialEq and PartialOrd, closes #28837
1 parent 130851e commit 6c209d1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/librustc_typeck/check/op.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ fn check_overloaded_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
191191
"binary operation `{}` cannot be applied to type `{}`",
192192
hir_util::binop_to_string(op.node),
193193
lhs_ty);
194+
match op.node {
195+
hir::BiEq =>
196+
span_note!(fcx.tcx().sess, lhs_expr.span,
197+
"an implementation of `std::cmp::PartialEq` might be \
198+
missing for `{}` or one of its type paramters",
199+
lhs_ty),
200+
hir::BiLt | hir::BiLe | hir::BiGt | hir::BiGe =>
201+
span_note!(fcx.tcx().sess, lhs_expr.span,
202+
"an implementation of `std::cmp::PartialOrd` might be \
203+
missing for `{}` or one of its type paramters",
204+
lhs_ty),
205+
_ => ()
206+
207+
};
194208
}
195209
}
196210
fcx.tcx().types.err

src/test/compile-fail/issue-28837.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct A;
2+
3+
fn main() {
4+
let a = A;
5+
6+
if a == a {} //~ ERROR binary operation `==` cannot be applied to type `A`
7+
//^~ NOTE an implementation of `std::cmp::PartialEq` might be missing for `A` or one of
8+
9+
if a < a {} //~ ERROR binary operation `<` cannot be applied to type `A`
10+
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
11+
12+
if a <= a {} //~ ERROR binary operation `<=` cannot be applied to type `A`
13+
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
14+
15+
if a > a {} //~ ERROR binary operation `>` cannot be applied to type `A`
16+
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
17+
18+
if a >= a {} //~ ERROR binary operation `>=` cannot be applied to type `A`
19+
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
20+
}

0 commit comments

Comments
 (0)