about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLeSeulArtichaut <leseulartichaut@gmail.com>2019-12-07 19:03:06 +0100
committerLeSeulArtichaut <leseulartichaut@gmail.com>2019-12-12 20:56:14 +0100
commit29e5f8e9bc2d9c6fd70941185aabcb3694fbca90 (patch)
tree93d46396ac52dfc8404022a6a2a85cc5d5c89fa0 /src
parente9469a6aec2f49fa1e2ae670649f293866932253 (diff)
E0369 messages mimics E0277
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/op.rs66
1 files changed, 44 insertions, 22 deletions
diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs
index 321faa4a322..e85bf0797c8 100644
--- a/src/librustc_typeck/check/op.rs
+++ b/src/librustc_typeck/check/op.rs
@@ -334,10 +334,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                             err.emit();
                         }
                         IsAssign::No => {
+                            let (message, missing_trait) = match op.node {
+                                hir::BinOpKind::Add    => {
+                                    (format!("cannot add `{}` to `{}`", rhs_ty, lhs_ty),
+                                    Some("std::ops::Add"))
+                                },
+                                hir::BinOpKind::Sub    => {
+                                    (format!("cannot substract `{}` from `{}`", rhs_ty, lhs_ty),
+                                    Some("std::ops::Sub"))
+                                },
+                                hir::BinOpKind::Mul    => {
+                                    (format!("cannot multiply `{}` to `{}`", rhs_ty, lhs_ty),
+                                    Some("std::ops::Mul"))
+                                },
+                                hir::BinOpKind::Div    => {
+                                    (format!("cannot divide `{}` by `{}`", lhs_ty, rhs_ty),
+                                    Some("std::ops::Div"))
+                                },
+                                hir::BinOpKind::Rem    => {
+                                    (format!("cannot mod `{}` by `{}`", lhs_ty, rhs_ty),
+                                    Some("std::ops::Rem"))
+                                },
+                                hir::BinOpKind::BitAnd => {
+                                    (format!("no implementation for `{} & {}`", lhs_ty, rhs_ty),
+                                    Some("std::ops::BitAnd"))
+                                },
+                                hir::BinOpKind::BitXor => {
+                                    (format!("no implementation for `{} ^ {}`", lhs_ty, rhs_ty),
+                                    Some("std::ops::BitXor"))
+                                },
+                                hir::BinOpKind::BitOr  => {
+                                    (format!("no implementation for `{} | {}`", lhs_ty, rhs_ty),
+                                    Some("std::ops::BitOr"))
+                                },
+                                hir::BinOpKind::Shl    => {
+                                    (format!("no implementation for `{} << {}", lhs_ty, rhs_ty),
+                                    Some("std::ops::Shl"))
+                                },
+                                hir::BinOpKind::Shr    => {
+                                    (format!("no implementation for `{} << {}", lhs_ty, rhs_ty),
+                                    Some("std::ops::Shr"))
+                                },
+                                _ => (format!("binary operation `{}` cannot be applied to type `{}`", op.node.as_str(), lhs_ty), None)
+                            };
                             let mut err = struct_span_err!(self.tcx.sess, op.span, E0369,
-                                "binary operation `{}` cannot be applied to type `{}`",
-                                op.node.as_str(),
-                                lhs_ty);
+                                "{}", message.as_str());
 
                             let mut involves_fn = false;
                             if !lhs_expr.span.eq(&rhs_expr.span) {
@@ -382,25 +423,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                                     }
                                 }
                             }
-                            let missing_trait = match op.node {
-                                hir::BinOpKind::Add    => Some("std::ops::Add"),
-                                hir::BinOpKind::Sub    => Some("std::ops::Sub"),
-                                hir::BinOpKind::Mul    => Some("std::ops::Mul"),
-                                hir::BinOpKind::Div    => Some("std::ops::Div"),
-                                hir::BinOpKind::Rem    => Some("std::ops::Rem"),
-                                hir::BinOpKind::BitAnd => Some("std::ops::BitAnd"),
-                                hir::BinOpKind::BitXor => Some("std::ops::BitXor"),
-                                hir::BinOpKind::BitOr  => Some("std::ops::BitOr"),
-                                hir::BinOpKind::Shl    => Some("std::ops::Shl"),
-                                hir::BinOpKind::Shr    => Some("std::ops::Shr"),
-                                hir::BinOpKind::Eq |
-                                hir::BinOpKind::Ne => Some("std::cmp::PartialEq"),
-                                hir::BinOpKind::Lt |
-                                hir::BinOpKind::Le |
-                                hir::BinOpKind::Gt |
-                                hir::BinOpKind::Ge => Some("std::cmp::PartialOrd"),
-                                _ => None
-                            };
                             if let Some(missing_trait) = missing_trait {
                                 if op.node == hir::BinOpKind::Add &&
                                     self.check_str_addition(