Skip to content

Commit 7f868c9

Browse files
committed
Merge branch 'master' of github.com:rust-lang/rust-clippy
2 parents 714272f + c6e43b1 commit 7f868c9

File tree

169 files changed

+1233
-2688
lines changed

Some content is hidden

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

169 files changed

+1233
-2688
lines changed

.cargo/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[alias]
22
uitest = "test --test compile-test"
3+
4+
[build]
5+
rustflags = ["-Zunstable-options"]

.github/PULL_REQUEST_TEMPLATE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
Thank you for making Clippy better!
3+
4+
We're collecting our changelog from pull request descriptions.
5+
If your PR only updates to the latest nightly, you can leave the
6+
`changelog` entry as `none`. Otherwise, please write a short comment
7+
explaining your change.
8+
9+
If your PR fixes an issue, you can add "fixes #issue_number" into this
10+
PR description. This way the issue will be automatically closed when
11+
your PR is merged.
12+
13+
If you added a new lint, here's a checklist for things that will be
14+
checked during review or continuous integration.
15+
16+
- [ ] Followed [lint naming conventions][lint_naming]
17+
- [ ] Added passing UI tests (including committed `.stderr` file)
18+
- [ ] `cargo test` passes locally
19+
- [ ] Executed `util/dev update_lints`
20+
- [ ] Added lint documentation
21+
- [ ] Run `cargo fmt`
22+
23+
Note that you can skip the above if you are just opening a WIP PR in
24+
order to get feedback.
25+
26+
Delete this line and everything above before opening your PR -->
27+
28+
changelog: none

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ All notable changes to this project will be documented in this file.
10151015
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
10161016
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
10171017
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
1018+
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
10181019
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
10191020
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
10201021
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

10-
[There are 298 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 299 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1111

1212
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1313

clippy_dev/rust-toolchain

Lines changed: 0 additions & 1 deletion
This file was deleted.

clippy_dev/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(clippy::default_hash_types)]
2-
31
use itertools::Itertools;
42
use lazy_static::lazy_static;
53
use regex::Regex;

clippy_lints/src/approx_const.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_tool_lint, lint_array};
4+
use rustc::{declare_lint_pass, declare_tool_lint};
55
use std::f64::consts as f64;
66
use syntax::ast::{FloatTy, Lit, LitKind};
77
use syntax::symbol;
@@ -53,20 +53,9 @@ const KNOWN_CONSTS: &[(f64, &str, usize)] = &[
5353
(f64::SQRT_2, "SQRT_2", 5),
5454
];
5555

56-
#[derive(Copy, Clone)]
57-
pub struct Pass;
56+
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
5857

59-
impl LintPass for Pass {
60-
fn get_lints(&self) -> LintArray {
61-
lint_array!(APPROX_CONSTANT)
62-
}
63-
64-
fn name(&self) -> &'static str {
65-
"ApproxConstant"
66-
}
67-
}
68-
69-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
58+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
7059
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
7160
if let ExprKind::Lit(lit) = &e.node {
7261
check_lit(cx, lit, e);

clippy_lints/src/arithmetic.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::consts::constant_simple;
22
use crate::utils::span_lint;
33
use rustc::hir;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5-
use rustc::{declare_tool_lint, lint_array};
5+
use rustc::{declare_tool_lint, impl_lint_pass};
66
use syntax::source_map::Span;
77

88
declare_clippy_lint! {
@@ -48,15 +48,7 @@ pub struct Arithmetic {
4848
const_span: Option<Span>,
4949
}
5050

51-
impl LintPass for Arithmetic {
52-
fn get_lints(&self) -> LintArray {
53-
lint_array!(INTEGER_ARITHMETIC, FLOAT_ARITHMETIC)
54-
}
55-
56-
fn name(&self) -> &'static str {
57-
"Arithmetic"
58-
}
59-
}
51+
impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
6052

6153
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
6254
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {

clippy_lints/src/assertions_on_constants.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use if_chain::if_chain;
22
use rustc::hir::{Expr, ExprKind};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_tool_lint, lint_array};
4+
use rustc::{declare_lint_pass, declare_tool_lint};
55

66
use crate::consts::{constant, Constant};
77
use crate::syntax::ast::LitKind;
@@ -29,17 +29,7 @@ declare_clippy_lint! {
2929
"`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`"
3030
}
3131

32-
pub struct AssertionsOnConstants;
33-
34-
impl LintPass for AssertionsOnConstants {
35-
fn get_lints(&self) -> LintArray {
36-
lint_array![ASSERTIONS_ON_CONSTANTS]
37-
}
38-
39-
fn name(&self) -> &'static str {
40-
"AssertionsOnConstants"
41-
}
42-
}
32+
declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
4333

4434
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4535
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

clippy_lints/src/assign_ops.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use if_chain::if_chain;
22
use rustc::hir;
33
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5-
use rustc::{declare_tool_lint, lint_array};
5+
use rustc::{declare_lint_pass, declare_tool_lint};
66
use rustc_errors::Applicability;
77

88
use crate::utils::{
@@ -53,18 +53,7 @@ declare_clippy_lint! {
5353
"having a variable on both sides of an assign op"
5454
}
5555

56-
#[derive(Copy, Clone, Default)]
57-
pub struct AssignOps;
58-
59-
impl LintPass for AssignOps {
60-
fn get_lints(&self) -> LintArray {
61-
lint_array!(ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP)
62-
}
63-
64-
fn name(&self) -> &'static str {
65-
"AssignOps"
66-
}
67-
}
56+
declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
6857

6958
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7059
#[allow(clippy::too_many_lines)]

clippy_lints/src/attrs.rs

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::reexport::*;
44
use crate::utils::{
5-
in_macro, last_line_of_span, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg, span_lint_and_then,
5+
in_macro, last_line_of_span, paths, snippet_opt, span_lint, span_lint_and_sugg, span_lint_and_then,
66
without_block_comments,
77
};
88
use if_chain::if_chain;
@@ -11,8 +11,8 @@ use rustc::lint::{
1111
in_external_macro, CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray,
1212
LintContext, LintPass,
1313
};
14-
use rustc::ty::{self, TyCtxt};
15-
use rustc::{declare_tool_lint, lint_array};
14+
use rustc::ty;
15+
use rustc::{declare_lint_pass, declare_tool_lint};
1616
use rustc_errors::Applicability;
1717
use semver::Version;
1818
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
@@ -187,26 +187,15 @@ declare_clippy_lint! {
187187
"usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"
188188
}
189189

190-
#[derive(Copy, Clone)]
191-
pub struct AttrPass;
190+
declare_lint_pass!(Attributes => [
191+
INLINE_ALWAYS,
192+
DEPRECATED_SEMVER,
193+
USELESS_ATTRIBUTE,
194+
EMPTY_LINE_AFTER_OUTER_ATTR,
195+
UNKNOWN_CLIPPY_LINTS,
196+
]);
192197

193-
impl LintPass for AttrPass {
194-
fn get_lints(&self) -> LintArray {
195-
lint_array!(
196-
INLINE_ALWAYS,
197-
DEPRECATED_SEMVER,
198-
USELESS_ATTRIBUTE,
199-
EMPTY_LINE_AFTER_OUTER_ATTR,
200-
UNKNOWN_CLIPPY_LINTS,
201-
)
202-
}
203-
204-
fn name(&self) -> &'static str {
205-
"Attributes"
206-
}
207-
}
208-
209-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
198+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
210199
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
211200
if let Some(items) = &attr.meta_item_list() {
212201
if let Some(ident) = attr.ident() {
@@ -234,7 +223,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
234223
}
235224

236225
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
237-
if is_relevant_item(cx.tcx, item) {
226+
if is_relevant_item(cx, item) {
238227
check_attrs(cx, item.span, item.ident.name, &item.attrs)
239228
}
240229
match item.node {
@@ -302,13 +291,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
302291
}
303292

304293
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
305-
if is_relevant_impl(cx.tcx, item) {
294+
if is_relevant_impl(cx, item) {
306295
check_attrs(cx, item.span, item.ident.name, &item.attrs)
307296
}
308297
}
309298

310299
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
311-
if is_relevant_trait(cx.tcx, item) {
300+
if is_relevant_trait(cx, item) {
312301
check_attrs(cx, item.span, item.ident.name, &item.attrs)
313302
}
314303
}
@@ -361,52 +350,52 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
361350
}
362351
}
363352

364-
fn is_relevant_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &Item) -> bool {
353+
fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item) -> bool {
365354
if let ItemKind::Fn(_, _, _, eid) = item.node {
366-
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir().body(eid).value)
355+
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
367356
} else {
368357
true
369358
}
370359
}
371360

372-
fn is_relevant_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &ImplItem) -> bool {
361+
fn is_relevant_impl(cx: &LateContext<'_, '_>, item: &ImplItem) -> bool {
373362
match item.node {
374-
ImplItemKind::Method(_, eid) => is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir().body(eid).value),
363+
ImplItemKind::Method(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value),
375364
_ => false,
376365
}
377366
}
378367

379-
fn is_relevant_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &TraitItem) -> bool {
368+
fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem) -> bool {
380369
match item.node {
381370
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
382371
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
383-
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir().body(eid).value)
372+
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
384373
},
385374
_ => false,
386375
}
387376
}
388377

389-
fn is_relevant_block<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
378+
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
390379
if let Some(stmt) = block.stmts.first() {
391380
match &stmt.node {
392381
StmtKind::Local(_) => true,
393-
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(tcx, tables, expr),
382+
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr),
394383
_ => false,
395384
}
396385
} else {
397-
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
386+
block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e))
398387
}
399388
}
400389

401-
fn is_relevant_expr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
390+
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
402391
match &expr.node {
403-
ExprKind::Block(block, _) => is_relevant_block(tcx, tables, block),
404-
ExprKind::Ret(Some(e)) => is_relevant_expr(tcx, tables, e),
392+
ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
393+
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),
405394
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
406395
ExprKind::Call(path_expr, _) => {
407396
if let ExprKind::Path(qpath) = &path_expr.node {
408397
if let Some(fun_id) = tables.qpath_def(qpath, path_expr.hir_id).opt_def_id() {
409-
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
398+
!cx.match_def_path(fun_id, &paths::BEGIN_PANIC)
410399
} else {
411400
true
412401
}
@@ -506,20 +495,9 @@ fn is_present_in_source(cx: &LateContext<'_, '_>, span: Span) -> bool {
506495
true
507496
}
508497

509-
#[derive(Copy, Clone)]
510-
pub struct CfgAttrPass;
511-
512-
impl LintPass for CfgAttrPass {
513-
fn get_lints(&self) -> LintArray {
514-
lint_array!(DEPRECATED_CFG_ATTR,)
515-
}
516-
517-
fn name(&self) -> &'static str {
518-
"DeprecatedCfgAttribute"
519-
}
520-
}
498+
declare_lint_pass!(DeprecatedCfgAttribute => [DEPRECATED_CFG_ATTR]);
521499

522-
impl EarlyLintPass for CfgAttrPass {
500+
impl EarlyLintPass for DeprecatedCfgAttribute {
523501
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
524502
if_chain! {
525503
// check cfg_attr

clippy_lints/src/bit_mask.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::utils::{span_lint, span_lint_and_then};
44
use if_chain::if_chain;
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
7-
use rustc::{declare_tool_lint, lint_array};
7+
use rustc::{declare_tool_lint, impl_lint_pass};
88
use rustc_errors::Applicability;
99
use syntax::ast::LitKind;
1010
use syntax::source_map::Span;
@@ -107,14 +107,7 @@ impl BitMask {
107107
}
108108
}
109109

110-
impl LintPass for BitMask {
111-
fn get_lints(&self) -> LintArray {
112-
lint_array!(BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK)
113-
}
114-
fn name(&self) -> &'static str {
115-
"BitMask"
116-
}
117-
}
110+
impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]);
118111

119112
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
120113
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

0 commit comments

Comments
 (0)