|
1 | 1 | use clippy_utils::consts::{constant, Constant}; |
2 | 2 | use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; |
3 | 3 | use clippy_utils::sugg::Sugg; |
4 | | -use if_chain::if_chain; |
5 | 4 | use rustc_ast::ast::LitKind; |
6 | 5 | use rustc_errors::Applicability; |
7 | 6 | use rustc_hir::{BinOpKind, Expr, ExprKind}; |
@@ -130,32 +129,33 @@ impl<'tcx> LateLintPass<'tcx> for BitMask { |
130 | 129 | } |
131 | 130 | } |
132 | 131 | } |
133 | | - if_chain! { |
134 | | - if let ExprKind::Binary(op, left, right) = &e.kind; |
135 | | - if BinOpKind::Eq == op.node; |
136 | | - if let ExprKind::Binary(op1, left1, right1) = &left.kind; |
137 | | - if BinOpKind::BitAnd == op1.node; |
138 | | - if let ExprKind::Lit(lit) = &right1.kind; |
139 | | - if let LitKind::Int(n, _) = lit.node; |
140 | | - if let ExprKind::Lit(lit1) = &right.kind; |
141 | | - if let LitKind::Int(0, _) = lit1.node; |
142 | | - if n.leading_zeros() == n.count_zeros(); |
143 | | - if n > u128::from(self.verbose_bit_mask_threshold); |
144 | | - then { |
145 | | - span_lint_and_then(cx, |
146 | | - VERBOSE_BIT_MASK, |
147 | | - e.span, |
148 | | - "bit mask could be simplified with a call to `trailing_zeros`", |
149 | | - |diag| { |
| 132 | + |
| 133 | + if let ExprKind::Binary(op, left, right) = &e.kind |
| 134 | + && BinOpKind::Eq == op.node |
| 135 | + && let ExprKind::Binary(op1, left1, right1) = &left.kind |
| 136 | + && BinOpKind::BitAnd == op1.node |
| 137 | + && let ExprKind::Lit(lit) = &right1.kind |
| 138 | + && let LitKind::Int(n, _) = lit.node |
| 139 | + && let ExprKind::Lit(lit1) = &right.kind |
| 140 | + && let LitKind::Int(0, _) = lit1.node |
| 141 | + && n.leading_zeros() == n.count_zeros() |
| 142 | + && n > u128::from(self.verbose_bit_mask_threshold) |
| 143 | + { |
| 144 | + span_lint_and_then( |
| 145 | + cx, |
| 146 | + VERBOSE_BIT_MASK, |
| 147 | + e.span, |
| 148 | + "bit mask could be simplified with a call to `trailing_zeros`", |
| 149 | + |diag| { |
150 | 150 | let sugg = Sugg::hir(cx, left1, "...").maybe_par(); |
151 | 151 | diag.span_suggestion( |
152 | 152 | e.span, |
153 | 153 | "try", |
154 | 154 | format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()), |
155 | 155 | Applicability::MaybeIncorrect, |
156 | 156 | ); |
157 | | - }); |
158 | | - } |
| 157 | + }, |
| 158 | + ); |
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
|
0 commit comments