diff options
| author | bors <bors@rust-lang.org> | 2015-10-17 13:24:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-10-17 13:24:01 +0000 |
| commit | c7a58b534e61f65e9f3724ec921ec7a3396efdcc (patch) | |
| tree | b489d3b69ba19af74ea048edce3840e00c1f44eb | |
| parent | ad5a43a4834990ac2c96781160f7a3186b185350 (diff) | |
| parent | b21ae1ab1ad582964c12136f645f80865a4c8d54 (diff) | |
| download | rust-c7a58b534e61f65e9f3724ec921ec7a3396efdcc.tar.gz rust-c7a58b534e61f65e9f3724ec921ec7a3396efdcc.zip | |
Auto merge of #28933 - fhahn:issue-28837-partialeq-note, r=alexcrichton
this PR adds notes for missing `PartialEq` and `PartialOrd`. I've added a test case but it seems like `NOTE` is ignored by the test runner. #28837
| -rw-r--r-- | src/librustc_typeck/check/op.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-28837.rs | 60 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 7be61327f81..0c65f68f02e 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -191,6 +191,27 @@ 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); + 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 => + Some("std::cmp::PartialOrd"), + _ => None + }; + + if let Some(missing_trait) = missing_trait { + span_note!(fcx.tcx().sess, lhs_expr.span, + "an implementation of `{}` might be missing for `{}`", + missing_trait, 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 00000000000..c7cf63bf2c4 --- /dev/null +++ b/src/test/compile-fail/issue-28837.rs @@ -0,0 +1,60 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct A; + +fn main() { + let a = A; + + a + a; //~ ERROR binary operation `+` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::Add` might be missing for `A` + + a - a; //~ ERROR binary operation `-` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::Sub` might be missing for `A` + + a * a; //~ ERROR binary operation `*` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::Mul` might be missing for `A` + + a / a; //~ ERROR binary operation `/` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::Div` might be missing for `A` + + a % a; //~ ERROR binary operation `%` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::Rem` might be missing for `A` + + a & a; //~ ERROR binary operation `&` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::BitAnd` might be missing for `A` + + a | a; //~ ERROR binary operation `|` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::BitOr` might be missing for `A` + + a << a; //~ ERROR binary operation `<<` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::Shl` might be missing for `A` + + a >> a; //~ ERROR binary operation `>>` cannot be applied to type `A` + //~^ NOTE an implementation of `std::ops::Shr` might be missing for `A` + + a == a; //~ ERROR binary operation `==` cannot be applied to type `A` + //~^ NOTE an implementation of `std::cmp::PartialEq` might be missing for `A` + + a != a; //~ ERROR binary operation `!=` cannot be applied to type `A` + //~^ NOTE an implementation of `std::cmp::PartialEq` might be missing for `A` + + a < a; //~ ERROR binary operation `<` cannot be applied to type `A` + //~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` + + a <= a; //~ ERROR binary operation `<=` cannot be applied to type `A` + //~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` + + a > a; //~ ERROR binary operation `>` cannot be applied to type `A` + //~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` + + a >= a; //~ ERROR binary operation `>=` cannot be applied to type `A` + //~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` +} |
