Skip to content

Commit 5e23fce

Browse files
author
Michael Wright
committed
Merge branch 'master' into issue2894
2 parents a05c9b6 + b2caf66 commit 5e23fce

File tree

143 files changed

+873
-787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+873
-787
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ matrix:
4848
- env: INTEGRATION=serde-rs/serde
4949
- env: INTEGRATION=Geal/nom
5050
- env: INTEGRATION=hyperium/hyper
51-
- env: INTEGRATION=rust-lang/cargo
52-
- env: INTEGRATION=rust-lang-nursery/rls
5351

5452
script:
5553
- |

clippy_lints/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ edition = "2018"
2121
[dependencies]
2222
cargo_metadata = "0.5"
2323
itertools = "0.7"
24-
lazy_static = "1.0"
25-
matches = "0.1.2"
24+
lazy_static = "1.0.2"
25+
matches = "0.1.7"
2626
quine-mc_cluskey = "0.2.2"
2727
regex-syntax = "0.6"
2828
semver = "0.9.0"
@@ -32,7 +32,7 @@ toml = "0.4"
3232
unicode-normalization = "0.1"
3333
pulldown-cmark = "0.1"
3434
url = "1.7.0"
35-
if_chain = "0.1"
35+
if_chain = "0.1.3"
3636

3737
[features]
3838
debugging = []

clippy_lints/src/approx_const.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir::*;
33
use rustc::lint::*;
4+
use rustc::{declare_lint, lint_array};
45
use std::f64::consts as f64;
56
use syntax::ast::{FloatTy, Lit, LitKind};
67
use syntax::symbol;
@@ -69,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
6970
}
7071
}
7172

72-
fn check_lit(cx: &LateContext, lit: &Lit, e: &Expr) {
73+
fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
7374
match lit.node {
7475
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
7576
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
@@ -78,7 +79,7 @@ fn check_lit(cx: &LateContext, lit: &Lit, e: &Expr) {
7879
}
7980
}
8081

81-
fn check_known_consts(cx: &LateContext, e: &Expr, s: symbol::Symbol, module: &str) {
82+
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
8283
let s = s.as_str();
8384
if s.parse::<f64>().is_ok() {
8485
for &(constant, name, min_digits) in KNOWN_CONSTS {

clippy_lints/src/arithmetic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir;
33
use rustc::lint::*;
4+
use rustc::{declare_lint, lint_array};
45
use syntax::codemap::Span;
56

67
/// **What it does:** Checks for plain integer arithmetic.

clippy_lints/src/assign_ops.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use crate::utils::{higher, sugg};
33
use rustc::hir;
44
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
55
use rustc::lint::*;
6+
use rustc::{declare_lint, lint_array};
7+
use if_chain::if_chain;
68
use syntax::ast;
79

810
/// **What it does:** Checks for compound assignment operations (`+=` and
@@ -49,8 +51,10 @@ declare_clippy_lint! {
4951
/// **Why is this bad?** Most likely these are bugs where one meant to write `a
5052
/// op= b`.
5153
///
52-
/// **Known problems:** Someone might actually mean `a op= a op b`, but that
53-
/// should rather be written as `a = (2 * a) op b` where applicable.
54+
/// **Known problems:** Clippy cannot know for sure if `a op= a op b` should have
55+
/// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore it suggests both.
56+
/// If `a op= a op b` is really the correct behaviour it should be
57+
/// written as `a = a op a op b` as it's less confusing.
5458
///
5559
/// **Example:**
5660
/// ```rust

clippy_lints/src/attrs.rs

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::utils::{
77
};
88
use rustc::hir::*;
99
use rustc::lint::*;
10+
use rustc::{declare_lint, lint_array};
11+
use if_chain::if_chain;
1012
use rustc::ty::{self, TyCtxt};
1113
use semver::Version;
1214
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
@@ -39,22 +41,31 @@ declare_clippy_lint! {
3941
}
4042

4143
/// **What it does:** Checks for `extern crate` and `use` items annotated with
42-
/// lint attributes
44+
/// lint attributes.
45+
///
46+
/// This lint whitelists `#[allow(unused_imports)]` and `#[allow(deprecated)]` on
47+
/// `use` items and `#[allow(unused_imports)]` on `extern crate` items with a
48+
/// `#[macro_use]` attribute.
4349
///
4450
/// **Why is this bad?** Lint attributes have no effect on crate imports. Most
45-
/// likely a `!` was
46-
/// forgotten
51+
/// likely a `!` was forgotten.
4752
///
48-
/// **Known problems:** Technically one might allow `unused_import` on a `use`
49-
/// item,
50-
/// but it's easier to remove the unused item.
53+
/// **Known problems:** None.
5154
///
5255
/// **Example:**
5356
/// ```rust
57+
/// // Bad
5458
/// #[deny(dead_code)]
5559
/// extern crate foo;
56-
/// #[allow(unused_import)]
60+
/// #[forbid(dead_code)]
5761
/// use foo::bar;
62+
///
63+
/// // Ok
64+
/// #[allow(unused_imports)]
65+
/// use foo::baz;
66+
/// #[allow(unused_imports)]
67+
/// #[macro_use]
68+
/// extern crate baz;
5869
/// ```
5970
declare_clippy_lint! {
6071
pub USELESS_ATTRIBUTE,
@@ -154,17 +165,26 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
154165
check_attrs(cx, item.span, item.name, &item.attrs)
155166
}
156167
match item.node {
157-
ItemKind::ExternCrate(_) | ItemKind::Use(_, _) => {
168+
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
169+
let skip_unused_imports = item.attrs.iter().any(|attr| attr.name() == "macro_use");
170+
158171
for attr in &item.attrs {
159172
if let Some(ref lint_list) = attr.meta_item_list() {
160173
match &*attr.name().as_str() {
161174
"allow" | "warn" | "deny" | "forbid" => {
162-
// whitelist `unused_imports` and `deprecated`
175+
// whitelist `unused_imports` and `deprecated` for `use` items
176+
// and `unused_imports` for `extern crate` items with `macro_use`
163177
for lint in lint_list {
164-
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
165-
if let ItemKind::Use(_, _) = item.node {
166-
return;
167-
}
178+
match item.node {
179+
ItemKind::Use(..) => if is_word(lint, "unused_imports")
180+
|| is_word(lint, "deprecated") {
181+
return
182+
},
183+
ItemKind::ExternCrate(..) => if is_word(lint, "unused_imports")
184+
&& skip_unused_imports {
185+
return
186+
},
187+
_ => {},
168188
}
169189
}
170190
let line_span = last_line_of_span(cx, attr.span);
@@ -206,22 +226,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
206226
}
207227
}
208228

209-
fn is_relevant_item(tcx: TyCtxt, item: &Item) -> bool {
229+
fn is_relevant_item(tcx: TyCtxt<'_, '_, '_>, item: &Item) -> bool {
210230
if let ItemKind::Fn(_, _, _, eid) = item.node {
211231
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)
212232
} else {
213233
true
214234
}
215235
}
216236

217-
fn is_relevant_impl(tcx: TyCtxt, item: &ImplItem) -> bool {
237+
fn is_relevant_impl(tcx: TyCtxt<'_, '_, '_>, item: &ImplItem) -> bool {
218238
match item.node {
219239
ImplItemKind::Method(_, eid) => is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value),
220240
_ => false,
221241
}
222242
}
223243

224-
fn is_relevant_trait(tcx: TyCtxt, item: &TraitItem) -> bool {
244+
fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
225245
match item.node {
226246
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
227247
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
@@ -231,7 +251,7 @@ fn is_relevant_trait(tcx: TyCtxt, item: &TraitItem) -> bool {
231251
}
232252
}
233253

234-
fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> bool {
254+
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
235255
if let Some(stmt) = block.stmts.first() {
236256
match stmt.node {
237257
StmtKind::Decl(_, _) => true,
@@ -242,7 +262,7 @@ fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> b
242262
}
243263
}
244264

245-
fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool {
265+
fn is_relevant_expr(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
246266
match expr.node {
247267
ExprKind::Block(ref block, _) => is_relevant_block(tcx, tables, block),
248268
ExprKind::Ret(Some(ref e)) => is_relevant_expr(tcx, tables, e),
@@ -260,7 +280,7 @@ fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool
260280
}
261281
}
262282

263-
fn check_attrs(cx: &LateContext, span: Span, name: Name, attrs: &[Attribute]) {
283+
fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) {
264284
if in_macro(span) {
265285
return;
266286
}
@@ -311,7 +331,7 @@ fn check_attrs(cx: &LateContext, span: Span, name: Name, attrs: &[Attribute]) {
311331
}
312332
}
313333

314-
fn check_semver(cx: &LateContext, span: Span, lit: &Lit) {
334+
fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
315335
if let LitKind::Str(ref is, _) = lit.node {
316336
if Version::parse(&is.as_str()).is_ok() {
317337
return;
@@ -338,7 +358,7 @@ fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
338358
// sources that the user has no control over.
339359
// For some reason these attributes don't have any expansion info on them, so
340360
// we have to check it this way until there is a better way.
341-
fn is_present_in_source(cx: &LateContext, span: Span) -> bool {
361+
fn is_present_in_source(cx: &LateContext<'_, '_>, span: Span) -> bool {
342362
if let Some(snippet) = snippet_opt(cx, span) {
343363
if snippet.is_empty() {
344364
return false;

clippy_lints/src/bit_mask.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc::hir::*;
22
use rustc::lint::*;
3+
use rustc::{declare_lint, lint_array};
4+
use if_chain::if_chain;
35
use syntax::ast::LitKind;
46
use syntax::codemap::Span;
57
use crate::utils::{span_lint, span_lint_and_then};
@@ -156,7 +158,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
156158
}
157159

158160

159-
fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
161+
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
160162
if let ExprKind::Binary(ref op, ref left, ref right) = bit_op.node {
161163
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
162164
return;
@@ -167,7 +169,7 @@ fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOpKind, cmp_value:
167169
}
168170
}
169171

170-
fn check_bit_mask(cx: &LateContext, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, cmp_value: u128, span: Span) {
172+
fn check_bit_mask(cx: &LateContext<'_, '_>, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, cmp_value: u128, span: Span) {
171173
match cmp_op {
172174
BinOpKind::Eq | BinOpKind::Ne => match bit_op {
173175
BinOpKind::BitAnd => if mask_value & cmp_value != cmp_value {
@@ -268,7 +270,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOpKind, cmp_op: BinOpKind, mask_v
268270
}
269271
}
270272

271-
fn check_ineffective_lt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str) {
273+
fn check_ineffective_lt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) {
272274
if c.is_power_of_two() && m < c {
273275
span_lint(
274276
cx,
@@ -284,7 +286,7 @@ fn check_ineffective_lt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str
284286
}
285287
}
286288

287-
fn check_ineffective_gt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str) {
289+
fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) {
288290
if (c + 1).is_power_of_two() && m <= c {
289291
span_lint(
290292
cx,
@@ -300,7 +302,7 @@ fn check_ineffective_gt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str
300302
}
301303
}
302304

303-
fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u128> {
305+
fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr) -> Option<u128> {
304306
match constant(cx, cx.tables, lit)?.0 {
305307
Constant::Int(n) => Some(n),
306308
_ => None,

clippy_lints/src/blacklisted_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc::lint::*;
2+
use rustc::{declare_lint, lint_array};
23
use rustc::hir::*;
34
use crate::utils::span_lint;
45

clippy_lints/src/block_in_if_condition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use matches::matches;
12
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3+
use rustc::{declare_lint, lint_array};
24
use rustc::hir::*;
35
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
46
use crate::utils::*;

clippy_lints/src/booleans.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
2+
use rustc::{declare_lint, lint_array};
23
use rustc::hir::*;
34
use rustc::hir::intravisit::*;
45
use syntax::ast::{LitKind, NodeId, DUMMY_NODE_ID};
@@ -274,7 +275,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
274275
}
275276

276277
// The boolean part of the return indicates whether some simplifications have been applied.
277-
fn suggest(cx: &LateContext, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
278+
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
278279
let mut suggest_context = SuggestContext {
279280
terminals,
280281
cx,

clippy_lints/src/bytecount.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc::hir::*;
22
use rustc::lint::*;
3+
use rustc::{declare_lint, lint_array};
4+
use if_chain::if_chain;
35
use rustc::ty;
46
use syntax::ast::{Name, UintTy};
57
use crate::utils::{contains_name, get_pat_name, match_type, paths, single_segment_path, snippet, span_lint_and_sugg,
@@ -36,7 +38,7 @@ impl LintPass for ByteCount {
3638
}
3739

3840
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
39-
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
41+
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
4042
if_chain! {
4143
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.node;
4244
if count.ident.name == "count";

clippy_lints/src/collapsible_if.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
//! This lint is **warn** by default
1414
1515
use rustc::lint::*;
16+
use rustc::{declare_lint, lint_array};
17+
use if_chain::if_chain;
1618
use syntax::ast;
1719

1820
use crate::utils::{in_macro, snippet_block, span_lint_and_sugg, span_lint_and_then};
@@ -78,14 +80,14 @@ impl LintPass for CollapsibleIf {
7880
}
7981

8082
impl EarlyLintPass for CollapsibleIf {
81-
fn check_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr) {
83+
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
8284
if !in_macro(expr.span) {
8385
check_if(cx, expr)
8486
}
8587
}
8688
}
8789

88-
fn check_if(cx: &EarlyContext, expr: &ast::Expr) {
90+
fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
8991
match expr.node {
9092
ast::ExprKind::If(ref check, ref then, ref else_) => if let Some(ref else_) = *else_ {
9193
check_collapsible_maybe_if_let(cx, else_);
@@ -99,7 +101,7 @@ fn check_if(cx: &EarlyContext, expr: &ast::Expr) {
99101
}
100102
}
101103

102-
fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
104+
fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
103105
if_chain! {
104106
if let ast::ExprKind::Block(ref block, _) = else_.node;
105107
if let Some(else_) = expr_block(block);
@@ -120,7 +122,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
120122
}
121123
}
122124

123-
fn check_collapsible_no_if_let(cx: &EarlyContext, expr: &ast::Expr, check: &ast::Expr, then: &ast::Block) {
125+
fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &ast::Expr, then: &ast::Block) {
124126
if_chain! {
125127
if let Some(inner) = expr_block(then);
126128
if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node;

0 commit comments

Comments
 (0)