diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 7be61327f81f..ab145db8242d 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 000000000000..9f2a565e7320 --- /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 +}