Skip to content

Commit aee138a

Browse files
committed
Auto merge of #3597 - xfix:match-ergonomics, r=phansch
Match ergonomics (lints from A to B)
2 parents ad2a4ef + aeabb89 commit aee138a

File tree

7 files changed

+56
-56
lines changed

7 files changed

+56
-56
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl LintPass for Pass {
7373

7474
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
7575
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
76-
if let ExprKind::Lit(ref lit) = e.node {
76+
if let ExprKind::Lit(lit) = &e.node {
7777
check_lit(cx, lit, e);
7878
}
7979
}

clippy_lints/src/arithmetic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
7373
return;
7474
}
7575
}
76-
match expr.node {
77-
hir::ExprKind::Binary(ref op, ref l, ref r) => {
76+
match &expr.node {
77+
hir::ExprKind::Binary(op, l, r) => {
7878
match op.node {
7979
hir::BinOpKind::And
8080
| hir::BinOpKind::Or
@@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
100100
self.expr_span = Some(expr.span);
101101
}
102102
},
103-
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => {
103+
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
104104
let ty = cx.tables.expr_ty(arg);
105105
if ty.is_integral() {
106106
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");

clippy_lints/src/assign_ops.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ impl LintPass for AssignOps {
7070

7171
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7272
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
73-
match expr.node {
74-
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
75-
if let hir::ExprKind::Binary(binop, ref l, ref r) = rhs.node {
73+
match &expr.node {
74+
hir::ExprKind::AssignOp(op, lhs, rhs) => {
75+
if let hir::ExprKind::Binary(binop, l, r) = &rhs.node {
7676
if op.node == binop.node {
7777
let lint = |assignee: &hir::Expr, rhs_other: &hir::Expr| {
7878
span_lint_and_then(
@@ -122,8 +122,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
122122
}
123123
}
124124
},
125-
hir::ExprKind::Assign(ref assignee, ref e) => {
126-
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
125+
hir::ExprKind::Assign(assignee, e) => {
126+
if let hir::ExprKind::Binary(op, l, r) = &e.node {
127127
#[allow(clippy::cyclomatic_complexity)]
128128
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
129129
let ty = cx.tables.expr_ty(assignee);
@@ -150,8 +150,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
150150
if_chain! {
151151
if parent_impl != ast::CRATE_NODE_ID;
152152
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
153-
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) =
154-
item.node;
153+
if let hir::ItemKind::Impl(_, _, _, _, Some(trait_ref), _, _) =
154+
&item.node;
155155
if trait_ref.path.def.def_id() == trait_id;
156156
then { return; }
157157
}

clippy_lints/src/attrs.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl LintPass for AttrPass {
212212

213213
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
214214
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
215-
if let Some(ref items) = attr.meta_item_list() {
215+
if let Some(items) = &attr.meta_item_list() {
216216
match &*attr.name().as_str() {
217217
"allow" | "warn" | "deny" | "forbid" => {
218218
check_clippy_lint_names(cx, items);
@@ -224,8 +224,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
224224
}
225225
for item in items {
226226
if_chain! {
227-
if let NestedMetaItemKind::MetaItem(ref mi) = item.node;
228-
if let MetaItemKind::NameValue(ref lit) = mi.node;
227+
if let NestedMetaItemKind::MetaItem(mi) = &item.node;
228+
if let MetaItemKind::NameValue(lit) = &mi.node;
229229
if mi.name() == "since";
230230
then {
231231
check_semver(cx, item.span, lit);
@@ -244,7 +244,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
244244
let skip_unused_imports = item.attrs.iter().any(|attr| attr.name() == "macro_use");
245245

246246
for attr in &item.attrs {
247-
if let Some(ref lint_list) = attr.meta_item_list() {
247+
if let Some(lint_list) = &attr.meta_item_list() {
248248
match &*attr.name().as_str() {
249249
"allow" | "warn" | "deny" | "forbid" => {
250250
// whitelist `unused_imports` and `deprecated` for `use` items
@@ -381,22 +381,22 @@ fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
381381

382382
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
383383
if let Some(stmt) = block.stmts.first() {
384-
match stmt.node {
384+
match &stmt.node {
385385
StmtKind::Decl(_, _) => true,
386-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => is_relevant_expr(tcx, tables, expr),
386+
StmtKind::Expr(expr, _) | StmtKind::Semi(expr, _) => is_relevant_expr(tcx, tables, expr),
387387
}
388388
} else {
389389
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
390390
}
391391
}
392392

393393
fn is_relevant_expr(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
394-
match expr.node {
395-
ExprKind::Block(ref block, _) => is_relevant_block(tcx, tables, block),
396-
ExprKind::Ret(Some(ref e)) => is_relevant_expr(tcx, tables, e),
394+
match &expr.node {
395+
ExprKind::Block(block, _) => is_relevant_block(tcx, tables, block),
396+
ExprKind::Ret(Some(e)) => is_relevant_expr(tcx, tables, e),
397397
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
398-
ExprKind::Call(ref path_expr, _) => {
399-
if let ExprKind::Path(ref qpath) = path_expr.node {
398+
ExprKind::Call(path_expr, _) => {
399+
if let ExprKind::Path(qpath) = &path_expr.node {
400400
if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) {
401401
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
402402
} else {
@@ -443,7 +443,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
443443
}
444444
}
445445

446-
if let Some(ref values) = attr.meta_item_list() {
446+
if let Some(values) = attr.meta_item_list() {
447447
if values.len() != 1 || attr.name() != "inline" {
448448
continue;
449449
}
@@ -463,7 +463,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
463463
}
464464

465465
fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
466-
if let LitKind::Str(ref is, _) = lit.node {
466+
if let LitKind::Str(is, _) = lit.node {
467467
if Version::parse(&is.as_str()).is_ok() {
468468
return;
469469
}
@@ -477,7 +477,7 @@ fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
477477
}
478478

479479
fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
480-
if let NestedMetaItemKind::MetaItem(ref mi) = nmi.node {
480+
if let NestedMetaItemKind::MetaItem(mi) = &nmi.node {
481481
mi.is_word() && mi.name() == expected
482482
} else {
483483
false
@@ -512,7 +512,7 @@ impl EarlyLintPass for CfgAttrPass {
512512
if_chain! {
513513
// check cfg_attr
514514
if attr.name() == "cfg_attr";
515-
if let Some(ref items) = attr.meta_item_list();
515+
if let Some(items) = attr.meta_item_list();
516516
if items.len() == 2;
517517
// check for `rustfmt`
518518
if let Some(feature_item) = items[0].meta_item();

clippy_lints/src/bit_mask.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl LintPass for BitMask {
121121

122122
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
123123
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
124-
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
124+
if let ExprKind::Binary(cmp, left, right) = &e.node {
125125
if cmp.node.is_comparison() {
126126
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
127127
check_compare(cx, left, cmp.node, cmp_opt, e.span)
@@ -131,13 +131,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
131131
}
132132
}
133133
if_chain! {
134-
if let ExprKind::Binary(ref op, ref left, ref right) = e.node;
134+
if let ExprKind::Binary(op, left, right) = &e.node;
135135
if BinOpKind::Eq == op.node;
136-
if let ExprKind::Binary(ref op1, ref left1, ref right1) = left.node;
136+
if let ExprKind::Binary(op1, left1, right1) = &left.node;
137137
if BinOpKind::BitAnd == op1.node;
138-
if let ExprKind::Lit(ref lit) = right1.node;
138+
if let ExprKind::Lit(lit) = &right1.node;
139139
if let LitKind::Int(n, _) = lit.node;
140-
if let ExprKind::Lit(ref lit1) = right.node;
140+
if let ExprKind::Lit(lit1) = &right.node;
141141
if let LitKind::Int(0, _) = lit1.node;
142142
if n.leading_zeros() == n.count_zeros();
143143
if n > u128::from(self.verbose_bit_mask_threshold);
@@ -173,7 +173,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
173173
}
174174

175175
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
176-
if let ExprKind::Binary(ref op, ref left, ref right) = bit_op.node {
176+
if let ExprKind::Binary(op, left, right) = &bit_op.node {
177177
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
178178
return;
179179
}

clippy_lints/src/block_in_if_condition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks
8888

8989
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
9090
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
91-
if let ExprKind::If(ref check, ref then, _) = expr.node {
92-
if let ExprKind::Block(ref block, _) = check.node {
91+
if let ExprKind::If(check, then, _) = &expr.node {
92+
if let ExprKind::Block(block, _) = &check.node {
9393
if block.rules == DefaultBlock {
9494
if block.stmts.is_empty() {
95-
if let Some(ref ex) = block.expr {
95+
if let Some(ex) = &block.expr {
9696
// don't dig into the expression here, just suggest that they remove
9797
// the block
9898
if in_macro(expr.span) || differing_macro_contexts(expr.span, ex.span) {

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)