This should close #2090.
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!
}
}
+/// **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.
///
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;
};
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",
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);
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,
+++ /dev/null
-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));
- }
- }}
- }
-}
+++ /dev/null
-
-
-
-#![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
-}
+++ /dev/null
-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
-