Add notes for missing PartialEq and PartialOrd, closes #28837
This commit is contained in:
parent
130851e030
commit
6c209d1cc4
2 changed files with 34 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
20
src/test/compile-fail/issue-28837.rs
Normal file
20
src/test/compile-fail/issue-28837.rs
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue