Skip to content

Commit f9a5348

Browse files
committed
Update clippy
1 parent 4a6d6f4 commit f9a5348

File tree

12 files changed

+89
-32
lines changed

12 files changed

+89
-32
lines changed

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ semver = "0.9.0"
2727
serde = { version = "1.0", features = ["derive"] }
2828
toml = "0.5"
2929
unicode-normalization = "0.1"
30-
pulldown-cmark = "0.5.0"
30+
pulldown-cmark = "0.5.2"
3131
url = "1.7.0"
3232
if_chain = "1.0.0"
3333
smallvec = { version = "0.6.5", features = ["union"] }

clippy_lints/src/utils/author.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::utils::{get_attr, higher};
55
use rustc::hir;
66
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
7-
use rustc::hir::{BindingAnnotation, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind};
7+
use rustc::hir::{BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind};
88
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
99
use rustc::session::Session;
1010
use rustc::{declare_lint_pass, declare_tool_lint};
@@ -511,6 +511,17 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
511511
}
512512
}
513513

514+
fn visit_block(&mut self, block: &Block) {
515+
let trailing_pat = self.next("trailing_expr");
516+
println!(" if let Some({}) = &{}.expr;", trailing_pat, self.current);
517+
println!(" if {}.stmts.len() == {};", self.current, block.stmts.len());
518+
let current = self.current.clone();
519+
for (i, stmt) in block.stmts.iter().enumerate() {
520+
self.current = format!("{}.stmts[{}]", current, i);
521+
self.visit_stmt(stmt);
522+
}
523+
}
524+
514525
#[allow(clippy::too_many_lines)]
515526
fn visit_pat(&mut self, pat: &Pat) {
516527
print!(" if let PatKind::");

tests/ui/author/blocks.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(stmt_expr_attributes)]
2+
3+
#[rustfmt::skip]
4+
fn main() {
5+
#[clippy::author]
6+
{
7+
;;;;
8+
}
9+
}
10+
11+
#[clippy::author]
12+
fn foo() {
13+
let x = 42i32;
14+
-x;
15+
}

tests/ui/author/blocks.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: statement with no effect
2+
--> $DIR/blocks.rs:14:5
3+
|
4+
LL | -x;
5+
| ^^^
6+
|
7+
= note: `-D clippy::no-effect` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

tests/ui/author/blocks.stdout

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
if_chain! {
2+
if let ExprKind::Block(ref block) = expr.node;
3+
if let Some(trailing_expr) = &block.expr;
4+
if block.stmts.len() == 0;
5+
then {
6+
// report your lint here
7+
}
8+
}
9+
if_chain! {
10+
then {
11+
// report your lint here
12+
}
13+
}

tests/ui/author/for_loop.stdout

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ if_chain! {
1111
// unimplemented: field checks
1212
if arms.len() == 1;
1313
if let ExprKind::Loop(ref body, ref label, LoopSource::ForLoop) = arms[0].body.node;
14-
if let StmtKind::Local(ref local) = body.node;
14+
if let Some(trailing_expr) = &body.expr;
15+
if body.stmts.len() == 4;
16+
if let StmtKind::Local(ref local) = body.stmts[0].node;
1517
if let PatKind::Binding(BindingAnnotation::Mutable, _, name, None) = local.pat.node;
1618
if name.node.as_str() == "__next";
17-
if let StmtKind::Expr(ref e, _) = local.pat.node
19+
if let StmtKind::Expr(ref e, _) = body.stmts[1].node
1820
if let ExprKind::Match(ref expr2, ref arms1, MatchSource::ForLoopDesugar) = e.node;
1921
if let ExprKind::Call(ref func1, ref args1) = expr2.node;
2022
if let ExprKind::Path(ref path2) = func1.node;
@@ -38,15 +40,17 @@ if_chain! {
3840
if arms1[1].pats.len() == 1;
3941
if let PatKind::Path(ref path7) = arms1[1].pats[0].node;
4042
if match_qpath(path7, &["{{root}}", "std", "option", "Option", "None"]);
41-
if let StmtKind::Local(ref local1) = path7.node;
43+
if let StmtKind::Local(ref local1) = body.stmts[2].node;
4244
if let Some(ref init) = local1.init;
4345
if let ExprKind::Path(ref path8) = init.node;
4446
if match_qpath(path8, &["__next"]);
4547
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local1.pat.node;
4648
if name1.node.as_str() == "y";
47-
if let StmtKind::Expr(ref e1, _) = local1.pat.node
49+
if let StmtKind::Expr(ref e1, _) = body.stmts[3].node
4850
if let ExprKind::Block(ref block) = e1.node;
49-
if let StmtKind::Local(ref local2) = block.node;
51+
if let Some(trailing_expr1) = &block.expr;
52+
if block.stmts.len() == 1;
53+
if let StmtKind::Local(ref local2) = block.stmts[0].node;
5054
if let Some(ref init1) = local2.init;
5155
if let ExprKind::Path(ref path9) = init1.node;
5256
if match_qpath(path9, &["y"]);

tests/ui/author/if.stdout

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ if_chain! {
33
if let Some(ref init) = local.init;
44
if let Some((ref cond, ref then, Some(else_))) = higher::if_block(&init);
55
if let ExprKind::Block(ref block) = else_.node;
6-
if let StmtKind::Semi(ref e, _) = block.node
6+
if let Some(trailing_expr) = &block.expr;
7+
if block.stmts.len() == 1;
8+
if let StmtKind::Semi(ref e, _) = block.stmts[0].node
79
if let ExprKind::Binary(ref op, ref left, ref right) = e.node;
810
if BinOpKind::Eq == op.node;
911
if let ExprKind::Lit(ref lit) = left.node;
@@ -13,7 +15,9 @@ if_chain! {
1315
if let ExprKind::Lit(ref lit2) = cond.node;
1416
if let LitKind::Bool(true) = lit2.node;
1517
if let ExprKind::Block(ref block1) = then.node;
16-
if let StmtKind::Semi(ref e1, _) = block1.node
18+
if let Some(trailing_expr1) = &block1.expr;
19+
if block1.stmts.len() == 1;
20+
if let StmtKind::Semi(ref e1, _) = block1.stmts[0].node
1721
if let ExprKind::Binary(ref op1, ref left1, ref right1) = e1.node;
1822
if BinOpKind::Eq == op1.node;
1923
if let ExprKind::Lit(ref lit3) = left1.node;

tests/ui/match_bool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ fn match_bool() {
4444

4545
// Not linted
4646
match option {
47-
1...10 => 1,
48-
11...20 => 2,
47+
1..=10 => 1,
48+
11..=20 => 2,
4949
_ => 3,
5050
};
5151
}

tests/ui/match_overlapping_arm.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ fn overlapping() {
88
const FOO: u64 = 2;
99

1010
match 42 {
11-
0...10 => println!("0 ... 10"),
12-
0...11 => println!("0 ... 11"),
11+
0..=10 => println!("0 ... 10"),
12+
0..=11 => println!("0 ... 11"),
1313
_ => (),
1414
}
1515

1616
match 42 {
17-
0...5 => println!("0 ... 5"),
18-
6...7 => println!("6 ... 7"),
19-
FOO...11 => println!("0 ... 11"),
17+
0..=5 => println!("0 ... 5"),
18+
6..=7 => println!("6 ... 7"),
19+
FOO..=11 => println!("0 ... 11"),
2020
_ => (),
2121
}
2222

2323
match 42 {
2424
2 => println!("2"),
25-
0...5 => println!("0 ... 5"),
25+
0..=5 => println!("0 ... 5"),
2626
_ => (),
2727
}
2828

2929
match 42 {
3030
2 => println!("2"),
31-
0...2 => println!("0 ... 2"),
31+
0..=2 => println!("0 ... 2"),
3232
_ => (),
3333
}
3434

3535
match 42 {
36-
0...10 => println!("0 ... 10"),
37-
11...50 => println!("11 ... 50"),
36+
0..=10 => println!("0 ... 10"),
37+
11..=50 => println!("11 ... 50"),
3838
_ => (),
3939
}
4040

@@ -52,7 +52,7 @@ fn overlapping() {
5252

5353
match 42 {
5454
0..11 => println!("0 .. 11"),
55-
0...11 => println!("0 ... 11"),
55+
0..=11 => println!("0 ... 11"),
5656
_ => (),
5757
}
5858

tests/ui/match_overlapping_arm.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
error: some ranges overlap
22
--> $DIR/match_overlapping_arm.rs:11:9
33
|
4-
LL | 0...10 => println!("0 ... 10"),
4+
LL | 0..=10 => println!("0 ... 10"),
55
| ^^^^^^
66
|
77
= note: `-D clippy::match-overlapping-arm` implied by `-D warnings`
88
note: overlaps with this
99
--> $DIR/match_overlapping_arm.rs:12:9
1010
|
11-
LL | 0...11 => println!("0 ... 11"),
11+
LL | 0..=11 => println!("0 ... 11"),
1212
| ^^^^^^
1313

1414
error: some ranges overlap
1515
--> $DIR/match_overlapping_arm.rs:17:9
1616
|
17-
LL | 0...5 => println!("0 ... 5"),
17+
LL | 0..=5 => println!("0 ... 5"),
1818
| ^^^^^
1919
|
2020
note: overlaps with this
2121
--> $DIR/match_overlapping_arm.rs:19:9
2222
|
23-
LL | FOO...11 => println!("0 ... 11"),
23+
LL | FOO..=11 => println!("0 ... 11"),
2424
| ^^^^^^^^
2525

2626
error: some ranges overlap
2727
--> $DIR/match_overlapping_arm.rs:25:9
2828
|
29-
LL | 0...5 => println!("0 ... 5"),
29+
LL | 0..=5 => println!("0 ... 5"),
3030
| ^^^^^
3131
|
3232
note: overlaps with this
@@ -38,7 +38,7 @@ LL | 2 => println!("2"),
3838
error: some ranges overlap
3939
--> $DIR/match_overlapping_arm.rs:31:9
4040
|
41-
LL | 0...2 => println!("0 ... 2"),
41+
LL | 0..=2 => println!("0 ... 2"),
4242
| ^^^^^
4343
|
4444
note: overlaps with this
@@ -56,7 +56,7 @@ LL | 0..11 => println!("0 .. 11"),
5656
note: overlaps with this
5757
--> $DIR/match_overlapping_arm.rs:55:9
5858
|
59-
LL | 0...11 => println!("0 ... 11"),
59+
LL | 0..=11 => println!("0 ... 11"),
6060
| ^^^^^^
6161

6262
error: aborting due to 5 previous errors

0 commit comments

Comments
 (0)