-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Extend author lint #7894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Extend author lint #7894
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.