Add notes for missing PartialEq and PartialOrd, closes #28837

This commit is contained in:
Florian Hahn 2015-10-09 22:42:46 +02:00
parent 130851e030
commit 6c209d1cc4
2 changed files with 34 additions and 0 deletions

View file

@ -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

View file

@ -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
}