|
1 | 1 | use crate::consts::{constant, Constant};
|
2 | 2 | use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, snippet_opt, span_lint_and_help};
|
3 | 3 | use if_chain::if_chain;
|
4 |
| -use rustc_ast::ast::LitKind; |
5 |
| -use rustc_hir::{Expr, ExprKind, PatKind, UnOp}; |
| 4 | +use rustc_hir::{Expr, ExprKind, UnOp}; |
6 | 5 | use rustc_lint::{LateContext, LateLintPass};
|
7 | 6 | use rustc_session::{declare_lint_pass, declare_tool_lint};
|
8 | 7 |
|
@@ -102,31 +101,22 @@ enum AssertKind {
|
102 | 101 | /// Check if the expression matches
|
103 | 102 | ///
|
104 | 103 | /// ```rust,ignore
|
105 |
| -/// match { let _t = !c; _t } { |
106 |
| -/// true => { |
107 |
| -/// { |
108 |
| -/// ::std::rt::begin_panic(message, _) |
109 |
| -/// } |
110 |
| -/// } |
111 |
| -/// _ => { } |
112 |
| -/// }; |
| 104 | +/// if !c { |
| 105 | +/// { |
| 106 | +/// ::std::rt::begin_panic(message, _) |
| 107 | +/// } |
| 108 | +/// } |
113 | 109 | /// ```
|
114 | 110 | ///
|
115 | 111 | /// where `message` is any expression and `c` is a constant bool.
|
116 | 112 | fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
|
117 | 113 | if_chain! {
|
118 |
| - if let ExprKind::Match(ref expr, ref arms, _) = expr.kind; |
119 |
| - // matches { let _t = expr; _t } |
120 |
| - if let ExprKind::DropTemps(ref expr) = expr.kind; |
121 |
| - if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind; |
| 114 | + if let ExprKind::If(ref cond, ref then, _) = expr.kind; |
| 115 | + if let ExprKind::Unary(UnOp::UnNot, ref expr) = cond.kind; |
122 | 116 | // bind the first argument of the `assert!` macro
|
123 | 117 | if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
|
124 |
| - // arm 1 pattern |
125 |
| - if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind; |
126 |
| - if let ExprKind::Lit(ref lit) = lit_expr.kind; |
127 |
| - if let LitKind::Bool(true) = lit.node; |
128 |
| - // arm 1 block |
129 |
| - if let ExprKind::Block(ref block, _) = arms[0].body.kind; |
| 118 | + // block |
| 119 | + if let ExprKind::Block(ref block, _) = then.kind; |
130 | 120 | if block.stmts.is_empty();
|
131 | 121 | if let Some(block_expr) = &block.expr;
|
132 | 122 | // inner block is optional. unwrap it if it exists, or use the expression as is otherwise.
|
|
0 commit comments