forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#7894 - Serial-ATA:extend-author-lint, r=camst…
…effen Extend author lint changelog: none * Print float and int suffixes * Print labels * Struct field checks * Repeat length expression check * Destructure method calls * Destructure closures
- Loading branch information
Showing
16 changed files
with
827 additions
and
230 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
// edition:2018 | ||
|
||
#![allow(redundant_semicolons, clippy::no_effect)] | ||
#![feature(stmt_expr_attributes)] | ||
#![feature(async_closure)] | ||
|
||
#[rustfmt::skip] | ||
fn main() { | ||
#[clippy::author] | ||
{ | ||
let x = 42i32; | ||
let _t = 1f32; | ||
|
||
-x; | ||
}; | ||
#[clippy::author] | ||
{ | ||
let expr = String::new(); | ||
drop(expr) | ||
}; | ||
|
||
#[clippy::author] | ||
async move || {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,11 @@ fn main() { | |
} else { | ||
2 == 2; | ||
}; | ||
|
||
let a = true; | ||
|
||
#[clippy::author] | ||
if let true = a { | ||
} else { | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
if_chain! { | ||
if let StmtKind::Local(ref local) = stmt.kind; | ||
if let Some(ref init) = local.init; | ||
if let ExprKind::If(ref cond, ref then, Some(ref else_)) = init.kind; | ||
if let ExprKind::Block(ref block) = else_.kind; | ||
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 ExprKind::Binary(ref op, ref left, ref right) = e.kind; | ||
if BinOpKind::Eq == op.node; | ||
if let ExprKind::Lit(ref lit) = left.kind; | ||
if let LitKind::Int(2, _) = lit.node; | ||
if let ExprKind::Lit(ref lit1) = right.kind; | ||
if let LitKind::Int(2, _) = lit1.node; | ||
if let ExprKind::Lit(ref lit1) = left.kind; | ||
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node; | ||
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::DropTemps(ref expr) = cond.kind; | ||
if let ExprKind::Lit(ref lit2) = expr.kind; | ||
if let LitKind::Bool(true) = lit2.node; | ||
if let ExprKind::Block(ref block1) = then.kind; | ||
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 ExprKind::Binary(ref op1, ref left1, ref right1) = e1.kind; | ||
if BinOpKind::Eq == op1.node; | ||
if let ExprKind::Lit(ref lit3) = left1.kind; | ||
if let LitKind::Int(1, _) = lit3.node; | ||
if let LitKind::Int(2, LitIntType::Unsuffixed) = lit3.node; | ||
if let ExprKind::Lit(ref lit4) = right1.kind; | ||
if let LitKind::Int(1, _) = lit4.node; | ||
if let LitKind::Int(2, LitIntType::Unsuffixed) = lit4.node; | ||
if block1.expr.is_none(); | ||
if let PatKind::Wild = local.pat.kind; | ||
then { | ||
// report your lint here | ||
} | ||
} | ||
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 ExprKind::Lit(ref lit) = lit_expr.kind; | ||
if let LitKind::Bool(true) = lit.node; | ||
if let ExprKind::Path(ref path) = let_expr.kind; | ||
if match_qpath(path, &["a"]); | ||
if let ExprKind::Block(ref block, ref label) = if_then.kind; | ||
if block.stmts.len() == 0; | ||
if block.expr.is_none(); | ||
if let ExprKind::Block(ref block1, ref label1) = else_expr.kind; | ||
if block1.stmts.len() == 0; | ||
if block1.expr.is_none(); | ||
then { | ||
// report your lint here | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![feature(stmt_expr_attributes)] | ||
#![allow(clippy::never_loop, clippy::while_immutable_condition)] | ||
|
||
fn main() { | ||
#[clippy::author] | ||
for y in 0..10 { | ||
let z = y; | ||
} | ||
|
||
#[clippy::author] | ||
for _ in 0..10 { | ||
break; | ||
} | ||
|
||
#[clippy::author] | ||
'label: for _ in 0..10 { | ||
break 'label; | ||
} | ||
|
||
let a = true; | ||
|
||
#[clippy::author] | ||
while a { | ||
break; | ||
} | ||
|
||
#[clippy::author] | ||
while let true = a { | ||
break; | ||
} | ||
|
||
#[clippy::author] | ||
loop { | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
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 PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = pat.kind; | ||
if name.as_str() == "y"; | ||
if let ExprKind::Struct(ref path, ref fields, None) = arg.kind; | ||
if matches!(path, 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 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 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::Local(ref local) = block.stmts[0].kind; | ||
if let Some(ref init) = local.init; | ||
if let ExprKind::Path(ref path1) = init.kind; | ||
if match_qpath(path1, &["y"]); | ||
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local.pat.kind; | ||
if name1.as_str() == "z"; | ||
if block.expr.is_none(); | ||
then { | ||
// report your lint here | ||
} | ||
} | ||
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 PatKind::Wild = pat.kind; | ||
if let ExprKind::Struct(ref path, ref fields, None) = arg.kind; | ||
if matches!(path, 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 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 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 ExprKind::Break(ref destination, None) = e.kind; | ||
if block.expr.is_none(); | ||
then { | ||
// report your lint here | ||
} | ||
} | ||
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 PatKind::Wild = pat.kind; | ||
if let ExprKind::Struct(ref path, ref fields, None) = arg.kind; | ||
if matches!(path, 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 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 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 ExprKind::Break(ref destination, None) = e.kind; | ||
if let Some(ref label1) = destination.label | ||
if label_name.ident.name.as_str() == "'label"; | ||
if block.expr.is_none(); | ||
then { | ||
// report your lint here | ||
} | ||
} | ||
if_chain! { | ||
if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr) | ||
if let ExprKind::Path(ref path) = condition.kind; | ||
if match_qpath(path, &["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 ExprKind::Break(ref destination, None) = e.kind; | ||
if block.expr.is_none(); | ||
then { | ||
// report your lint here | ||
} | ||
} | ||
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 ExprKind::Lit(ref lit) = lit_expr.kind; | ||
if let LitKind::Bool(true) = lit.node; | ||
if let ExprKind::Path(ref path) = let_expr.kind; | ||
if match_qpath(path, &["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 ExprKind::Break(ref destination, None) = e.kind; | ||
if block.expr.is_none(); | ||
then { | ||
// report your lint here | ||
} | ||
} | ||
if_chain! { | ||
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 ExprKind::Break(ref destination, None) = e.kind; | ||
if body.expr.is_none(); | ||
then { | ||
// report your lint here | ||
} | ||
} |
Oops, something went wrong.