Fix author lint
This commit is contained in:
parent
4bbd10a585
commit
8d8ba14371
@ -38,7 +38,7 @@
|
||||
/// 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
|
||||
/// }
|
||||
@ -401,7 +401,7 @@ fn visit_expr(&mut self, expr: &Expr) {
|
||||
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);
|
||||
},
|
||||
@ -532,7 +532,7 @@ fn visit_pat(&mut self, pat: &Pat) {
|
||||
} 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");
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![allow(redundant_semicolon)]
|
||||
#![allow(redundant_semicolon, clippy::no_effect)]
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
|
@ -1,16 +0,0 @@
|
||||
error: statement with no effect
|
||||
--> $DIR/blocks.rs:8:9
|
||||
|
|
||||
LL | ;;;;
|
||||
| ^^^^
|
||||
|
|
||||
= note: `-D clippy::no-effect` implied by `-D warnings`
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/blocks.rs:15:5
|
||||
|
|
||||
LL | -x;
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
@ -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
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(tool_attributes)]
|
||||
#![allow(clippy::let_and_return)]
|
||||
|
||||
fn main() {
|
||||
#[clippy::author]
|
||||
|
@ -1,17 +0,0 @@
|
||||
error: returning the result of a let binding from a block
|
||||
--> $DIR/matches.rs:9:13
|
||||
|
|
||||
LL | let x = 3;
|
||||
| ---------- unnecessary let binding
|
||||
LL | x
|
||||
| ^
|
||||
|
|
||||
= note: `-D clippy::let-and-return` implied by `-D warnings`
|
||||
help: return the expression directly
|
||||
|
|
||||
LL |
|
||||
LL | 3
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
33
tests/ui/author/matches.stdout
Normal file
33
tests/ui/author/matches.stdout
Normal file
@ -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
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
if_chain! {
|
||||
if let StmtKind::Decl(ref decl, _) = stmt.kind
|
||||
if let DeclKind::Local(ref local) = decl.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.kind;
|
||||
if arms.len() == 3;
|
||||
if let ExprKind::Lit(ref lit1) = arms[0].body.kind;
|
||||
if let LitKind::Int(5, _) = lit1.kind;
|
||||
if arms[0].pats.len() == 1;
|
||||
if let PatKind::Lit(ref lit_expr) = arms[0].pats[0].kind
|
||||
if let ExprKind::Lit(ref lit2) = lit_expr.kind;
|
||||
if let LitKind::Int(16, _) = lit2.kind;
|
||||
if let ExprKind::Block(ref block) = arms[1].body.kind;
|
||||
if let StmtKind::Decl(ref decl1, _) = block.kind
|
||||
if let DeclKind::Local(ref local1) = decl1.kind;
|
||||
if let Some(ref init1) = local1.init
|
||||
if let ExprKind::Lit(ref lit3) = init1.kind;
|
||||
if let LitKind::Int(3, _) = lit3.kind;
|
||||
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local1.pat.kind;
|
||||
if name.kind.as_str() == "x";
|
||||
if let ExprKind::Path(ref path) = local1.pat.kind;
|
||||
if match_qpath(path, &["x"]);
|
||||
if arms[1].pats.len() == 1;
|
||||
if let PatKind::Lit(ref lit_expr1) = arms[1].pats[0].kind
|
||||
if let ExprKind::Lit(ref lit4) = lit_expr1.kind;
|
||||
if let LitKind::Int(17, _) = lit4.kind;
|
||||
if let ExprKind::Lit(ref lit5) = arms[2].body.kind;
|
||||
if let LitKind::Int(1, _) = lit5.kind;
|
||||
if arms[2].pats.len() == 1;
|
||||
if let PatKind::Wild = arms[2].pats[0].kind;
|
||||
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local.pat.kind;
|
||||
if name1.kind.as_str() == "a";
|
||||
then {
|
||||
// report your lint here
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user