about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/op.rs14
-rw-r--r--src/test/compile-fail/issue-28837.rs20
2 files changed, 34 insertions, 0 deletions
diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs
index 7be61327f81..ab145db8242 100644
--- a/src/librustc_typeck/check/op.rs
+++ b/src/librustc_typeck/check/op.rs
@@ -191,6 +191,20 @@ fn check_overloaded_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                               "binary operation `{}` cannot be applied to type `{}`",
                               hir_util::binop_to_string(op.node),
                               lhs_ty);
+                    match op.node {
+                        hir::BiEq =>
+                            span_note!(fcx.tcx().sess, lhs_expr.span,
+                                       "an implementation of `std::cmp::PartialEq` might be \
+                                        missing for `{}` or one of its type paramters",
+                                        lhs_ty),
+                        hir::BiLt | hir::BiLe | hir::BiGt | hir::BiGe =>
+                            span_note!(fcx.tcx().sess, lhs_expr.span,
+                                       "an implementation of `std::cmp::PartialOrd` might be \
+                                        missing for `{}` or one of its type paramters",
+                                        lhs_ty),
+                        _ => ()
+
+                    };
                 }
             }
             fcx.tcx().types.err
diff --git a/src/test/compile-fail/issue-28837.rs b/src/test/compile-fail/issue-28837.rs
new file mode 100644
index 00000000000..9f2a565e732
--- /dev/null
+++ b/src/test/compile-fail/issue-28837.rs
@@ -0,0 +1,20 @@
+struct A;
+
+fn main() {
+    let a = A;
+
+    if a == a {} //~ ERROR binary operation `==` cannot be applied to type `A`
+        //^~ NOTE an implementation of `std::cmp::PartialEq` might be missing for `A` or one of
+
+    if a < a {} //~ ERROR binary operation `<` cannot be applied to type `A`
+        //^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
+
+    if a <= a {} //~ ERROR binary operation `<=` cannot be applied to type `A`
+        //^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
+
+    if a > a {} //~ ERROR binary operation `>` cannot be applied to type `A`
+        //^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
+
+    if a >= a {} //~ ERROR binary operation `>=` cannot be applied to type `A`
+        //^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
+}