Skip to content

Commit

Permalink
Fix author lint
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed Sep 27, 2019
1 parent 4bbd10a commit 8d8ba14
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 81 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare_clippy_lint! {
/// if let ExprKind::Binary(BinOp::Eq, ref left, ref right) = cond.kind,
/// if let ExprKind::Path(ref path) = left.kind,
/// if let ExprKind::Lit(ref lit) = right.kind,
/// if let LitKind::Int(42, _) = lit.kind,
/// if let LitKind::Int(42, _) = lit.node,
/// then {
/// // report your lint here
/// }
Expand Down Expand Up @@ -401,7 +401,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
let obj_pat = self.next("object");
let field_name_pat = self.next("field_name");
println!("Field(ref {}, ref {}) = {};", obj_pat, field_name_pat, current);
println!(" if {}.kind.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);
},
Expand Down Expand Up @@ -532,7 +532,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
} else {
println!("Binding({}, _, {}, None) = {};", anno_pat, name_pat, current);
}
println!(" if {}.kind.as_str() == \"{}\";", name_pat, ident.as_str());
println!(" if {}.as_str() == \"{}\";", name_pat, ident.as_str());
},
PatKind::Struct(ref path, ref fields, ignore) => {
let path_pat = self.next("path");
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/author.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if_chain! {
if let ExprKind::Lit(ref lit) = expr.kind;
if let LitKind::Int(69, _) = lit.node;
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind;
if name.kind.as_str() == "x";
if name.as_str() == "x";
then {
// report your lint here
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/author/blocks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(stmt_expr_attributes)]
#![allow(redundant_semicolon)]
#![allow(redundant_semicolon, clippy::no_effect)]

#[rustfmt::skip]
fn main() {
Expand Down
16 changes: 0 additions & 16 deletions tests/ui/author/blocks.stderr

This file was deleted.

8 changes: 4 additions & 4 deletions tests/ui/author/for_loop.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if_chain! {
if body.stmts.len() == 4;
if let StmtKind::Local(ref local) = body.stmts[0].kind;
if let PatKind::Binding(BindingAnnotation::Mutable, _, name, None) = local.pat.kind;
if name.kind.as_str() == "__next";
if name.as_str() == "__next";
if let StmtKind::Expr(ref e, _) = body.stmts[1].kind
if let ExprKind::Match(ref expr2, ref arms1, MatchSource::ForLoopDesugar) = e.kind;
if let ExprKind::Call(ref func1, ref args1) = expr2.kind;
Expand Down Expand Up @@ -43,7 +43,7 @@ if_chain! {
if let ExprKind::Path(ref path8) = init.kind;
if match_qpath(path8, &["__next"]);
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local1.pat.kind;
if name1.kind.as_str() == "y";
if name1.as_str() == "y";
if let StmtKind::Expr(ref e1, _) = body.stmts[3].kind
if let ExprKind::Block(ref block) = e1.kind;
if let Some(trailing_expr1) = &block.expr;
Expand All @@ -53,9 +53,9 @@ if_chain! {
if let ExprKind::Path(ref path9) = init1.kind;
if match_qpath(path9, &["y"]);
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name2, None) = local2.pat.kind;
if name2.kind.as_str() == "z";
if name2.as_str() == "z";
if let PatKind::Binding(BindingAnnotation::Mutable, _, name3, None) = arms[0].pat.kind;
if name3.kind.as_str() == "iter";
if name3.as_str() == "iter";
then {
// report your lint here
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/author/matches.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(tool_attributes)]
#![allow(clippy::let_and_return)]

fn main() {
#[clippy::author]
Expand Down
17 changes: 0 additions & 17 deletions tests/ui/author/matches.stderr

This file was deleted.

33 changes: 33 additions & 0 deletions tests/ui/author/matches.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 LitKind::Int(42, _) = lit.node;
if arms.len() == 3;
if let ExprKind::Lit(ref lit1) = arms[0].body.kind;
if let LitKind::Int(5, _) = 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, _) = lit2.node;
if let ExprKind::Block(ref block) = arms[1].body.kind;
if let Some(trailing_expr) = &block.expr;
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, _) = lit3.node;
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local1.pat.kind;
if name.as_str() == "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, _) = lit4.node;
if let ExprKind::Lit(ref lit5) = arms[2].body.kind;
if let LitKind::Int(1, _) = 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 {
// report your lint here
}
}
38 changes: 0 additions & 38 deletions tests/ui/author/matches.stout

This file was deleted.

0 comments on commit 8d8ba14

Please sign in to comment.