Skip to content

Commit aeabb89

Browse files
committed
Use match ergonomics for booleans lint
1 parent 13c857b commit aeabb89

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

clippy_lints/src/booleans.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct Hir2Qmm<'a, 'tcx: 'a, 'v> {
9696
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
9797
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
9898
for a in a {
99-
if let ExprKind::Binary(binop, ref lhs, ref rhs) = a.node {
99+
if let ExprKind::Binary(binop, lhs, rhs) = &a.node {
100100
if binop.node == op {
101101
v = self.extract(op, &[lhs, rhs], v)?;
102102
continue;
@@ -110,14 +110,14 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
110110
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
111111
// prevent folding of `cfg!` macros and the like
112112
if !in_macro(e.span) {
113-
match e.node {
114-
ExprKind::Unary(UnNot, ref inner) => return Ok(Bool::Not(box self.run(inner)?)),
115-
ExprKind::Binary(binop, ref lhs, ref rhs) => match binop.node {
113+
match &e.node {
114+
ExprKind::Unary(UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
115+
ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
116116
BinOpKind::Or => return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)),
117117
BinOpKind::And => return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)),
118118
_ => (),
119119
},
120-
ExprKind::Lit(ref lit) => match lit.node {
120+
ExprKind::Lit(lit) => match lit.node {
121121
LitKind::Bool(true) => return Ok(Bool::True),
122122
LitKind::Bool(false) => return Ok(Bool::False),
123123
_ => (),
@@ -130,8 +130,8 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
130130
#[allow(clippy::cast_possible_truncation)]
131131
return Ok(Bool::Term(n as u8));
132132
}
133-
let negated = match e.node {
134-
ExprKind::Binary(binop, ref lhs, ref rhs) => {
133+
let negated = match &e.node {
134+
ExprKind::Binary(binop, lhs, rhs) => {
135135
if !implements_ord(self.cx, lhs) {
136136
continue;
137137
}
@@ -184,8 +184,8 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
184184
}
185185

186186
fn simplify_not(&self, expr: &Expr) -> Option<String> {
187-
match expr.node {
188-
ExprKind::Binary(binop, ref lhs, ref rhs) => {
187+
match &expr.node {
188+
ExprKind::Binary(binop, lhs, rhs) => {
189189
if !implements_ord(self.cx, lhs) {
190190
return None;
191191
}
@@ -201,7 +201,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
201201
}
202202
.and_then(|op| Some(format!("{}{}{}", self.snip(lhs)?, op, self.snip(rhs)?)))
203203
},
204-
ExprKind::MethodCall(ref path, _, ref args) if args.len() == 1 => {
204+
ExprKind::MethodCall(path, _, args) if args.len() == 1 => {
205205
let type_of_receiver = self.cx.tables.expr_ty(&args[0]);
206206
if !match_type(self.cx, type_of_receiver, &paths::OPTION)
207207
&& !match_type(self.cx, type_of_receiver, &paths::RESULT)
@@ -221,14 +221,14 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
221221

222222
fn recurse(&mut self, suggestion: &Bool) -> Option<()> {
223223
use quine_mc_cluskey::Bool::*;
224-
match *suggestion {
224+
match suggestion {
225225
True => {
226226
self.output.push_str("true");
227227
},
228228
False => {
229229
self.output.push_str("false");
230230
},
231-
Not(ref inner) => match **inner {
231+
Not(inner) => match **inner {
232232
And(_) | Or(_) => {
233233
self.output.push('!');
234234
self.output.push('(');
@@ -251,7 +251,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
251251
self.recurse(inner)?;
252252
},
253253
},
254-
And(ref v) => {
254+
And(v) => {
255255
for (index, inner) in v.iter().enumerate() {
256256
if index > 0 {
257257
self.output.push_str(" && ");
@@ -265,15 +265,15 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
265265
}
266266
}
267267
},
268-
Or(ref v) => {
268+
Or(v) => {
269269
for (index, inner) in v.iter().enumerate() {
270270
if index > 0 {
271271
self.output.push_str(" || ");
272272
}
273273
self.recurse(inner);
274274
}
275275
},
276-
Term(n) => {
276+
&Term(n) => {
277277
let snip = self.snip(self.terminals[n as usize])?;
278278
self.output.push_str(&snip);
279279
},
@@ -325,22 +325,22 @@ struct Stats {
325325

326326
fn terminal_stats(b: &Bool) -> Stats {
327327
fn recurse(b: &Bool, stats: &mut Stats) {
328-
match *b {
328+
match b {
329329
True | False => stats.ops += 1,
330-
Not(ref inner) => {
330+
Not(inner) => {
331331
match **inner {
332332
And(_) | Or(_) => stats.ops += 1, // brackets are also operations
333333
_ => stats.negations += 1,
334334
}
335335
recurse(inner, stats);
336336
},
337-
And(ref v) | Or(ref v) => {
337+
And(v) | Or(v) => {
338338
stats.ops += v.len() - 1;
339339
for inner in v {
340340
recurse(inner, stats);
341341
}
342342
},
343-
Term(n) => stats.terminals[n as usize] += 1,
343+
&Term(n) => stats.terminals[n as usize] += 1,
344344
}
345345
}
346346
use quine_mc_cluskey::Bool::*;
@@ -461,11 +461,11 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
461461
if in_macro(e.span) {
462462
return;
463463
}
464-
match e.node {
464+
match &e.node {
465465
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
466466
self.bool_expr(e)
467467
},
468-
ExprKind::Unary(UnNot, ref inner) => {
468+
ExprKind::Unary(UnNot, inner) => {
469469
if self.cx.tables.node_types()[inner.hir_id].is_bool() {
470470
self.bool_expr(e);
471471
} else {

0 commit comments

Comments
 (0)