]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/assertions_on_constants.rs
Auto merge of #6278 - ThibsG:DerefAddrOf, r=llogiq
[rust.git] / clippy_lints / src / assertions_on_constants.rs
index bd9a2a7c40c4cf10876c05732d9d2b293c92aec3..982d5ecf8d02f03aae9cc3fd52b19be5685fb266 100644 (file)
     /// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
     ///
     /// **Why is this bad?** Will be optimized out by the compiler or should probably be replaced by a
-    /// panic!() or unreachable!()
+    /// `panic!()` or `unreachable!()`
     ///
     /// **Known problems:** None
     ///
     /// **Example:**
     /// ```rust,ignore
     /// assert!(false)
-    /// // or
     /// assert!(true)
-    /// // or
     /// const B: bool = false;
     /// assert!(B)
     /// ```
@@ -31,8 +29,8 @@
 
 declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
-    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
+impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
+    fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
         let lint_true = |is_debug: bool| {
             span_lint_and_help(
                 cx,
@@ -43,6 +41,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
                 } else {
                     "`assert!(true)` will be optimized out by the compiler"
                 },
+                None,
                 "remove it",
             );
         };
@@ -52,6 +51,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
                 ASSERTIONS_ON_CONSTANTS,
                 e.span,
                 "`assert!(false)` should probably be replaced",
+                None,
                 "use `panic!()` or `unreachable!()`",
             );
         };
@@ -61,6 +61,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
                 ASSERTIONS_ON_CONSTANTS,
                 e.span,
                 &format!("`assert!(false, {})` should probably be replaced", panic_message),
+                None,
                 &format!("use `panic!({})` or `unreachable!({})`", panic_message, panic_message),
             )
         };
@@ -71,7 +72,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
             }
             if_chain! {
                 if let ExprKind::Unary(_, ref lit) = e.kind;
-                if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit);
+                if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), lit);
                 if is_true;
                 then {
                     lint_true(true);
@@ -113,14 +114,14 @@ enum AssertKind {
 /// ```
 ///
 /// where `message` is any expression and `c` is a constant bool.
-fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
+fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
     if_chain! {
         if let ExprKind::Match(ref expr, ref arms, _) = expr.kind;
         // matches { let _t = expr; _t }
         if let ExprKind::DropTemps(ref expr) = expr.kind;
         if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind;
         // bind the first argument of the `assert!` macro
-        if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, expr);
+        if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
         // arm 1 pattern
         if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind;
         if let ExprKind::Lit(ref lit) = lit_expr.kind;