Make author DRYer

This commit is contained in:
Cameron Steffen 2021-11-05 17:05:04 -05:00
parent 72d7b9c097
commit 27a1763eac
8 changed files with 552 additions and 914 deletions

View File

@ -2,6 +2,7 @@
#![feature(box_patterns)]
#![feature(drain_filter)]
#![feature(format_args_capture)]
#![feature(in_band_lifetimes)]
#![feature(iter_zip)]
#![feature(once_cell)]

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
if_chain! {
if let ExprKind::Block(block, label) = expr.kind;
if let ExprKind::Block(block, None) = expr.kind;
if block.stmts.len() == 3;
if let StmtKind::Local(local) = block.stmts[0].kind;
if let Some(init) = local.init;
@ -23,14 +23,14 @@ if_chain! {
}
}
if_chain! {
if let ExprKind::Block(block, label) = expr.kind;
if let ExprKind::Block(block, None) = expr.kind;
if block.stmts.len() == 1;
if let StmtKind::Local(local) = block.stmts[0].kind;
if let Some(init) = local.init;
if let ExprKind::Call(func, args) = init.kind;
if let ExprKind::Path(ref qpath) = func.kind;
if match_qpath(qpath, &["String", "new"]);
if args.len() == 0;
if args.is_empty();
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind;
if name.as_str() == "expr";
if let Some(trailing_expr) = block.expr;
@ -47,16 +47,16 @@ if_chain! {
if_chain! {
if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind;
if let FnRetTy::DefaultReturn(_) = fn_decl.output;
let body = cx.tcx.hir().body(body_id);
if let ExprKind::Call(func, args) = body.value.kind;
let expr1 = &cx.tcx.hir().body(body_id).value;
if let ExprKind::Call(func, args) = expr1.kind;
if let ExprKind::Path(ref qpath) = func.kind;
if matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _));
if args.len() == 1;
if let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind;
if let FnRetTy::DefaultReturn(_) = fn_decl1.output;
let body1 = cx.tcx.hir().body(body_id1);
if let ExprKind::Block(block, label) = body1.value.kind;
if block.stmts.len() == 0;
let expr2 = &cx.tcx.hir().body(body_id1).value;
if let ExprKind::Block(block, None) = expr2.kind;
if block.stmts.is_empty();
if block.expr.is_none();
then {
// report your lint here

View File

@ -1,10 +1,11 @@
if_chain! {
if let StmtKind::Local(local) = stmt.kind;
if let Some(init) = local.init;
if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(init);
if let ExprKind::Lit(ref lit) = cond.kind;
if let ExprKind::If(cond, then, Some(else_expr)) = init.kind;
if let ExprKind::DropTemps(expr) = cond.kind;
if let ExprKind::Lit(ref lit) = expr.kind;
if let LitKind::Bool(true) = lit.node;
if let ExprKind::Block(block, label) = then.kind;
if let ExprKind::Block(block, None) = then.kind;
if block.stmts.len() == 1;
if let StmtKind::Semi(e) = block.stmts[0].kind;
if let ExprKind::Binary(op, left, right) = e.kind;
@ -14,7 +15,7 @@ if_chain! {
if let ExprKind::Lit(ref lit2) = right.kind;
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit2.node;
if block.expr.is_none();
if let ExprKind::Block(block1, label1) = else_expr.kind;
if let ExprKind::Block(block1, None) = else_expr.kind;
if block1.stmts.len() == 1;
if let StmtKind::Semi(e1) = block1.stmts[0].kind;
if let ExprKind::Binary(op1, left1, right1) = e1.kind;
@ -30,17 +31,18 @@ if_chain! {
}
}
if_chain! {
if let Some(higher::IfLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then, if_else: else_expr}) = higher::IfLet::hir(expr);
if let PatKind::Lit(lit_expr) = let_pat.kind;
if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind;
if let ExprKind::Let(pat, expr1, _) = cond.kind;
if let PatKind::Lit(lit_expr) = pat.kind;
if let ExprKind::Lit(ref lit) = lit_expr.kind;
if let LitKind::Bool(true) = lit.node;
if let ExprKind::Path(ref qpath) = let_expr.kind;
if let ExprKind::Path(ref qpath) = expr1.kind;
if match_qpath(qpath, &["a"]);
if let ExprKind::Block(block, label) = if_then.kind;
if block.stmts.len() == 0;
if let ExprKind::Block(block, None) = then.kind;
if block.stmts.is_empty();
if block.expr.is_none();
if let ExprKind::Block(block1, label1) = else_expr.kind;
if block1.stmts.len() == 0;
if let ExprKind::Block(block1, None) = else_expr.kind;
if block1.stmts.is_empty();
if block1.expr.is_none();
then {
// report your lint here

View File

@ -1,18 +1,18 @@
if_chain! {
if let ExprKind::DropTemps(expr) = expr.kind;
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr);
if let ExprKind::DropTemps(expr1) = expr.kind;
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr1);
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = pat.kind;
if name.as_str() == "y";
if let ExprKind::Struct(qpath, fields, None) = arg.kind;
if matches!(qpath, QPath::LangItem(LangItem::Range, _));
if fields.len() == 2;
if fields[0].ident.name.as_str() == "start";
if fields[0].ident.as_str() == "start";
if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
if fields[1].ident.name.as_str() == "end";
if fields[1].ident.as_str() == "end";
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
if let ExprKind::Block(block, label) = body.kind;
if let ExprKind::Block(block, None) = body.kind;
if block.stmts.len() == 1;
if let StmtKind::Local(local) = block.stmts[0].kind;
if let Some(init) = local.init;
@ -26,46 +26,47 @@ if_chain! {
}
}
if_chain! {
if let ExprKind::DropTemps(expr) = expr.kind;
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr);
if let ExprKind::DropTemps(expr1) = expr.kind;
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr1);
if let PatKind::Wild = pat.kind;
if let ExprKind::Struct(qpath, fields, None) = arg.kind;
if matches!(qpath, QPath::LangItem(LangItem::Range, _));
if fields.len() == 2;
if fields[0].ident.name.as_str() == "start";
if fields[0].ident.as_str() == "start";
if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
if fields[1].ident.name.as_str() == "end";
if fields[1].ident.as_str() == "end";
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
if let ExprKind::Block(block, label) = body.kind;
if let ExprKind::Block(block, None) = body.kind;
if block.stmts.len() == 1;
if let StmtKind::Semi(e) = block.stmts[0].kind;
if let ExprKind::Break(destination, None) = e.kind;
if destination.label.is_none();
if block.expr.is_none();
then {
// report your lint here
}
}
if_chain! {
if let ExprKind::DropTemps(expr) = expr.kind;
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr);
if let ExprKind::DropTemps(expr1) = expr.kind;
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr1);
if let PatKind::Wild = pat.kind;
if let ExprKind::Struct(qpath, fields, None) = arg.kind;
if matches!(qpath, QPath::LangItem(LangItem::Range, _));
if fields.len() == 2;
if fields[0].ident.name.as_str() == "start";
if fields[0].ident.as_str() == "start";
if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
if fields[1].ident.name.as_str() == "end";
if fields[1].ident.as_str() == "end";
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
if let ExprKind::Block(block, label) = body.kind;
if let ExprKind::Block(block, None) = body.kind;
if block.stmts.len() == 1;
if let StmtKind::Semi(e) = block.stmts[0].kind;
if let ExprKind::Break(destination, None) = e.kind;
if let Some(label1) = destination.label;
if label_name.ident.name.as_str() == "'label";
if let Some(label) = destination.label;
if label.ident.as_str() == "'label";
if block.expr.is_none();
then {
// report your lint here
@ -75,10 +76,11 @@ if_chain! {
if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr);
if let ExprKind::Path(ref qpath) = condition.kind;
if match_qpath(qpath, &["a"]);
if let ExprKind::Block(block, label) = body.kind;
if let ExprKind::Block(block, None) = body.kind;
if block.stmts.len() == 1;
if let StmtKind::Semi(e) = block.stmts[0].kind;
if let ExprKind::Break(destination, None) = e.kind;
if destination.label.is_none();
if block.expr.is_none();
then {
// report your lint here
@ -91,20 +93,22 @@ if_chain! {
if let LitKind::Bool(true) = lit.node;
if let ExprKind::Path(ref qpath) = let_expr.kind;
if match_qpath(qpath, &["a"]);
if let ExprKind::Block(block, label) = if_then.kind;
if let ExprKind::Block(block, None) = if_then.kind;
if block.stmts.len() == 1;
if let StmtKind::Semi(e) = block.stmts[0].kind;
if let ExprKind::Break(destination, None) = e.kind;
if destination.label.is_none();
if block.expr.is_none();
then {
// report your lint here
}
}
if_chain! {
if let ExprKind::Loop(body, label, LoopSource::Loop, _) = expr.kind;
if let ExprKind::Loop(body, None, LoopSource::Loop, _) = expr.kind;
if body.stmts.len() == 1;
if let StmtKind::Semi(e) = body.stmts[0].kind;
if let ExprKind::Break(destination, None) = e.kind;
if destination.label.is_none();
if body.expr.is_none();
then {
// report your lint here

View File

@ -8,12 +8,14 @@ if_chain! {
if let PatKind::Lit(lit_expr) = arms[0].pat.kind;
if let ExprKind::Lit(ref lit1) = lit_expr.kind;
if let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node;
if arms[0].guard.is_none();
if let ExprKind::Lit(ref lit2) = arms[0].body.kind;
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node;
if let PatKind::Lit(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(block, label) = arms[1].body.kind;
if arms[1].guard.is_none();
if let ExprKind::Block(block, None) = arms[1].body.kind;
if block.stmts.len() == 1;
if let StmtKind::Local(local1) = block.stmts[0].kind;
if let Some(init1) = local1.init;
@ -25,6 +27,7 @@ if_chain! {
if let ExprKind::Path(ref qpath) = trailing_expr.kind;
if match_qpath(qpath, &["x"]);
if let PatKind::Wild = arms[2].pat.kind;
if arms[2].guard.is_none();
if let ExprKind::Lit(ref lit5) = arms[2].body.kind;
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node;
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local.pat.kind;

View File

@ -2,7 +2,8 @@ if_chain! {
if let ExprKind::Repeat(value, length) = expr.kind;
if let ExprKind::Lit(ref lit) = value.kind;
if let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node;
if let ExprKind::Lit(ref lit1) = length.value.kind;
let expr1 = &cx.tcx.hir().body(length.body).value;
if let ExprKind::Lit(ref lit1) = expr1.kind;
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node;
then {
// report your lint here

View File

@ -2,17 +2,18 @@ if_chain! {
if let ExprKind::Struct(qpath, fields, None) = expr.kind;
if match_qpath(qpath, &["Test"]);
if fields.len() == 1;
if fields[0].ident.name.as_str() == "field";
if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(fields[0].expr);
if let ExprKind::Lit(ref lit) = cond.kind;
if fields[0].ident.as_str() == "field";
if let ExprKind::If(cond, then, Some(else_expr)) = fields[0].expr.kind;
if let ExprKind::DropTemps(expr1) = cond.kind;
if let ExprKind::Lit(ref lit) = expr1.kind;
if let LitKind::Bool(true) = lit.node;
if let ExprKind::Block(block, label) = then.kind;
if block.stmts.len() == 0;
if let ExprKind::Block(block, None) = then.kind;
if block.stmts.is_empty();
if let Some(trailing_expr) = block.expr;
if let ExprKind::Lit(ref lit1) = trailing_expr.kind;
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node;
if let ExprKind::Block(block1, label1) = else_expr.kind;
if block1.stmts.len() == 0;
if let ExprKind::Block(block1, None) = else_expr.kind;
if block1.stmts.is_empty();
if let Some(trailing_expr1) = block1.expr;
if let ExprKind::Lit(ref lit2) = trailing_expr1.kind;
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit2.node;
@ -21,29 +22,31 @@ if_chain! {
}
}
if_chain! {
if let PatKind::Struct(ref qpath, fields, false) = arm.kind;
if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind;
if match_qpath(qpath, &["Test"]);
if fields.len() == 1;
if fields[0].ident.name.as_str() == "field";
if let PatKind::Lit(lit_expr) = fields[0].kind;
if fields[0].ident.as_str() == "field";
if let PatKind::Lit(lit_expr) = fields[0].pat.kind;
if let ExprKind::Lit(ref lit) = lit_expr.kind;
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
if let ExprKind::Block(block, label) = lit_expr.kind;
if block.stmts.len() == 0;
if arm.guard.is_none();
if let ExprKind::Block(block, None) = arm.body.kind;
if block.stmts.is_empty();
if block.expr.is_none();
then {
// report your lint here
}
}
if_chain! {
if let PatKind::TupleStruct(ref qpath, fields, None) = arm.kind;
if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind;
if match_qpath(qpath, &["TestTuple"]);
if fields.len() == 1;
if let PatKind::Lit(lit_expr) = fields[0].kind;
if let ExprKind::Lit(ref lit) = lit_expr.kind;
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
if let ExprKind::Block(block, label) = lit_expr.kind;
if block.stmts.len() == 0;
if arm.guard.is_none();
if let ExprKind::Block(block, None) = arm.body.kind;
if block.stmts.is_empty();
if block.expr.is_none();
then {
// report your lint here
@ -51,7 +54,7 @@ if_chain! {
}
if_chain! {
if let ExprKind::MethodCall(method_name, _, args, _) = expr.kind;
if method_name.ident.name.as_str() == test;
if method_name.ident.as_str() == "test";
if args.len() == 1;
if let ExprKind::Path(ref qpath) = args[0].kind;
if match_qpath(qpath, &["test_method_call"]);