diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index b840c3ddd02e..87419332dd56 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -140,7 +140,6 @@ pub mod regex; pub mod returns; pub mod serde_api; pub mod shadow; -pub mod should_assert_eq; pub mod strings; pub mod swap; pub mod temporary_assignment; @@ -322,7 +321,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_early_lint_pass(box double_parens::DoubleParens); reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount); reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold)); - reg.register_late_lint_pass(box should_assert_eq::ShouldAssertEq); reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue); reg.register_early_lint_pass(box literal_digit_grouping::LiteralDigitGrouping); reg.register_late_lint_pass(box use_self::UseSelf); @@ -531,7 +529,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { returns::LET_AND_RETURN, returns::NEEDLESS_RETURN, serde_api::SERDE_API_MISUSE, - should_assert_eq::SHOULD_ASSERT_EQ, strings::STRING_LIT_AS_BYTES, swap::ALMOST_SWAPPED, swap::MANUAL_SWAP, diff --git a/clippy_lints/src/should_assert_eq.rs b/clippy_lints/src/should_assert_eq.rs deleted file mode 100644 index 47e444c8c885..000000000000 --- a/clippy_lints/src/should_assert_eq.rs +++ /dev/null @@ -1,61 +0,0 @@ -use rustc::lint::*; -use rustc::hir::*; -use utils::{implements_trait, is_direct_expn_of, is_expn_of, span_lint}; - -/// **What it does:** Checks for `assert!(x == y)` or `assert!(x != y)` which -/// can be better written -/// using `assert_eq` or `assert_ne` if `x` and `y` implement `Debug` trait. -/// -/// **Why is this bad?** `assert_eq` and `assert_ne` provide better assertion -/// failure reporting. -/// -/// **Known problems:** Hopefully none. -/// -/// **Example:** -/// ```rust -/// let (x, y) = (1, 2); -/// -/// assert!(x == y); // assertion failed: x == y -/// assert_eq!(x, y); // assertion failed: `(left == right)` (left: `1`, right: -/// `2`) -/// ``` -declare_lint! { - pub SHOULD_ASSERT_EQ, - Warn, - "using `assert` macro for asserting equality" -} - -pub struct ShouldAssertEq; - -impl LintPass for ShouldAssertEq { - fn get_lints(&self) -> LintArray { - lint_array![SHOULD_ASSERT_EQ] - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ShouldAssertEq { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { - if_let_chain! {[ - let ExprIf(ref cond, ..) = e.node, - let ExprUnary(UnOp::UnNot, ref cond) = cond.node, - let ExprBinary(ref binop, ref expr1, ref expr2) = cond.node, - is_direct_expn_of(e.span, "assert").is_some(), - let Some(debug_trait) = cx.tcx.lang_items().debug_trait(), - ], { - let debug = is_expn_of(e.span, "debug_assert").map_or("", |_| "debug_"); - let sugg = match binop.node { - BinOp_::BiEq => "assert_eq", - BinOp_::BiNe => "assert_ne", - _ => return, - }; - - let ty1 = cx.tables.expr_ty(expr1); - let ty2 = cx.tables.expr_ty(expr2); - - if implements_trait(cx, ty1, debug_trait, &[]) && - implements_trait(cx, ty2, debug_trait, &[]) { - span_lint(cx, SHOULD_ASSERT_EQ, e.span, &format!("use `{}{}` for better reporting", debug, sugg)); - } - }} - } -} diff --git a/tests/ui/should_assert_eq.rs b/tests/ui/should_assert_eq.rs deleted file mode 100644 index ac5fca8dd0b3..000000000000 --- a/tests/ui/should_assert_eq.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![feature(plugin)] -#![plugin(clippy)] - -#![allow(needless_pass_by_value)] -#![warn(should_assert_eq)] - -#[derive(PartialEq, Eq)] -struct NonDebug(i32); - -#[derive(Debug, PartialEq, Eq)] -struct Debug(i32); - -fn main() { - assert!(1 == 2); - assert!(Debug(1) == Debug(2)); - assert!(NonDebug(1) == NonDebug(1)); // ok - assert!(Debug(1) != Debug(2)); - assert!(NonDebug(1) != NonDebug(2)); // ok - - test_generic(1, 2, 3, 4); - - debug_assert!(4 == 5); - debug_assert!(4 != 6); -} - -fn test_generic(x: T, y: T, z: U, w: U) { - assert!(x == y); - assert!(z == w); // ok - - assert!(x != y); - assert!(z != w); // ok -} diff --git a/tests/ui/should_assert_eq.stderr b/tests/ui/should_assert_eq.stderr deleted file mode 100644 index 57abf8004988..000000000000 --- a/tests/ui/should_assert_eq.stderr +++ /dev/null @@ -1,59 +0,0 @@ -error: use `assert_eq` for better reporting - --> $DIR/should_assert_eq.rs:14:5 - | -14 | assert!(1 == 2); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D should-assert-eq` implied by `-D warnings` - = note: this error originates in a macro outside of the current crate - -error: use `assert_eq` for better reporting - --> $DIR/should_assert_eq.rs:15:5 - | -15 | assert!(Debug(1) == Debug(2)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro outside of the current crate - -error: use `assert_ne` for better reporting - --> $DIR/should_assert_eq.rs:17:5 - | -17 | assert!(Debug(1) != Debug(2)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro outside of the current crate - -error: use `debug_assert_eq` for better reporting - --> $DIR/should_assert_eq.rs:22:5 - | -22 | debug_assert!(4 == 5); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro outside of the current crate - -error: use `debug_assert_ne` for better reporting - --> $DIR/should_assert_eq.rs:23:5 - | -23 | debug_assert!(4 != 6); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro outside of the current crate - -error: use `assert_eq` for better reporting - --> $DIR/should_assert_eq.rs:27:5 - | -27 | assert!(x == y); - | ^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro outside of the current crate - -error: use `assert_ne` for better reporting - --> $DIR/should_assert_eq.rs:30:5 - | -30 | assert!(x != y); - | ^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro outside of the current crate - -error: aborting due to 7 previous errors -