Skip to content

Commit 6430fe4

Browse files
committed
Extend author lint
1 parent 00821ca commit 6430fe4

File tree

17 files changed

+828
-231
lines changed

17 files changed

+828
-231
lines changed

clippy_lints/src/utils/author.rs

Lines changed: 480 additions & 131 deletions
Large diffs are not rendered by default.

clippy_utils/src/higher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This module contains functions that retrieves specifiec elements.
1+
//! This module contains functions that retrieves specific elements.
22
33
#![deny(clippy::missing_docs_in_private_items)]
44

tests/ui/author.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if_chain! {
55
if let TyKind::Path(ref qp) = cast_ty.kind;
66
if match_qpath(qp, &["char"]);
77
if let ExprKind::Lit(ref lit) = expr.kind;
8-
if let LitKind::Int(69, _) = lit.node;
8+
if let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node;
99
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind;
1010
if name.as_str() == "x";
1111
then {

tests/ui/author/blocks.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1+
// edition:2018
2+
13
#![allow(redundant_semicolons, clippy::no_effect)]
4+
#![feature(stmt_expr_attributes)]
5+
#![feature(async_closure)]
26

37
#[rustfmt::skip]
48
fn main() {
59
#[clippy::author]
610
{
711
let x = 42i32;
12+
let _t = 1f32;
13+
814
-x;
915
};
1016
#[clippy::author]
1117
{
1218
let expr = String::new();
1319
drop(expr)
1420
};
21+
22+
#[clippy::author]
23+
async move || {};
1524
}

tests/ui/author/blocks.stdout

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
if_chain! {
2-
if let ExprKind::Block(ref block) = expr.kind;
3-
if block.stmts.len() == 2;
2+
if let ExprKind::Block(ref block, ref label) = expr.kind;
3+
if block.stmts.len() == 3;
44
if let StmtKind::Local(ref local) = block.stmts[0].kind;
55
if let Some(ref init) = local.init;
66
if let ExprKind::Lit(ref lit) = init.kind;
7-
if let LitKind::Int(42, _) = lit.node;
7+
if let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node;
88
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind;
99
if name.as_str() == "x";
10-
if let StmtKind::Semi(ref e, _) = block.stmts[1].kind
10+
if let StmtKind::Local(ref local1) = block.stmts[1].kind;
11+
if let Some(ref init1) = local1.init;
12+
if let ExprKind::Lit(ref lit1) = init1.kind;
13+
if let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node;
14+
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local1.pat.kind;
15+
if name1.as_str() == "_t";
16+
if let StmtKind::Semi(ref e, _) = block.stmts[2].kind
1117
if let ExprKind::Unary(UnOp::Neg, ref inner) = e.kind;
1218
if let ExprKind::Path(ref path) = inner.kind;
1319
if match_qpath(path, &["x"]);
@@ -17,7 +23,7 @@ if_chain! {
1723
}
1824
}
1925
if_chain! {
20-
if let ExprKind::Block(ref block) = expr.kind;
26+
if let ExprKind::Block(ref block, ref label) = expr.kind;
2127
if block.stmts.len() == 1;
2228
if let StmtKind::Local(ref local) = block.stmts[0].kind;
2329
if let Some(ref init) = local.init;
@@ -38,3 +44,21 @@ if_chain! {
3844
// report your lint here
3945
}
4046
}
47+
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
50+
let body = cx.tcx.hir().body(body_id);
51+
if let ExprKind::Call(ref func, ref args) = body.value.kind;
52+
if let ExprKind::Path(ref path) = func.kind;
53+
if matches!(path, QPath::LangItem(LangItem::FromGenerator, _));
54+
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
57+
let body1 = cx.tcx.hir().body(body_id1);
58+
if let ExprKind::Block(ref block, ref label) = body1.value.kind;
59+
if block.stmts.len() == 0;
60+
if block.expr.is_none();
61+
then {
62+
// report your lint here
63+
}
64+
}

tests/ui/author/call.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ if_chain! {
66
if match_qpath(path, &["{{root}}", "std", "cmp", "min"]);
77
if args.len() == 2;
88
if let ExprKind::Lit(ref lit) = args[0].kind;
9-
if let LitKind::Int(3, _) = lit.node;
9+
if let LitKind::Int(3, LitIntType::Unsuffixed) = lit.node;
1010
if let ExprKind::Lit(ref lit1) = args[1].kind;
11-
if let LitKind::Int(4, _) = lit1.node;
11+
if let LitKind::Int(4, LitIntType::Unsuffixed) = lit1.node;
1212
if let PatKind::Wild = local.pat.kind;
1313
then {
1414
// report your lint here

tests/ui/author/for_loop.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/ui/author/for_loop.stdout

Lines changed: 0 additions & 64 deletions
This file was deleted.

tests/ui/author/if.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ fn main() {
77
} else {
88
2 == 2;
99
};
10+
11+
let a = true;
12+
13+
#[clippy::author]
14+
if let true = a {
15+
} else {
16+
};
1017
}

tests/ui/author/if.stdout

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
11
if_chain! {
22
if let StmtKind::Local(ref local) = stmt.kind;
33
if let Some(ref init) = local.init;
4-
if let ExprKind::If(ref cond, ref then, Some(ref else_)) = init.kind;
5-
if let ExprKind::Block(ref block) = else_.kind;
4+
if let Some(higher::If { cond: cond, then: then, r#else: else_expr}) = higher::If::hir(init)
5+
if let ExprKind::Lit(ref lit) = cond.kind;
6+
if let LitKind::Bool(true) = lit.node;
7+
if let ExprKind::Block(ref block, ref label) = then.kind;
68
if block.stmts.len() == 1;
79
if let StmtKind::Semi(ref e, _) = block.stmts[0].kind
810
if let ExprKind::Binary(ref op, ref left, ref right) = e.kind;
911
if BinOpKind::Eq == op.node;
10-
if let ExprKind::Lit(ref lit) = left.kind;
11-
if let LitKind::Int(2, _) = lit.node;
12-
if let ExprKind::Lit(ref lit1) = right.kind;
13-
if let LitKind::Int(2, _) = lit1.node;
12+
if let ExprKind::Lit(ref lit1) = left.kind;
13+
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node;
14+
if let ExprKind::Lit(ref lit2) = right.kind;
15+
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit2.node;
1416
if block.expr.is_none();
15-
if let ExprKind::DropTemps(ref expr) = cond.kind;
16-
if let ExprKind::Lit(ref lit2) = expr.kind;
17-
if let LitKind::Bool(true) = lit2.node;
18-
if let ExprKind::Block(ref block1) = then.kind;
17+
if let ExprKind::Block(ref block1, ref label1) = else_expr.kind;
1918
if block1.stmts.len() == 1;
2019
if let StmtKind::Semi(ref e1, _) = block1.stmts[0].kind
2120
if let ExprKind::Binary(ref op1, ref left1, ref right1) = e1.kind;
2221
if BinOpKind::Eq == op1.node;
2322
if let ExprKind::Lit(ref lit3) = left1.kind;
24-
if let LitKind::Int(1, _) = lit3.node;
23+
if let LitKind::Int(2, LitIntType::Unsuffixed) = lit3.node;
2524
if let ExprKind::Lit(ref lit4) = right1.kind;
26-
if let LitKind::Int(1, _) = lit4.node;
25+
if let LitKind::Int(2, LitIntType::Unsuffixed) = lit4.node;
2726
if block1.expr.is_none();
2827
if let PatKind::Wild = local.pat.kind;
2928
then {
3029
// report your lint here
3130
}
3231
}
32+
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
35+
if let ExprKind::Lit(ref lit) = lit_expr.kind;
36+
if let LitKind::Bool(true) = lit.node;
37+
if let ExprKind::Path(ref path) = let_expr.kind;
38+
if match_qpath(path, &["a"]);
39+
if let ExprKind::Block(ref block, ref label) = if_then.kind;
40+
if block.stmts.len() == 0;
41+
if block.expr.is_none();
42+
if let ExprKind::Block(ref block1, ref label1) = else_expr.kind;
43+
if block1.stmts.len() == 0;
44+
if block1.expr.is_none();
45+
then {
46+
// report your lint here
47+
}
48+
}

tests/ui/author/loop.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![feature(stmt_expr_attributes)]
2+
#![allow(clippy::never_loop, clippy::while_immutable_condition)]
3+
4+
fn main() {
5+
#[clippy::author]
6+
for y in 0..10 {
7+
let z = y;
8+
}
9+
10+
#[clippy::author]
11+
for _ in 0..10 {
12+
break;
13+
}
14+
15+
#[clippy::author]
16+
'label: for _ in 0..10 {
17+
break 'label;
18+
}
19+
20+
let a = true;
21+
22+
#[clippy::author]
23+
while a {
24+
break;
25+
}
26+
27+
#[clippy::author]
28+
while let true = a {
29+
break;
30+
}
31+
32+
#[clippy::author]
33+
loop {
34+
break;
35+
}
36+
}

0 commit comments

Comments
 (0)