Skip to content

Commit 3c4af49

Browse files
committed
Rustup to ea0dc92
1 parent b5b6945 commit 3c4af49

12 files changed

+86
-71
lines changed

clippy_lints/src/booleans.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc::hir::*;
33
use rustc::hir::intravisit::*;
44
use syntax::ast::{LitKind, DUMMY_NODE_ID};
55
use syntax::codemap::{DUMMY_SP, dummy_spanned};
6+
use syntax::util::ThinVec;
67
use utils::{span_lint_and_then, in_macro, snippet_opt, SpanlessEq};
78

89
/// **What it does:** This lint checks for boolean expressions that can be written more concisely
@@ -99,7 +100,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
99100
Expr {
100101
id: DUMMY_NODE_ID,
101102
span: DUMMY_SP,
102-
attrs: None,
103+
attrs: ThinVec::new(),
103104
node: ExprBinary(dummy_spanned(op), lhs.clone(), rhs.clone()),
104105
}
105106
};

clippy_lints/src/formatting.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,13 @@ impl EarlyLintPass for Formatting {
5959
fn check_block(&mut self, cx: &EarlyContext, block: &ast::Block) {
6060
for w in block.stmts.windows(2) {
6161
match (&w[0].node, &w[1].node) {
62-
(&ast::StmtKind::Expr(ref first, _), &ast::StmtKind::Expr(ref second, _)) |
63-
(&ast::StmtKind::Expr(ref first, _), &ast::StmtKind::Semi(ref second, _)) => {
62+
(&ast::StmtKind::Expr(ref first), &ast::StmtKind::Expr(ref second)) |
63+
(&ast::StmtKind::Expr(ref first), &ast::StmtKind::Semi(ref second)) => {
6464
check_consecutive_ifs(cx, first, second);
6565
}
6666
_ => (),
6767
}
6868
}
69-
70-
if let Some(ref expr) = block.expr {
71-
if let Some(ref stmt) = block.stmts.iter().last() {
72-
if let ast::StmtKind::Expr(ref first, _) = stmt.node {
73-
check_consecutive_ifs(cx, first, expr);
74-
}
75-
}
76-
}
7769
}
7870

7971
fn check_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr) {

clippy_lints/src/items_after_statements.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc::lint::*;
44
use syntax::ast::*;
5-
use utils::in_macro;
5+
use utils::{in_macro, span_lint};
66

77
/// **What it does:** This lints checks for items declared after some statement in a block
88
///
@@ -44,26 +44,23 @@ impl EarlyLintPass for ItemsAfterStatements {
4444
if in_macro(cx, item.span) {
4545
return;
4646
}
47-
let mut stmts = item.stmts.iter().map(|stmt| &stmt.node);
47+
4848
// skip initial items
49-
while let Some(&StmtKind::Decl(ref decl, _)) = stmts.next() {
50-
if let DeclKind::Local(_) = decl.node {
51-
break;
52-
}
53-
}
49+
let stmts = item.stmts.iter()
50+
.map(|stmt| &stmt.node)
51+
.skip_while(|s| matches!(**s, StmtKind::Item(..)));
52+
5453
// lint on all further items
5554
for stmt in stmts {
56-
if let StmtKind::Decl(ref decl, _) = *stmt {
57-
if let DeclKind::Item(ref it) = decl.node {
58-
if in_macro(cx, it.span) {
59-
return;
60-
}
61-
cx.struct_span_lint(ITEMS_AFTER_STATEMENTS,
62-
it.span,
63-
"adding items after statements is confusing, since items exist from the \
64-
start of the scope")
65-
.emit();
55+
if let StmtKind::Item(ref it) = *stmt {
56+
if in_macro(cx, it.span) {
57+
return;
6658
}
59+
span_lint(cx,
60+
ITEMS_AFTER_STATEMENTS,
61+
it.span,
62+
"adding items after statements is confusing, since items exist from the \
63+
start of the scope");
6764
}
6865
}
6966
}

clippy_lints/src/misc_early.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,14 @@ impl EarlyLintPass for MiscEarly {
171171
fn check_block(&mut self, cx: &EarlyContext, block: &Block) {
172172
for w in block.stmts.windows(2) {
173173
if_let_chain! {[
174-
let StmtKind::Decl(ref first, _) = w[0].node,
175-
let DeclKind::Local(ref local) = first.node,
174+
let StmtKind::Local(ref local) = w[0].node,
176175
let Option::Some(ref t) = local.init,
177-
let ExprKind::Closure(_,_,_,_) = t.node,
178-
let PatKind::Ident(_,sp_ident,_) = local.pat.node,
179-
let StmtKind::Semi(ref second,_) = w[1].node,
180-
let ExprKind::Assign(_,ref call) = second.node,
181-
let ExprKind::Call(ref closure,_) = call.node,
182-
let ExprKind::Path(_,ref path) = closure.node
176+
let ExprKind::Closure(_, _, _, _) = t.node,
177+
let PatKind::Ident(_, sp_ident, _) = local.pat.node,
178+
let StmtKind::Semi(ref second) = w[1].node,
179+
let ExprKind::Assign(_, ref call) = second.node,
180+
let ExprKind::Call(ref closure, _) = call.node,
181+
let ExprKind::Path(_, ref path) = closure.node
183182
], {
184183
if sp_ident.node == (&path.segments[0]).identifier {
185184
span_lint(cx, REDUNDANT_CLOSURE_CALL, second.span, "Closure called just once immediately after it was declared");

clippy_lints/src/non_expressive_names.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const WHITELIST: &'static [&'static [&'static str]] = &[
6868

6969
struct SimilarNamesNameVisitor<'a, 'b: 'a, 'c: 'b>(&'a mut SimilarNamesLocalVisitor<'b, 'c>);
7070

71-
impl<'v, 'a, 'b, 'c> Visitor<'v> for SimilarNamesNameVisitor<'a, 'b, 'c> {
72-
fn visit_pat(&mut self, pat: &'v Pat) {
71+
impl<'a, 'b, 'c> Visitor for SimilarNamesNameVisitor<'a, 'b, 'c> {
72+
fn visit_pat(&mut self, pat: &Pat) {
7373
match pat.node {
7474
PatKind::Ident(_, id, _) => self.check_name(id.span, id.node.name),
7575
PatKind::Struct(_, ref fields, _) => {
@@ -226,25 +226,25 @@ impl<'a, 'b> SimilarNamesLocalVisitor<'a, 'b> {
226226
}
227227
}
228228

229-
impl<'v, 'a, 'b> Visitor<'v> for SimilarNamesLocalVisitor<'a, 'b> {
230-
fn visit_local(&mut self, local: &'v Local) {
229+
impl<'a, 'b> Visitor for SimilarNamesLocalVisitor<'a, 'b> {
230+
fn visit_local(&mut self, local: &Local) {
231231
if let Some(ref init) = local.init {
232232
self.apply(|this| walk_expr(this, &**init));
233233
}
234234
// add the pattern after the expression because the bindings aren't available yet in the init expression
235235
SimilarNamesNameVisitor(self).visit_pat(&*local.pat);
236236
}
237-
fn visit_block(&mut self, blk: &'v Block) {
237+
fn visit_block(&mut self, blk: &Block) {
238238
self.apply(|this| walk_block(this, blk));
239239
}
240-
fn visit_arm(&mut self, arm: &'v Arm) {
240+
fn visit_arm(&mut self, arm: &Arm) {
241241
self.apply(|this| {
242242
// just go through the first pattern, as either all patterns bind the same bindings or rustc would have errored much earlier
243243
SimilarNamesNameVisitor(this).visit_pat(&arm.pats[0]);
244244
this.apply(|this| walk_expr(this, &arm.body));
245245
});
246246
}
247-
fn visit_item(&mut self, _: &'v Item) {
247+
fn visit_item(&mut self, _: &Item) {
248248
// do not recurse into inner items
249249
}
250250
}

clippy_lints/src/returns.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ pub struct ReturnPass;
3636
impl ReturnPass {
3737
// Check the final stmt or expr in a block for unnecessary return.
3838
fn check_block_return(&mut self, cx: &EarlyContext, block: &Block) {
39-
if let Some(ref expr) = block.expr {
40-
self.check_final_expr(cx, expr);
41-
} else if let Some(stmt) = block.stmts.last() {
42-
if let StmtKind::Semi(ref expr, _) = stmt.node {
43-
if let ExprKind::Ret(Some(ref inner)) = expr.node {
44-
self.emit_return_lint(cx, (stmt.span, inner.span));
39+
if let Some(stmt) = block.stmts.last() {
40+
match stmt.node {
41+
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => {
42+
self.check_final_expr(cx, expr);
4543
}
44+
_ => (),
4645
}
4746
}
4847
}
@@ -88,12 +87,14 @@ impl ReturnPass {
8887

8988
// Check for "let x = EXPR; x"
9089
fn check_let_return(&mut self, cx: &EarlyContext, block: &Block) {
90+
let mut it = block.stmts.iter();
91+
9192
// we need both a let-binding stmt and an expr
9293
if_let_chain! {[
93-
let Some(stmt) = block.stmts.last(),
94-
let Some(ref retexpr) = block.expr,
95-
let StmtKind::Decl(ref decl, _) = stmt.node,
96-
let DeclKind::Local(ref local) = decl.node,
94+
let Some(ref retexpr) = it.next_back(),
95+
let StmtKind::Expr(ref retexpr) = retexpr.node,
96+
let Some(stmt) = it.next_back(),
97+
let StmtKind::Local(ref local) = stmt.node,
9798
let Some(ref initexpr) = local.init,
9899
let PatKind::Ident(_, Spanned { node: id, .. }, _) = local.pat.node,
99100
let ExprKind::Path(_, ref path) = retexpr.node,

mini-macro/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate rustc;
55
extern crate rustc_plugin;
66

77
use syntax::codemap::Span;
8-
use syntax::ast::TokenTree;
8+
use syntax::tokenstream::TokenTree;
99
use syntax::ext::base::{ExtCtxt, MacResult, MacEager};
1010
use syntax::ext::build::AstBuilder; // trait for expr_usize
1111
use rustc_plugin::Registry;

src/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#![feature(box_syntax)]
33
#![feature(rustc_private)]
44

5-
extern crate rustc_driver;
5+
extern crate clippy_lints;
66
extern crate getopts;
77
extern crate rustc;
8-
extern crate syntax;
8+
extern crate rustc_driver;
9+
extern crate rustc_errors;
910
extern crate rustc_plugin;
10-
extern crate clippy_lints;
11+
extern crate syntax;
1112

1213
use rustc_driver::{driver, CompilerCalls, RustcDefaultCalls, Compilation};
1314
use rustc::session::{config, Session};
1415
use rustc::session::config::{Input, ErrorOutputType};
15-
use syntax::diagnostics;
1616
use std::path::PathBuf;
1717
use std::process::Command;
1818

@@ -36,7 +36,7 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
3636
fn early_callback(&mut self,
3737
matches: &getopts::Matches,
3838
sopts: &config::Options,
39-
descriptions: &diagnostics::registry::Registry,
39+
descriptions: &rustc_errors::registry::Registry,
4040
output: ErrorOutputType)
4141
-> Compilation {
4242
self.0.early_callback(matches, sopts, descriptions, output)
@@ -46,7 +46,7 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
4646
sopts: &config::Options,
4747
odir: &Option<PathBuf>,
4848
ofile: &Option<PathBuf>,
49-
descriptions: &diagnostics::registry::Registry)
49+
descriptions: &rustc_errors::registry::Registry)
5050
-> Option<(Input, Option<PathBuf>)> {
5151
self.0.no_input(matches, sopts, odir, ofile, descriptions)
5252
}

tests/compile-fail/formatting.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ fn main() {
1616
//~| NOTE add the missing `else` or
1717
}
1818

19-
let _ = {
19+
let _ = { // if as the last expression
20+
let _ = 0;
21+
2022
if foo() {
2123
} if foo() {
2224
//~^ ERROR this looks like an `else if` but the `else` is missing
@@ -26,6 +28,18 @@ fn main() {
2628
}
2729
};
2830

31+
let _ = { // if in the middle of a block
32+
if foo() {
33+
} if foo() {
34+
//~^ ERROR this looks like an `else if` but the `else` is missing
35+
//~| NOTE add the missing `else` or
36+
}
37+
else {
38+
}
39+
40+
let _ = 0;
41+
};
42+
2943
if foo() {
3044
} else
3145
//~^ ERROR this is an `else if` but the formatting might hide it

tests/compile-fail/item_after_statement.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
#![plugin(clippy)]
33
#![deny(items_after_statements)]
44

5+
fn ok() {
6+
fn foo() { println!("foo"); }
7+
foo();
8+
}
9+
10+
fn last() {
11+
foo();
12+
fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing
13+
}
14+
515
fn main() {
616
foo();
717
fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing

tests/compile-fail/needless_bool.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![feature(plugin)]
22
#![plugin(clippy)]
3+
#![deny(needless_bool)]
34

45
#[allow(if_same_then_else)]
5-
#[deny(needless_bool)]
66
fn main() {
77
let x = true;
88
if x { true } else { true }; //~ERROR this if-then-else expression will always return true
@@ -22,27 +22,27 @@ fn main() {
2222
bool_ret4(x);
2323
}
2424

25-
#[deny(needless_bool)]
26-
#[allow(if_same_then_else)]
25+
#[allow(if_same_then_else, needless_return)]
2726
fn bool_ret(x: bool) -> bool {
28-
if x { return true } else { return true }; //~ERROR this if-then-else expression will always return true
27+
if x { return true } else { return true };
28+
//~^ ERROR this if-then-else expression will always return true
2929
}
3030

31-
#[deny(needless_bool)]
32-
#[allow(if_same_then_else)]
31+
#[allow(if_same_then_else, needless_return)]
3332
fn bool_ret2(x: bool) -> bool {
34-
if x { return false } else { return false }; //~ERROR this if-then-else expression will always return false
33+
if x { return false } else { return false };
34+
//~^ ERROR this if-then-else expression will always return false
3535
}
3636

37-
#[deny(needless_bool)]
37+
#[allow(needless_return)]
3838
fn bool_ret3(x: bool) -> bool {
3939
if x { return true } else { return false };
4040
//~^ ERROR this if-then-else expression returns a bool literal
4141
//~| HELP you can reduce it to
4242
//~| SUGGESTION `return x`
4343
}
4444

45-
#[deny(needless_bool)]
45+
#[allow(needless_return)]
4646
fn bool_ret4(x: bool) -> bool {
4747
if x { return false } else { return true };
4848
//~^ ERROR this if-then-else expression returns a bool literal

tests/consts.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use syntax::ast::{LitIntType, LitKind, StrStyle};
1414
use syntax::codemap::{Spanned, COMMAND_LINE_SP};
1515
use syntax::parse::token::InternedString;
1616
use syntax::ptr::P;
17+
use syntax::util::ThinVec;
1718

1819
fn spanned<T>(t: T) -> Spanned<T> {
1920
Spanned {
@@ -27,7 +28,7 @@ fn expr(n: Expr_) -> Expr {
2728
id: 1,
2829
node: n,
2930
span: COMMAND_LINE_SP,
30-
attrs: None,
31+
attrs: ThinVec::new(),
3132
}
3233
}
3334

0 commit comments

Comments
 (0)