]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/op.rs
Auto merge of #30641 - tsion:match-range, r=eddyb
[rust.git] / src / librustc_typeck / check / op.rs
index ab145db8242dccd2c960e3292c2274b714214f88..c5a36fb4ada256d96cfad9da7ef91282329d320c 100644 (file)
@@ -187,24 +187,32 @@ fn check_overloaded_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                               hir_util::binop_to_string(op.node),
                               lhs_ty);
                 } else {
-                    span_err!(fcx.tcx().sess, lhs_expr.span, E0369,
-                              "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),
+                    let mut err = struct_span_err!(fcx.tcx().sess, lhs_expr.span, E0369,
+                        "binary operation `{}` cannot be applied to type `{}`",
+                        hir_util::binop_to_string(op.node),
+                        lhs_ty);
+                    let missing_trait = match op.node {
+                        hir::BiAdd    => Some("std::ops::Add"),
+                        hir::BiSub    => Some("std::ops::Sub"),
+                        hir::BiMul    => Some("std::ops::Mul"),
+                        hir::BiDiv    => Some("std::ops::Div"),
+                        hir::BiRem    => Some("std::ops::Rem"),
+                        hir::BiBitAnd => Some("std::ops::BitAnd"),
+                        hir::BiBitOr  => Some("std::ops::BitOr"),
+                        hir::BiShl    => Some("std::ops::Shl"),
+                        hir::BiShr    => Some("std::ops::Shr"),
+                        hir::BiEq | hir::BiNe => Some("std::cmp::PartialEq"),
                         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),
-                        _ => ()
-
+                            Some("std::cmp::PartialOrd"),
+                        _             => None
                     };
+
+                    if let Some(missing_trait) = missing_trait {
+                        span_note!(&mut err, lhs_expr.span,
+                                   "an implementation of `{}` might be missing for `{}`",
+                                    missing_trait, lhs_ty);
+                    }
+                    err.emit();
                 }
             }
             fcx.tcx().types.err