From 6c209d1cc49a26247c7055c3da546dbe243ed81b Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 9 Oct 2015 22:42:46 +0200 Subject: [PATCH] Add notes for missing PartialEq and PartialOrd, closes #28837 --- src/librustc_typeck/check/op.rs | 14 ++++++++++++++ src/test/compile-fail/issue-28837.rs | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/test/compile-fail/issue-28837.rs 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 +}