Skip to content

Commit d0cc201

Browse files
committed
author: fix some bugs
1 parent ce01346 commit d0cc201

File tree

6 files changed

+59
-59
lines changed

6 files changed

+59
-59
lines changed

clippy_lints/src/utils/author.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
196196
if let Some(label) = label {
197197
let label_bind = self.next("label");
198198

199-
println!(" if let Some(ref {}) = {}", label_bind, self.current);
199+
println!(" if let Some(ref {}) = {};", label_bind, self.current);
200200

201201
let label_name_bind = self.next("label_name");
202202
let label_name = label.ident.name;
@@ -246,7 +246,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
246246
let str_pat = self.next("s");
247247

248248
println!(" if let LitKind::Str(ref {}, _) = {}.node;", str_pat, lit_pat);
249-
println!(" if {}.as_str() == {:?}", str_pat, &*text.as_str());
249+
println!(" if {}.as_str() == {:?};", str_pat, &*text.as_str());
250250
},
251251
}
252252
}
@@ -311,7 +311,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
311311
let body_pat = self.next("body");
312312

313313
println!(
314-
" if let Some(higher::While {{ condition: {}, body: {} }}) = higher::While::hir({})",
314+
" if let Some(higher::While {{ condition: {}, body: {} }}) = higher::While::hir({});",
315315
condition_pat, body_pat, self.current
316316
);
317317

@@ -335,7 +335,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
335335
let if_then_pat = self.next("if_then");
336336

337337
println!(
338-
" if let Some(higher::WhileLet {{ let_pat: {}, let_expr: {}, if_then: {} }}) = higher::WhileLet::hir({})",
338+
" if let Some(higher::WhileLet {{ let_pat: {}, let_expr: {}, if_then: {} }}) = higher::WhileLet::hir({});",
339339
let_pat_, let_expr_pat, if_then_pat, self.current
340340
);
341341

@@ -364,7 +364,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
364364
let else_pat = self.next("else_expr");
365365

366366
println!(
367-
" if let Some(higher::IfLet {{ let_pat: {}, let_expr: {}, if_then: {}, if_else: {}}}) = higher::IfLet::hir({})",
367+
" if let Some(higher::IfLet {{ let_pat: {}, let_expr: {}, if_then: {}, if_else: {}}}) = higher::IfLet::hir({});",
368368
let_pat_, let_expr_pat, if_then_pat, else_pat, self.current
369369
);
370370

@@ -391,7 +391,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
391391
let else_pat = self.next("else_expr");
392392

393393
println!(
394-
" if let Some(higher::If {{ cond: {}, then: {}, r#else: {}}}) = higher::If::hir({})",
394+
" if let Some(higher::If {{ cond: {}, then: {}, r#else: {}}}) = higher::If::hir({});",
395395
cond_pat, then_pat, else_pat, self.current
396396
);
397397

@@ -415,7 +415,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
415415
let body_pat = self.next("body");
416416

417417
println!(
418-
" if let Some(higher::ForLoop {{ pat: {}, arg: {}, body: {}, ..}}) = higher::ForLoop::hir({})",
418+
" if let Some(higher::ForLoop {{ pat: {}, arg: {}, body: {}, ..}}) = higher::ForLoop::hir({});",
419419
pat_, arg_pat, body_pat, self.current
420420
);
421421

@@ -596,7 +596,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
596596
let label_pat = self.next("label");
597597

598598
println!(
599-
"Loop(ref {}, ref {}, LoopSource::{:?}) = {};",
599+
"Loop(ref {}, ref {}, LoopSource::{:?}, _) = {};",
600600
body_pat, label_pat, des, current
601601
);
602602

@@ -626,10 +626,10 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
626626
let body_id_pat = self.next("body_id");
627627

628628
println!(
629-
"Closure({}, ref {}, ref {}, _, {}) = {}",
629+
"Closure({}, ref {}, ref {}, _, {}) = {};",
630630
capture_by, fn_decl_pat, body_id_pat, movability, current
631631
);
632-
println!(" if let {} = {}.output", ret_ty, fn_decl_pat);
632+
println!(" if let {} = {}.output;", ret_ty, fn_decl_pat);
633633

634634
let hir = self.cx.tcx.hir();
635635
let body = hir.body(body_id);
@@ -699,7 +699,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
699699
let field_name_pat = self.next("field_name");
700700

701701
println!("Field(ref {}, ref {}) = {};", obj_pat, field_name_pat, current);
702-
println!(" if {}.as_str() == {:?}", field_name_pat, field_ident.as_str());
702+
println!(" if {}.as_str() == {:?};", field_name_pat, field_ident.as_str());
703703

704704
self.current = obj_pat;
705705
self.visit_expr(object);
@@ -804,13 +804,13 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
804804

805805
for (i, field) in fields.iter().enumerate() {
806806
println!(
807-
" if {}[{}].ident.name.as_str() == {:?}",
807+
" if {}[{}].ident.name.as_str() == {:?};",
808808
fields_pat,
809809
i,
810810
&*field.ident.name.as_str()
811811
);
812812

813-
self.current = format!("{}[{}]", fields_pat, i);
813+
self.current = format!("{}[{}].expr", fields_pat, i);
814814
self.visit_expr(field.expr);
815815
}
816816
},
@@ -909,7 +909,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
909909

910910
for (i, field) in fields.iter().enumerate() {
911911
println!(
912-
" if {}[{}].ident.name.as_str() == {:?}",
912+
" if {}[{}].ident.name.as_str() == {:?};",
913913
fields_pat,
914914
i,
915915
&*field.ident.name.as_str()
@@ -981,7 +981,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
981981
},
982982
PatKind::Lit(lit_expr) => {
983983
let lit_expr_pat = self.next("lit_expr");
984-
println!("Lit(ref {}) = {}", lit_expr_pat, current);
984+
println!("Lit(ref {}) = {};", lit_expr_pat, current);
985985

986986
self.current = lit_expr_pat;
987987
self.visit_expr(lit_expr);
@@ -1063,7 +1063,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
10631063
// Expr without trailing semi-colon (must have unit type):
10641064
StmtKind::Expr(e) => {
10651065
let e_pat = self.next("e");
1066-
println!("Expr(ref {}, _) = {}", e_pat, current);
1066+
println!("Expr(ref {}, _) = {};", e_pat, current);
10671067

10681068
self.current = e_pat;
10691069
self.visit_expr(e);
@@ -1072,7 +1072,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrintVisitor<'a, '_> {
10721072
// Expr with trailing semi-colon (may have any type):
10731073
StmtKind::Semi(e) => {
10741074
let e_pat = self.next("e");
1075-
println!("Semi(ref {}, _) = {}", e_pat, current);
1075+
println!("Semi(ref {}) = {};", e_pat, current);
10761076

10771077
self.current = e_pat;
10781078
self.visit_expr(e);

tests/ui/author/blocks.stdout

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if_chain! {
1313
if let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node;
1414
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local1.pat.kind;
1515
if name1.as_str() == "_t";
16-
if let StmtKind::Semi(ref e, _) = block.stmts[2].kind
16+
if let StmtKind::Semi(ref e) = block.stmts[2].kind;
1717
if let ExprKind::Unary(UnOp::Neg, ref inner) = e.kind;
1818
if let ExprKind::Path(ref qpath) = inner.kind;
1919
if match_qpath(qpath, &["x"]);
@@ -45,15 +45,15 @@ if_chain! {
4545
}
4646
}
4747
if_chain! {
48-
if let ExprKind::Closure(CaptureBy::Value, ref fn_decl, ref body_id, _, None) = expr.kind
49-
if let FnRetTy::DefaultReturn(_) = fn_decl.output
48+
if let ExprKind::Closure(CaptureBy::Value, ref fn_decl, ref body_id, _, None) = expr.kind;
49+
if let FnRetTy::DefaultReturn(_) = fn_decl.output;
5050
let body = cx.tcx.hir().body(body_id);
5151
if let ExprKind::Call(ref func, ref args) = body.value.kind;
5252
if let ExprKind::Path(ref qpath) = func.kind;
5353
if matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _));
5454
if args.len() == 1;
55-
if let ExprKind::Closure(CaptureBy::Value, ref fn_decl1, ref body_id1, _, Some(Movability::Static)) = args[0].kind
56-
if let FnRetTy::DefaultReturn(_) = fn_decl1.output
55+
if let ExprKind::Closure(CaptureBy::Value, ref fn_decl1, ref body_id1, _, Some(Movability::Static)) = args[0].kind;
56+
if let FnRetTy::DefaultReturn(_) = fn_decl1.output;
5757
let body1 = cx.tcx.hir().body(body_id1);
5858
if let ExprKind::Block(ref block, ref label) = body1.value.kind;
5959
if block.stmts.len() == 0;

tests/ui/author/if.stdout

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
if_chain! {
22
if let StmtKind::Local(ref local) = stmt.kind;
33
if let Some(ref init) = local.init;
4-
if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(init)
4+
if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(init);
55
if let ExprKind::Lit(ref lit) = cond.kind;
66
if let LitKind::Bool(true) = lit.node;
77
if let ExprKind::Block(ref block, ref label) = then.kind;
88
if block.stmts.len() == 1;
9-
if let StmtKind::Semi(ref e, _) = block.stmts[0].kind
9+
if let StmtKind::Semi(ref e) = block.stmts[0].kind;
1010
if let ExprKind::Binary(ref op, ref left, ref right) = e.kind;
1111
if BinOpKind::Eq == op.node;
1212
if let ExprKind::Lit(ref lit1) = left.kind;
@@ -16,7 +16,7 @@ if_chain! {
1616
if block.expr.is_none();
1717
if let ExprKind::Block(ref block1, ref label1) = else_expr.kind;
1818
if block1.stmts.len() == 1;
19-
if let StmtKind::Semi(ref e1, _) = block1.stmts[0].kind
19+
if let StmtKind::Semi(ref e1) = block1.stmts[0].kind;
2020
if let ExprKind::Binary(ref op1, ref left1, ref right1) = e1.kind;
2121
if BinOpKind::Eq == op1.node;
2222
if let ExprKind::Lit(ref lit3) = left1.kind;
@@ -30,8 +30,8 @@ if_chain! {
3030
}
3131
}
3232
if_chain! {
33-
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)
34-
if let PatKind::Lit(ref lit_expr) = let_pat.kind
33+
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);
34+
if let PatKind::Lit(ref lit_expr) = let_pat.kind;
3535
if let ExprKind::Lit(ref lit) = lit_expr.kind;
3636
if let LitKind::Bool(true) = lit.node;
3737
if let ExprKind::Path(ref qpath) = let_expr.kind;

tests/ui/author/loop.stdout

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
if_chain! {
22
if let ExprKind::DropTemps(ref expr) = expr.kind;
3-
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr)
3+
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr);
44
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = pat.kind;
55
if name.as_str() == "y";
66
if let ExprKind::Struct(ref qpath, ref fields, None) = arg.kind;
77
if matches!(qpath, QPath::LangItem(LangItem::Range, _));
88
if fields.len() == 2;
9-
if fields[0].ident.name.as_str() == "start"
10-
if let ExprKind::Lit(ref lit) = fields[0].kind;
9+
if fields[0].ident.name.as_str() == "start";
10+
if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
1111
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
12-
if fields[1].ident.name.as_str() == "end"
13-
if let ExprKind::Lit(ref lit1) = fields[1].kind;
12+
if fields[1].ident.name.as_str() == "end";
13+
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
1414
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
1515
if let ExprKind::Block(ref block, ref label) = body.kind;
1616
if block.stmts.len() == 1;
@@ -27,20 +27,20 @@ if_chain! {
2727
}
2828
if_chain! {
2929
if let ExprKind::DropTemps(ref expr) = expr.kind;
30-
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr)
30+
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr);
3131
if let PatKind::Wild = pat.kind;
3232
if let ExprKind::Struct(ref qpath, ref fields, None) = arg.kind;
3333
if matches!(qpath, QPath::LangItem(LangItem::Range, _));
3434
if fields.len() == 2;
35-
if fields[0].ident.name.as_str() == "start"
36-
if let ExprKind::Lit(ref lit) = fields[0].kind;
35+
if fields[0].ident.name.as_str() == "start";
36+
if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
3737
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
38-
if fields[1].ident.name.as_str() == "end"
39-
if let ExprKind::Lit(ref lit1) = fields[1].kind;
38+
if fields[1].ident.name.as_str() == "end";
39+
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
4040
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
4141
if let ExprKind::Block(ref block, ref label) = body.kind;
4242
if block.stmts.len() == 1;
43-
if let StmtKind::Semi(ref e, _) = block.stmts[0].kind
43+
if let StmtKind::Semi(ref e) = block.stmts[0].kind;
4444
if let ExprKind::Break(ref destination, None) = e.kind;
4545
if block.expr.is_none();
4646
then {
@@ -49,61 +49,61 @@ if_chain! {
4949
}
5050
if_chain! {
5151
if let ExprKind::DropTemps(ref expr) = expr.kind;
52-
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr)
52+
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, ..}) = higher::ForLoop::hir(expr);
5353
if let PatKind::Wild = pat.kind;
5454
if let ExprKind::Struct(ref qpath, ref fields, None) = arg.kind;
5555
if matches!(qpath, QPath::LangItem(LangItem::Range, _));
5656
if fields.len() == 2;
57-
if fields[0].ident.name.as_str() == "start"
58-
if let ExprKind::Lit(ref lit) = fields[0].kind;
57+
if fields[0].ident.name.as_str() == "start";
58+
if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
5959
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
60-
if fields[1].ident.name.as_str() == "end"
61-
if let ExprKind::Lit(ref lit1) = fields[1].kind;
60+
if fields[1].ident.name.as_str() == "end";
61+
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
6262
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
6363
if let ExprKind::Block(ref block, ref label) = body.kind;
6464
if block.stmts.len() == 1;
65-
if let StmtKind::Semi(ref e, _) = block.stmts[0].kind
65+
if let StmtKind::Semi(ref e) = block.stmts[0].kind;
6666
if let ExprKind::Break(ref destination, None) = e.kind;
67-
if let Some(ref label1) = destination.label
67+
if let Some(ref label1) = destination.label;
6868
if label_name.ident.name.as_str() == "'label";
6969
if block.expr.is_none();
7070
then {
7171
// report your lint here
7272
}
7373
}
7474
if_chain! {
75-
if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr)
75+
if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr);
7676
if let ExprKind::Path(ref qpath) = condition.kind;
7777
if match_qpath(qpath, &["a"]);
7878
if let ExprKind::Block(ref block, ref label) = body.kind;
7979
if block.stmts.len() == 1;
80-
if let StmtKind::Semi(ref e, _) = block.stmts[0].kind
80+
if let StmtKind::Semi(ref e) = block.stmts[0].kind;
8181
if let ExprKind::Break(ref destination, None) = e.kind;
8282
if block.expr.is_none();
8383
then {
8484
// report your lint here
8585
}
8686
}
8787
if_chain! {
88-
if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr)
89-
if let PatKind::Lit(ref lit_expr) = let_pat.kind
88+
if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr);
89+
if let PatKind::Lit(ref lit_expr) = let_pat.kind;
9090
if let ExprKind::Lit(ref lit) = lit_expr.kind;
9191
if let LitKind::Bool(true) = lit.node;
9292
if let ExprKind::Path(ref qpath) = let_expr.kind;
9393
if match_qpath(qpath, &["a"]);
9494
if let ExprKind::Block(ref block, ref label) = if_then.kind;
9595
if block.stmts.len() == 1;
96-
if let StmtKind::Semi(ref e, _) = block.stmts[0].kind
96+
if let StmtKind::Semi(ref e) = block.stmts[0].kind;
9797
if let ExprKind::Break(ref destination, None) = e.kind;
9898
if block.expr.is_none();
9999
then {
100100
// report your lint here
101101
}
102102
}
103103
if_chain! {
104-
if let ExprKind::Loop(ref body, ref label, LoopSource::Loop) = expr.kind;
104+
if let ExprKind::Loop(ref body, ref label, LoopSource::Loop, _) = expr.kind;
105105
if body.stmts.len() == 1;
106-
if let StmtKind::Semi(ref e, _) = body.stmts[0].kind
106+
if let StmtKind::Semi(ref e) = body.stmts[0].kind;
107107
if let ExprKind::Break(ref destination, None) = e.kind;
108108
if body.expr.is_none();
109109
then {

tests/ui/author/matches.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if_chain! {
77
if arms.len() == 3;
88
if let ExprKind::Lit(ref lit1) = arms[0].body.kind;
99
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node;
10-
if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind
10+
if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind;
1111
if let ExprKind::Lit(ref lit2) = lit_expr.kind;
1212
if let LitKind::Int(16, LitIntType::Unsuffixed) = lit2.node;
1313
if let ExprKind::Block(ref block, ref label) = arms[1].body.kind;
@@ -21,7 +21,7 @@ if_chain! {
2121
if let Some(trailing_expr) = &block.expr;
2222
if let ExprKind::Path(ref qpath) = trailing_expr.kind;
2323
if match_qpath(qpath, &["x"]);
24-
if let PatKind::Lit(ref lit_expr1) = arms[1].pat.kind
24+
if let PatKind::Lit(ref lit_expr1) = arms[1].pat.kind;
2525
if let ExprKind::Lit(ref lit4) = lit_expr1.kind;
2626
if let LitKind::Int(17, LitIntType::Unsuffixed) = lit4.node;
2727
if let ExprKind::Lit(ref lit5) = arms[2].body.kind;

tests/ui/author/struct.stdout

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ if_chain! {
22
if let ExprKind::Struct(ref qpath, ref fields, None) = expr.kind;
33
if match_qpath(qpath, &["Test"]);
44
if fields.len() == 1;
5-
if fields[0].ident.name.as_str() == "field"
6-
if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(fields[0])
5+
if fields[0].ident.name.as_str() == "field";
6+
if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(fields[0].expr);
77
if let ExprKind::Lit(ref lit) = cond.kind;
88
if let LitKind::Bool(true) = lit.node;
99
if let ExprKind::Block(ref block, ref label) = then.kind;
@@ -24,8 +24,8 @@ if_chain! {
2424
if let PatKind::Struct(ref qpath, ref fields, false) = arm.kind;
2525
if match_qpath(qpath, &["Test"]);
2626
if fields.len() == 1;
27-
if fields[0].ident.name.as_str() == "field"
28-
if let PatKind::Lit(ref lit_expr) = fields[0].kind
27+
if fields[0].ident.name.as_str() == "field";
28+
if let PatKind::Lit(ref lit_expr) = fields[0].kind;
2929
if let ExprKind::Lit(ref lit) = lit_expr.kind;
3030
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
3131
if let ExprKind::Block(ref block, ref label) = lit_expr.kind;
@@ -39,7 +39,7 @@ if_chain! {
3939
if let PatKind::TupleStruct(ref qpath, ref fields, None) = arm.kind;
4040
if match_qpath(qpath, &["TestTuple"]);
4141
if fields.len() == 1;
42-
if let PatKind::Lit(ref lit_expr) = fields[0].kind
42+
if let PatKind::Lit(ref lit_expr) = fields[0].kind;
4343
if let ExprKind::Lit(ref lit) = lit_expr.kind;
4444
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
4545
if let ExprKind::Block(ref block, ref label) = lit_expr.kind;

0 commit comments

Comments
 (0)