author: reorder match arm

This commit is contained in:
Cameron Steffen 2021-11-08 17:47:33 -06:00
parent d0cc201204
commit a806ce79b6
2 changed files with 17 additions and 17 deletions

View File

@ -252,7 +252,7 @@ fn print_lit_expr(&mut self, lit: &Lit, current: &str) {
}
fn print_match_expr(&mut self, expr: &Expr<'_>, arms: &[Arm<'_>], des: MatchSource, current: &str) {
let expr_pat = self.next("expr");
let expr_pat = self.next("scrutinee");
let arms_pat = self.next("arms");
println!(
@ -266,8 +266,8 @@ fn print_match_expr(&mut self, expr: &Expr<'_>, arms: &[Arm<'_>], des: MatchSour
println!(" if {}.len() == {};", arms_pat, arms.len());
for (i, arm) in arms.iter().enumerate() {
self.current = format!("{}[{}].body", arms_pat, i);
self.visit_expr(arm.body);
self.current = format!("{}[{}].pat", arms_pat, i);
self.visit_pat(arm.pat);
if let Some(ref guard) = arm.guard {
let guard_pat = self.next("guard");
@ -300,8 +300,8 @@ fn print_match_expr(&mut self, expr: &Expr<'_>, arms: &[Arm<'_>], des: MatchSour
},
}
}
self.current = format!("{}[{}].pat", arms_pat, i);
self.visit_pat(arm.pat);
self.current = format!("{}[{}].body", arms_pat, i);
self.visit_expr(arm.body);
}
}

View File

@ -1,32 +1,32 @@
if_chain! {
if let StmtKind::Local(ref local) = stmt.kind;
if let Some(ref init) = local.init;
if let ExprKind::Match(ref expr, ref arms, MatchSource::Normal) = init.kind;
if let ExprKind::Lit(ref lit) = expr.kind;
if let ExprKind::Match(ref scrutinee, ref arms, MatchSource::Normal) = init.kind;
if let ExprKind::Lit(ref lit) = scrutinee.kind;
if let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node;
if arms.len() == 3;
if let ExprKind::Lit(ref lit1) = arms[0].body.kind;
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node;
if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind;
if let ExprKind::Lit(ref lit2) = lit_expr.kind;
if let LitKind::Int(16, LitIntType::Unsuffixed) = lit2.node;
if let ExprKind::Lit(ref lit1) = lit_expr.kind;
if let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node;
if let ExprKind::Lit(ref lit2) = arms[0].body.kind;
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node;
if let PatKind::Lit(ref lit_expr1) = arms[1].pat.kind;
if let ExprKind::Lit(ref lit3) = lit_expr1.kind;
if let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node;
if let ExprKind::Block(ref block, ref label) = arms[1].body.kind;
if block.stmts.len() == 1;
if let StmtKind::Local(ref local1) = block.stmts[0].kind;
if let Some(ref init1) = local1.init;
if let ExprKind::Lit(ref lit3) = init1.kind;
if let LitKind::Int(3, LitIntType::Unsuffixed) = lit3.node;
if let ExprKind::Lit(ref lit4) = init1.kind;
if let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node;
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local1.pat.kind;
if name.as_str() == "x";
if let Some(trailing_expr) = &block.expr;
if let ExprKind::Path(ref qpath) = trailing_expr.kind;
if match_qpath(qpath, &["x"]);
if let PatKind::Lit(ref lit_expr1) = arms[1].pat.kind;
if let ExprKind::Lit(ref lit4) = lit_expr1.kind;
if let LitKind::Int(17, LitIntType::Unsuffixed) = lit4.node;
if let PatKind::Wild = arms[2].pat.kind;
if let ExprKind::Lit(ref lit5) = arms[2].body.kind;
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node;
if let PatKind::Wild = arms[2].pat.kind;
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local.pat.kind;
if name1.as_str() == "a";
then {