Skip to content

Commit a806ce7

Browse files
committed
author: reorder match arm
1 parent d0cc201 commit a806ce7

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

clippy_lints/src/utils/author.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
252252
}
253253

254254
fn print_match_expr(&mut self, expr: &Expr<'_>, arms: &[Arm<'_>], des: MatchSource, current: &str) {
255-
let expr_pat = self.next("expr");
255+
let expr_pat = self.next("scrutinee");
256256
let arms_pat = self.next("arms");
257257

258258
println!(
@@ -266,8 +266,8 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
266266
println!(" if {}.len() == {};", arms_pat, arms.len());
267267

268268
for (i, arm) in arms.iter().enumerate() {
269-
self.current = format!("{}[{}].body", arms_pat, i);
270-
self.visit_expr(arm.body);
269+
self.current = format!("{}[{}].pat", arms_pat, i);
270+
self.visit_pat(arm.pat);
271271

272272
if let Some(ref guard) = arm.guard {
273273
let guard_pat = self.next("guard");
@@ -300,8 +300,8 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
300300
},
301301
}
302302
}
303-
self.current = format!("{}[{}].pat", arms_pat, i);
304-
self.visit_pat(arm.pat);
303+
self.current = format!("{}[{}].body", arms_pat, i);
304+
self.visit_expr(arm.body);
305305
}
306306
}
307307

tests/ui/author/matches.stdout

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
if_chain! {
22
if let StmtKind::Local(ref local) = stmt.kind;
33
if let Some(ref init) = local.init;
4-
if let ExprKind::Match(ref expr, ref arms, MatchSource::Normal) = init.kind;
5-
if let ExprKind::Lit(ref lit) = expr.kind;
4+
if let ExprKind::Match(ref scrutinee, ref arms, MatchSource::Normal) = init.kind;
5+
if let ExprKind::Lit(ref lit) = scrutinee.kind;
66
if let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node;
77
if arms.len() == 3;
8-
if let ExprKind::Lit(ref lit1) = arms[0].body.kind;
9-
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node;
108
if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind;
11-
if let ExprKind::Lit(ref lit2) = lit_expr.kind;
12-
if let LitKind::Int(16, LitIntType::Unsuffixed) = lit2.node;
9+
if let ExprKind::Lit(ref lit1) = lit_expr.kind;
10+
if let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node;
11+
if let ExprKind::Lit(ref lit2) = arms[0].body.kind;
12+
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node;
13+
if let PatKind::Lit(ref lit_expr1) = arms[1].pat.kind;
14+
if let ExprKind::Lit(ref lit3) = lit_expr1.kind;
15+
if let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node;
1316
if let ExprKind::Block(ref block, ref label) = arms[1].body.kind;
1417
if block.stmts.len() == 1;
1518
if let StmtKind::Local(ref local1) = block.stmts[0].kind;
1619
if let Some(ref init1) = local1.init;
17-
if let ExprKind::Lit(ref lit3) = init1.kind;
18-
if let LitKind::Int(3, LitIntType::Unsuffixed) = lit3.node;
20+
if let ExprKind::Lit(ref lit4) = init1.kind;
21+
if let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node;
1922
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local1.pat.kind;
2023
if name.as_str() == "x";
2124
if let Some(trailing_expr) = &block.expr;
2225
if let ExprKind::Path(ref qpath) = trailing_expr.kind;
2326
if match_qpath(qpath, &["x"]);
24-
if let PatKind::Lit(ref lit_expr1) = arms[1].pat.kind;
25-
if let ExprKind::Lit(ref lit4) = lit_expr1.kind;
26-
if let LitKind::Int(17, LitIntType::Unsuffixed) = lit4.node;
27+
if let PatKind::Wild = arms[2].pat.kind;
2728
if let ExprKind::Lit(ref lit5) = arms[2].body.kind;
2829
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node;
29-
if let PatKind::Wild = arms[2].pat.kind;
3030
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local.pat.kind;
3131
if name1.as_str() == "a";
3232
then {

0 commit comments

Comments
 (0)