From d0cc201204644a2ccc0d9c9f5ff5ec44870cadc5 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 10 Nov 2021 15:42:49 -0600 Subject: [PATCH] author: fix some bugs --- clippy_lints/src/utils/author.rs | 34 +++++++++++----------- tests/ui/author/blocks.stdout | 10 +++---- tests/ui/author/if.stdout | 10 +++---- tests/ui/author/loop.stdout | 50 ++++++++++++++++---------------- tests/ui/author/matches.stdout | 4 +-- tests/ui/author/struct.stdout | 10 +++---- 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 26b2a89d2ce..3af90c5b1f4 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -196,7 +196,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { if let Some(label) = label { let label_bind = self.next("label"); - println!(" if let Some(ref {}) = {}", label_bind, self.current); + println!(" if let Some(ref {}) = {};", label_bind, self.current); let label_name_bind = self.next("label_name"); let label_name = label.ident.name; @@ -246,7 +246,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { let str_pat = self.next("s"); println!(" if let LitKind::Str(ref {}, _) = {}.node;", str_pat, lit_pat); - println!(" if {}.as_str() == {:?}", str_pat, &*text.as_str()); + println!(" if {}.as_str() == {:?};", str_pat, &*text.as_str()); }, } } @@ -311,7 +311,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { let body_pat = self.next("body"); println!( - " if let Some(higher::While {{ condition: {}, body: {} }}) = higher::While::hir({})", + " if let Some(higher::While {{ condition: {}, body: {} }}) = higher::While::hir({});", condition_pat, body_pat, self.current ); @@ -335,7 +335,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { let if_then_pat = self.next("if_then"); println!( - " if let Some(higher::WhileLet {{ let_pat: {}, let_expr: {}, if_then: {} }}) = higher::WhileLet::hir({})", + " if let Some(higher::WhileLet {{ let_pat: {}, let_expr: {}, if_then: {} }}) = higher::WhileLet::hir({});", let_pat_, let_expr_pat, if_then_pat, self.current ); @@ -364,7 +364,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { let else_pat = self.next("else_expr"); println!( - " if let Some(higher::IfLet {{ let_pat: {}, let_expr: {}, if_then: {}, if_else: {}}}) = higher::IfLet::hir({})", + " if let Some(higher::IfLet {{ let_pat: {}, let_expr: {}, if_then: {}, if_else: {}}}) = higher::IfLet::hir({});", let_pat_, let_expr_pat, if_then_pat, else_pat, self.current ); @@ -391,7 +391,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { let else_pat = self.next("else_expr"); println!( - " if let Some(higher::If {{ cond: {}, then: {}, r#else: {}}}) = higher::If::hir({})", + " if let Some(higher::If {{ cond: {}, then: {}, r#else: {}}}) = higher::If::hir({});", cond_pat, then_pat, else_pat, self.current ); @@ -415,7 +415,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { let body_pat = self.next("body"); println!( - " if let Some(higher::ForLoop {{ pat: {}, arg: {}, body: {}, ..}}) = higher::ForLoop::hir({})", + " if let Some(higher::ForLoop {{ pat: {}, arg: {}, body: {}, ..}}) = higher::ForLoop::hir({});", pat_, arg_pat, body_pat, self.current ); @@ -596,7 +596,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { let label_pat = self.next("label"); println!( - "Loop(ref {}, ref {}, LoopSource::{:?}) = {};", + "Loop(ref {}, ref {}, LoopSource::{:?}, _) = {};", body_pat, label_pat, des, current ); @@ -626,10 +626,10 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { let body_id_pat = self.next("body_id"); println!( - "Closure({}, ref {}, ref {}, _, {}) = {}", + "Closure({}, ref {}, ref {}, _, {}) = {};", capture_by, fn_decl_pat, body_id_pat, movability, current ); - println!(" if let {} = {}.output", ret_ty, fn_decl_pat); + println!(" if let {} = {}.output;", ret_ty, fn_decl_pat); let hir = self.cx.tcx.hir(); let body = hir.body(body_id); @@ -699,7 +699,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { let field_name_pat = self.next("field_name"); println!("Field(ref {}, ref {}) = {};", obj_pat, field_name_pat, current); - println!(" if {}.as_str() == {:?}", field_name_pat, field_ident.as_str()); + println!(" if {}.as_str() == {:?};", field_name_pat, field_ident.as_str()); self.current = obj_pat; self.visit_expr(object); @@ -804,13 +804,13 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { for (i, field) in fields.iter().enumerate() { println!( - " if {}[{}].ident.name.as_str() == {:?}", + " if {}[{}].ident.name.as_str() == {:?};", fields_pat, i, &*field.ident.name.as_str() ); - self.current = format!("{}[{}]", fields_pat, i); + self.current = format!("{}[{}].expr", fields_pat, i); self.visit_expr(field.expr); } }, @@ -909,7 +909,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { for (i, field) in fields.iter().enumerate() { println!( - " if {}[{}].ident.name.as_str() == {:?}", + " if {}[{}].ident.name.as_str() == {:?};", fields_pat, i, &*field.ident.name.as_str() @@ -981,7 +981,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { }, PatKind::Lit(lit_expr) => { let lit_expr_pat = self.next("lit_expr"); - println!("Lit(ref {}) = {}", lit_expr_pat, current); + println!("Lit(ref {}) = {};", lit_expr_pat, current); self.current = lit_expr_pat; self.visit_expr(lit_expr); @@ -1063,7 +1063,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { // Expr without trailing semi-colon (must have unit type): StmtKind::Expr(e) => { let e_pat = self.next("e"); - println!("Expr(ref {}, _) = {}", e_pat, current); + println!("Expr(ref {}, _) = {};", e_pat, current); self.current = e_pat; self.visit_expr(e); @@ -1072,7 +1072,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> { // Expr with trailing semi-colon (may have any type): StmtKind::Semi(e) => { let e_pat = self.next("e"); - println!("Semi(ref {}, _) = {}", e_pat, current); + println!("Semi(ref {}) = {};", e_pat, current); self.current = e_pat; self.visit_expr(e); diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 3454d2bd69c..d9bd738ae92 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -13,7 +13,7 @@ if_chain! { if let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node; if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local1.pat.kind; if name1.as_str() == "_t"; - if let StmtKind::Semi(ref e, _) = block.stmts[2].kind + if let StmtKind::Semi(ref e) = block.stmts[2].kind; if let ExprKind::Unary(UnOp::Neg, ref inner) = e.kind; if let ExprKind::Path(ref qpath) = inner.kind; if match_qpath(qpath, &["x"]); @@ -45,15 +45,15 @@ if_chain! { } } if_chain! { - if let ExprKind::Closure(CaptureBy::Value, ref fn_decl, ref body_id, _, None) = expr.kind - if let FnRetTy::DefaultReturn(_) = fn_decl.output + if let ExprKind::Closure(CaptureBy::Value, ref fn_decl, ref body_id, _, None) = expr.kind; + if let FnRetTy::DefaultReturn(_) = fn_decl.output; let body = cx.tcx.hir().body(body_id); if let ExprKind::Call(ref func, ref args) = body.value.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, ref fn_decl1, ref body_id1, _, Some(Movability::Static)) = args[0].kind - if let FnRetTy::DefaultReturn(_) = fn_decl1.output + if let ExprKind::Closure(CaptureBy::Value, ref fn_decl1, ref 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(ref block, ref label) = body1.value.kind; if block.stmts.len() == 0; diff --git a/tests/ui/author/if.stdout b/tests/ui/author/if.stdout index 6acdbee176a..889d3e595ba 100644 --- a/tests/ui/author/if.stdout +++ b/tests/ui/author/if.stdout @@ -1,12 +1,12 @@ if_chain! { if let StmtKind::Local(ref local) = stmt.kind; if let Some(ref init) = local.init; - if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(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 LitKind::Bool(true) = lit.node; if let ExprKind::Block(ref block, ref label) = then.kind; if block.stmts.len() == 1; - if let StmtKind::Semi(ref e, _) = block.stmts[0].kind + if let StmtKind::Semi(ref e) = block.stmts[0].kind; if let ExprKind::Binary(ref op, ref left, ref right) = e.kind; if BinOpKind::Eq == op.node; if let ExprKind::Lit(ref lit1) = left.kind; @@ -16,7 +16,7 @@ if_chain! { if block.expr.is_none(); if let ExprKind::Block(ref block1, ref label1) = else_expr.kind; if block1.stmts.len() == 1; - if let StmtKind::Semi(ref e1, _) = block1.stmts[0].kind + if let StmtKind::Semi(ref e1) = block1.stmts[0].kind; if let ExprKind::Binary(ref op1, ref left1, ref right1) = e1.kind; if BinOpKind::Eq == op1.node; if let ExprKind::Lit(ref lit3) = left1.kind; @@ -30,8 +30,8 @@ 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(ref lit_expr) = let_pat.kind + 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(ref lit_expr) = let_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; diff --git a/tests/ui/author/loop.stdout b/tests/ui/author/loop.stdout index ce1720551c5..9e7300335c5 100644 --- a/tests/ui/author/loop.stdout +++ b/tests/ui/author/loop.stdout @@ -1,16 +1,16 @@ if_chain! { if let ExprKind::DropTemps(ref expr) = expr.kind; - if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr) + if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr); if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = pat.kind; if name.as_str() == "y"; if let ExprKind::Struct(ref qpath, ref fields, None) = arg.kind; if matches!(qpath, QPath::LangItem(LangItem::Range, _)); if fields.len() == 2; - if fields[0].ident.name.as_str() == "start" - if let ExprKind::Lit(ref lit) = fields[0].kind; + if fields[0].ident.name.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 let ExprKind::Lit(ref lit1) = fields[1].kind; + if fields[1].ident.name.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(ref block, ref label) = body.kind; if block.stmts.len() == 1; @@ -27,20 +27,20 @@ if_chain! { } if_chain! { if let ExprKind::DropTemps(ref expr) = expr.kind; - if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr) + if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr); if let PatKind::Wild = pat.kind; if let ExprKind::Struct(ref qpath, ref fields, None) = arg.kind; if matches!(qpath, QPath::LangItem(LangItem::Range, _)); if fields.len() == 2; - if fields[0].ident.name.as_str() == "start" - if let ExprKind::Lit(ref lit) = fields[0].kind; + if fields[0].ident.name.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 let ExprKind::Lit(ref lit1) = fields[1].kind; + if fields[1].ident.name.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(ref block, ref label) = body.kind; if block.stmts.len() == 1; - if let StmtKind::Semi(ref e, _) = block.stmts[0].kind + if let StmtKind::Semi(ref e) = block.stmts[0].kind; if let ExprKind::Break(ref destination, None) = e.kind; if block.expr.is_none(); then { @@ -49,22 +49,22 @@ if_chain! { } if_chain! { if let ExprKind::DropTemps(ref expr) = expr.kind; - if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr) + if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr); if let PatKind::Wild = pat.kind; if let ExprKind::Struct(ref qpath, ref fields, None) = arg.kind; if matches!(qpath, QPath::LangItem(LangItem::Range, _)); if fields.len() == 2; - if fields[0].ident.name.as_str() == "start" - if let ExprKind::Lit(ref lit) = fields[0].kind; + if fields[0].ident.name.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 let ExprKind::Lit(ref lit1) = fields[1].kind; + if fields[1].ident.name.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(ref block, ref label) = body.kind; if block.stmts.len() == 1; - if let StmtKind::Semi(ref e, _) = block.stmts[0].kind + if let StmtKind::Semi(ref e) = block.stmts[0].kind; if let ExprKind::Break(ref destination, None) = e.kind; - if let Some(ref label1) = destination.label + if let Some(ref label1) = destination.label; if label_name.ident.name.as_str() == "'label"; if block.expr.is_none(); then { @@ -72,12 +72,12 @@ if_chain! { } } if_chain! { - if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr) + 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(ref block, ref label) = body.kind; if block.stmts.len() == 1; - if let StmtKind::Semi(ref e, _) = block.stmts[0].kind + if let StmtKind::Semi(ref e) = block.stmts[0].kind; if let ExprKind::Break(ref destination, None) = e.kind; if block.expr.is_none(); then { @@ -85,15 +85,15 @@ if_chain! { } } if_chain! { - if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr) - if let PatKind::Lit(ref lit_expr) = let_pat.kind + if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr); + if let PatKind::Lit(ref lit_expr) = let_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 match_qpath(qpath, &["a"]); if let ExprKind::Block(ref block, ref label) = if_then.kind; if block.stmts.len() == 1; - if let StmtKind::Semi(ref e, _) = block.stmts[0].kind + if let StmtKind::Semi(ref e) = block.stmts[0].kind; if let ExprKind::Break(ref destination, None) = e.kind; if block.expr.is_none(); then { @@ -101,9 +101,9 @@ if_chain! { } } if_chain! { - if let ExprKind::Loop(ref body, ref label, LoopSource::Loop) = expr.kind; + if let ExprKind::Loop(ref body, ref label, LoopSource::Loop, _) = expr.kind; if body.stmts.len() == 1; - if let StmtKind::Semi(ref e, _) = body.stmts[0].kind + if let StmtKind::Semi(ref e) = body.stmts[0].kind; if let ExprKind::Break(ref destination, None) = e.kind; if body.expr.is_none(); then { diff --git a/tests/ui/author/matches.stdout b/tests/ui/author/matches.stdout index b802b6bff86..07d744a7723 100644 --- a/tests/ui/author/matches.stdout +++ b/tests/ui/author/matches.stdout @@ -7,7 +7,7 @@ if_chain! { 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 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::Block(ref block, ref label) = arms[1].body.kind; @@ -21,7 +21,7 @@ if_chain! { 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 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 ExprKind::Lit(ref lit5) = arms[2].body.kind; diff --git a/tests/ui/author/struct.stdout b/tests/ui/author/struct.stdout index 52c708dc8fa..66e6df195d2 100644 --- a/tests/ui/author/struct.stdout +++ b/tests/ui/author/struct.stdout @@ -2,8 +2,8 @@ if_chain! { if let ExprKind::Struct(ref qpath, ref 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]) + 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 let LitKind::Bool(true) = lit.node; if let ExprKind::Block(ref block, ref label) = then.kind; @@ -24,8 +24,8 @@ if_chain! { if let PatKind::Struct(ref qpath, ref fields, false) = arm.kind; if match_qpath(qpath, &["Test"]); if fields.len() == 1; - if fields[0].ident.name.as_str() == "field" - if let PatKind::Lit(ref lit_expr) = fields[0].kind + if fields[0].ident.name.as_str() == "field"; + if let PatKind::Lit(ref 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(ref block, ref label) = lit_expr.kind; @@ -39,7 +39,7 @@ if_chain! { if let PatKind::TupleStruct(ref qpath, ref fields, None) = arm.kind; if match_qpath(qpath, &["TestTuple"]); if fields.len() == 1; - if let PatKind::Lit(ref lit_expr) = fields[0].kind + if let PatKind::Lit(ref 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(ref block, ref label) = lit_expr.kind;