about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-11-19 19:47:25 +0100
committerMara Bos <m-ou.se@m-ou.se>2020-11-19 19:47:25 +0100
commita125ef2e8ec27e8fedc119ddfdef638d09a69ba2 (patch)
treece4d1a05705c895859a4f9e76ab8e4f440284a20
parent454eaec1dc0875614a59ce6b074e91eccb5ab96a (diff)
downloadrust-a125ef2e8ec27e8fedc119ddfdef638d09a69ba2.tar.gz
rust-a125ef2e8ec27e8fedc119ddfdef638d09a69ba2.zip
Clippy: Match on assert!() expansions without an inner block.
-rw-r--r--src/tools/clippy/clippy_lints/src/assertions_on_constants.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
index a2ccb0369c4..a52f0997d43 100644
--- a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
+++ b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
@@ -129,8 +129,11 @@ fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>)
         if let ExprKind::Block(ref block, _) = arms[0].body.kind;
         if block.stmts.is_empty();
         if let Some(block_expr) = &block.expr;
-        if let ExprKind::Block(ref inner_block, _) = block_expr.kind;
-        if let Some(begin_panic_call) = &inner_block.expr;
+        // inner block is optional. unwarp it if it exists, or use the expression as is otherwise.
+        if let Some(begin_panic_call) = match block_expr.kind {
+            ExprKind::Block(ref inner_block, _) => &inner_block.expr,
+            _ => &block.expr,
+        };
         // function call
         if let Some(args) = match_panic_call(cx, begin_panic_call);
         if args.len() == 1;