]> git.lizzy.rs Git - rust.git/commitdiff
Deprecate should_assert_eq lint
authorcgm616 <cgm616@me.com>
Fri, 20 Oct 2017 04:42:04 +0000 (23:42 -0500)
committercgm616 <cgm616@me.com>
Fri, 20 Oct 2017 04:42:04 +0000 (23:42 -0500)
This should close #2090.

README.md
clippy_lints/src/deprecated_lints.rs
clippy_lints/src/lib.rs
clippy_lints/src/should_assert_eq.rs [deleted file]
tests/ui/should_assert_eq.rs [deleted file]
tests/ui/should_assert_eq.stderr [deleted file]

index 26e7f12dc83d1d4d4439c5bef719ece7417fb041..cd8e8a409e09a95eee1e954788c5c3896564bf84 100644 (file)
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
 
 A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
 
-[There are 209 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
+[There are 208 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
 
 More to come, please [file an issue](https://github.com/rust-lang-nursery/rust-clippy/issues) if you have ideas!
 
index 0c40823cd06fd62b11718106c96b08971bfb4f22..e51d7cc6d3838f7a9db13945695f62ec47f6eeb4 100644 (file)
@@ -4,6 +4,14 @@ macro_rules! declare_deprecated_lint {
     }
 }
 
+/// **What it does:** Nothing. This lint has been deprecated.
+///
+/// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend 
+/// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011.
+declare_deprecated_lint! {
+    pub SHOULD_ASSERT_EQ,
+    "`assert!()` will be more flexible with RFC 2011"
+}
 
 /// **What it does:** Nothing. This lint has been deprecated.
 ///
index 355b03b2b6a7e1dc6ad63997d5c5afe19628ddac..735df8fc0901676aeb4221b8ebfc6a37501528ea 100644 (file)
@@ -144,7 +144,6 @@ macro_rules! declare_restriction_lint {
 pub mod returns;
 pub mod serde_api;
 pub mod shadow;
-pub mod should_assert_eq;
 pub mod strings;
 pub mod explicit_write;
 pub mod swap;
@@ -200,6 +199,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
     };
 
     let mut store = reg.sess.lint_store.borrow_mut();
+    store.register_removed(
+        "should_assert_eq",
+        "`assert!()` will be more flexible with RFC 2011"
+    );
     store.register_removed(
         "extend_from_slice",
         "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
@@ -327,7 +330,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 explicit_write::Pass);
     reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue);
     reg.register_early_lint_pass(box literal_digit_grouping::LiteralDigitGrouping);
@@ -542,7 +544,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,
         explicit_write::EXPLICIT_WRITE,
         swap::ALMOST_SWAPPED,
diff --git a/clippy_lints/src/should_assert_eq.rs b/clippy_lints/src/should_assert_eq.rs
deleted file mode 100644 (file)
index 47e444c..0000000
+++ /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 (file)
index 5814e99..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-#![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<T: std::fmt::Debug + Eq, U: Eq>(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 (file)
index 5b393e1..0000000
+++ /dev/null
@@ -1,57 +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
-