Skip to content

Commit d243d68

Browse files
authored
Merge pull request #1054 from Manishearth/rustup
Rustup to ea0dc92
2 parents cb9786e + f609ac5 commit d243d68

17 files changed

+107
-98
lines changed

Diff for: CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4-
## 0.0.78 - TBA
4+
## 0.0.78 - 2016-07-02
5+
* Rustup to *rustc 1.11.0-nightly (01411937f 2016-07-01)*
56
* New lints: [`wrong_transmute`, `double_neg`]
67
* For compatibility, `cargo clippy` does not defines the `clippy` feature
78
introduced in 0.0.76 anymore

Diff for: Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.77"
3+
version = "0.0.78"
44
authors = [
55
"Manish Goregaokar <manishsmail@gmail.com>",
66
"Andre Bogus <bogusandre@gmail.com>",
@@ -25,7 +25,7 @@ test = false
2525

2626
[dependencies]
2727
# begin automatic update
28-
clippy_lints = { version = "0.0.77", path = "clippy_lints" }
28+
clippy_lints = { version = "0.0.78", path = "clippy_lints" }
2929
# end automatic update
3030

3131
[dev-dependencies]

Diff for: clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.0.77"
4+
version = "0.0.78"
55
# end automatic update
66
authors = [
77
"Manish Goregaokar <manishsmail@gmail.com>",

Diff for: 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
};

Diff for: clippy_lints/src/collapsible_if.rs

+11-23
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ fn check_if(cx: &EarlyContext, expr: &ast::Expr) {
7272
fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
7373
if_let_chain! {[
7474
let ast::ExprKind::Block(ref block) = else_.node,
75-
block.stmts.is_empty(),
76-
let Some(ref else_) = block.expr,
75+
let Some(ref else_) = expr_block(block),
76+
!in_macro(cx, else_.span),
7777
], {
7878
match else_.node {
7979
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {
@@ -96,7 +96,7 @@ fn check_collapsible_no_if_let(
9696
then: &ast::Block,
9797
) {
9898
if_let_chain! {[
99-
let Some(inner) = single_stmt_of_block(then),
99+
let Some(inner) = expr_block(then),
100100
let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node,
101101
], {
102102
if expr.span.expn_id != inner.span.expn_id {
@@ -128,28 +128,16 @@ fn check_to_string(cx: &EarlyContext, e: &ast::Expr) -> Cow<'static, str> {
128128
}
129129
}
130130

131-
fn single_stmt_of_block(block: &ast::Block) -> Option<&ast::Expr> {
132-
if block.stmts.len() == 1 && block.expr.is_none() {
133-
if let ast::StmtKind::Expr(ref expr, _) = block.stmts[0].node {
134-
single_stmt_of_expr(expr)
135-
} else {
136-
None
137-
}
138-
} else if block.stmts.is_empty() {
139-
if let Some(ref p) = block.expr {
140-
Some(p)
141-
} else {
142-
None
131+
/// If the block contains only one expression, returns it.
132+
fn expr_block(block: &ast::Block) -> Option<&ast::Expr> {
133+
let mut it = block.stmts.iter();
134+
135+
if let (Some(stmt), None) = (it.next(), it.next()) {
136+
match stmt.node {
137+
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => Some(expr),
138+
_ => None,
143139
}
144140
} else {
145141
None
146142
}
147143
}
148-
149-
fn single_stmt_of_expr(expr: &ast::Expr) -> Option<&ast::Expr> {
150-
if let ast::ExprKind::Block(ref block) = expr.node {
151-
single_stmt_of_block(block)
152-
} else {
153-
Some(expr)
154-
}
155-
}

Diff for: 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) {

Diff for: 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
}

Diff for: 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");

Diff for: 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
}

Diff for: 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,

Diff for: 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;

Diff for: 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
}

Diff for: tests/compile-fail/collapsible_if.rs

+5
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,9 @@ fn main() {
139139
println!("world!")
140140
}
141141
}
142+
143+
if true {
144+
} else {
145+
assert!(true); // assert! is just an `if`
146+
}
142147
}

Diff for: 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

Diff for: 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

0 commit comments

Comments
 (0)