Skip to content

Commit 0d30b1a

Browse files
committed
submodules: update clippy from f7bdf50 to 39bd844
Changes: ```` UI test cleanup: Extract iter_skip_next from methods.rs Update test output after rebase Remove false negatives from known problems Implement use_self for tuple structs Document known problems rustup rust-lang/rust#56225 Remove unnecessary `use` statements after `cargo fix` Apply cargo fix --edition-idioms fixes Use match ergonomics for booleans lint Use match ergonomics for block_in_if_condition lint Use match ergonomics for bit_mask lint Use match ergonomics for attrs lint Use match ergonomics for assign_ops lint Use match ergonomics for artithmetic lint Use match ergonomics for approx_const lint Remove crate:: prefixes from crate paths Support array indexing expressions in unused write to a constant Mark writes to constants as side-effect-less Update README local run command to remove syspath Remove unsafe from consts clippy lints Fix formatting Merge new_without_default_derive into new_without_default Only print out question_mark lint when it actually triggered Add failing test Reinserted commata Recomend `.as_ref()?` in certain situations Deduplicate some code? ````
1 parent eaeac1a commit 0d30b1a

File tree

156 files changed

+1299
-1083
lines changed

Some content is hidden

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

156 files changed

+1299
-1083
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ All notable changes to this project will be documented in this file.
785785
[`never_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
786786
[`new_ret_no_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self
787787
[`new_without_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
788-
[`new_without_default_derive`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default_derive
789788
[`no_effect`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect
790789
[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
791790
[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool

README.md

Lines changed: 2 additions & 2 deletions
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 291 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 290 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

@@ -79,7 +79,7 @@ To have cargo compile your crate with Clippy without Clippy installation
7979
in your code, you can use:
8080

8181
```terminal
82-
RUSTFLAGS=--sysroot=`rustc --print sysroot` cargo run --bin cargo-clippy --manifest-path=path_to_clippys_Cargo.toml
82+
cargo run --bin cargo-clippy --manifest-path=path_to_clippys_Cargo.toml
8383
```
8484

8585
*[Note](https://github.com/rust-lang/rust-clippy/wiki#a-word-of-warning):*

clippy_lints/src/approx_const.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::rustc::hir::*;
11-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
12-
use crate::rustc::{declare_tool_lint, lint_array};
13-
use crate::syntax::ast::{FloatTy, Lit, LitKind};
14-
use crate::syntax::symbol;
1510
use crate::utils::span_lint;
11+
use rustc::hir::*;
12+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13+
use rustc::{declare_tool_lint, lint_array};
1614
use std::f64::consts as f64;
15+
use syntax::ast::{FloatTy, Lit, LitKind};
16+
use syntax::symbol;
1717

1818
/// **What it does:** Checks for floating point literals that approximate
1919
/// constants which are defined in
@@ -73,7 +73,7 @@ impl LintPass for Pass {
7373

7474
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
7575
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
76-
if let ExprKind::Lit(ref lit) = e.node {
76+
if let ExprKind::Lit(lit) = &e.node {
7777
check_lit(cx, lit, e);
7878
}
7979
}

clippy_lints/src/arithmetic.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::rustc::hir;
11-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
12-
use crate::rustc::{declare_tool_lint, lint_array};
13-
use crate::syntax::source_map::Span;
1410
use crate::utils::span_lint;
11+
use rustc::hir;
12+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13+
use rustc::{declare_tool_lint, lint_array};
14+
use syntax::source_map::Span;
1515

1616
/// **What it does:** Checks for plain integer arithmetic.
1717
///
@@ -73,8 +73,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
7373
return;
7474
}
7575
}
76-
match expr.node {
77-
hir::ExprKind::Binary(ref op, ref l, ref r) => {
76+
match &expr.node {
77+
hir::ExprKind::Binary(op, l, r) => {
7878
match op.node {
7979
hir::BinOpKind::And
8080
| hir::BinOpKind::Or
@@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
100100
self.expr_span = Some(expr.span);
101101
}
102102
},
103-
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => {
103+
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
104104
let ty = cx.tables.expr_ty(arg);
105105
if ty.is_integral() {
106106
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");

clippy_lints/src/assign_ops.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::rustc::hir;
11-
use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
12-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13-
use crate::rustc::{declare_tool_lint, lint_array};
14-
use crate::rustc_errors::Applicability;
15-
use crate::syntax::ast;
1610
use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
1711
use crate::utils::{higher, sugg};
1812
use if_chain::if_chain;
13+
use rustc::hir;
14+
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
15+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
16+
use rustc::{declare_tool_lint, lint_array};
17+
use rustc_errors::Applicability;
18+
use syntax::ast;
1919

2020
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
2121
/// patterns.
@@ -70,9 +70,9 @@ impl LintPass for AssignOps {
7070

7171
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7272
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
73-
match expr.node {
74-
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
75-
if let hir::ExprKind::Binary(binop, ref l, ref r) = rhs.node {
73+
match &expr.node {
74+
hir::ExprKind::AssignOp(op, lhs, rhs) => {
75+
if let hir::ExprKind::Binary(binop, l, r) = &rhs.node {
7676
if op.node == binop.node {
7777
let lint = |assignee: &hir::Expr, rhs_other: &hir::Expr| {
7878
span_lint_and_then(
@@ -122,8 +122,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
122122
}
123123
}
124124
},
125-
hir::ExprKind::Assign(ref assignee, ref e) => {
126-
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
125+
hir::ExprKind::Assign(assignee, e) => {
126+
if let hir::ExprKind::Binary(op, l, r) = &e.node {
127127
#[allow(clippy::cyclomatic_complexity)]
128128
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
129129
let ty = cx.tables.expr_ty(assignee);
@@ -150,8 +150,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
150150
if_chain! {
151151
if parent_impl != ast::CRATE_NODE_ID;
152152
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
153-
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) =
154-
item.node;
153+
if let hir::ItemKind::Impl(_, _, _, _, Some(trait_ref), _, _) =
154+
&item.node;
155155
if trait_ref.path.def.def_id() == trait_id;
156156
then { return; }
157157
}
@@ -240,7 +240,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
240240
}
241241

242242
fn is_commutative(op: hir::BinOpKind) -> bool {
243-
use crate::rustc::hir::BinOpKind::*;
243+
use rustc::hir::BinOpKind::*;
244244
match op {
245245
Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true,
246246
Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false,

clippy_lints/src/attrs.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
//! checks for attributes
1111
1212
use crate::reexport::*;
13-
use crate::rustc::hir::*;
14-
use crate::rustc::lint::{
15-
CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
16-
};
17-
use crate::rustc::ty::{self, TyCtxt};
18-
use crate::rustc::{declare_tool_lint, lint_array};
19-
use crate::rustc_errors::Applicability;
20-
use crate::syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
21-
use crate::syntax::source_map::Span;
2213
use crate::utils::{
2314
in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg,
2415
span_lint_and_then, without_block_comments,
2516
};
2617
use if_chain::if_chain;
18+
use rustc::hir::*;
19+
use rustc::lint::{
20+
CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
21+
};
22+
use rustc::ty::{self, TyCtxt};
23+
use rustc::{declare_tool_lint, lint_array};
24+
use rustc_errors::Applicability;
2725
use semver::Version;
26+
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
27+
use syntax::source_map::Span;
2828

2929
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
3030
/// unless the annotated function is empty or simply panics.
@@ -212,7 +212,7 @@ impl LintPass for AttrPass {
212212

213213
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
214214
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
215-
if let Some(ref items) = attr.meta_item_list() {
215+
if let Some(items) = &attr.meta_item_list() {
216216
match &*attr.name().as_str() {
217217
"allow" | "warn" | "deny" | "forbid" => {
218218
check_clippy_lint_names(cx, items);
@@ -224,8 +224,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
224224
}
225225
for item in items {
226226
if_chain! {
227-
if let NestedMetaItemKind::MetaItem(ref mi) = item.node;
228-
if let MetaItemKind::NameValue(ref lit) = mi.node;
227+
if let NestedMetaItemKind::MetaItem(mi) = &item.node;
228+
if let MetaItemKind::NameValue(lit) = &mi.node;
229229
if mi.name() == "since";
230230
then {
231231
check_semver(cx, item.span, lit);
@@ -237,14 +237,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
237237

238238
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
239239
if is_relevant_item(cx.tcx, item) {
240-
check_attrs(cx, item.span, item.name, &item.attrs)
240+
check_attrs(cx, item.span, item.ident.name, &item.attrs)
241241
}
242242
match item.node {
243243
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
244244
let skip_unused_imports = item.attrs.iter().any(|attr| attr.name() == "macro_use");
245245

246246
for attr in &item.attrs {
247-
if let Some(ref lint_list) = attr.meta_item_list() {
247+
if let Some(lint_list) = &attr.meta_item_list() {
248248
match &*attr.name().as_str() {
249249
"allow" | "warn" | "deny" | "forbid" => {
250250
// whitelist `unused_imports` and `deprecated` for `use` items
@@ -381,22 +381,22 @@ fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
381381

382382
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
383383
if let Some(stmt) = block.stmts.first() {
384-
match stmt.node {
384+
match &stmt.node {
385385
StmtKind::Decl(_, _) => true,
386-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => is_relevant_expr(tcx, tables, expr),
386+
StmtKind::Expr(expr, _) | StmtKind::Semi(expr, _) => is_relevant_expr(tcx, tables, expr),
387387
}
388388
} else {
389389
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
390390
}
391391
}
392392

393393
fn is_relevant_expr(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
394-
match expr.node {
395-
ExprKind::Block(ref block, _) => is_relevant_block(tcx, tables, block),
396-
ExprKind::Ret(Some(ref e)) => is_relevant_expr(tcx, tables, e),
394+
match &expr.node {
395+
ExprKind::Block(block, _) => is_relevant_block(tcx, tables, block),
396+
ExprKind::Ret(Some(e)) => is_relevant_expr(tcx, tables, e),
397397
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
398-
ExprKind::Call(ref path_expr, _) => {
399-
if let ExprKind::Path(ref qpath) = path_expr.node {
398+
ExprKind::Call(path_expr, _) => {
399+
if let ExprKind::Path(qpath) = &path_expr.node {
400400
if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) {
401401
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
402402
} else {
@@ -443,7 +443,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
443443
}
444444
}
445445

446-
if let Some(ref values) = attr.meta_item_list() {
446+
if let Some(values) = attr.meta_item_list() {
447447
if values.len() != 1 || attr.name() != "inline" {
448448
continue;
449449
}
@@ -463,7 +463,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
463463
}
464464

465465
fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
466-
if let LitKind::Str(ref is, _) = lit.node {
466+
if let LitKind::Str(is, _) = lit.node {
467467
if Version::parse(&is.as_str()).is_ok() {
468468
return;
469469
}
@@ -477,7 +477,7 @@ fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
477477
}
478478

479479
fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
480-
if let NestedMetaItemKind::MetaItem(ref mi) = nmi.node {
480+
if let NestedMetaItemKind::MetaItem(mi) = &nmi.node {
481481
mi.is_word() && mi.name() == expected
482482
} else {
483483
false
@@ -512,7 +512,7 @@ impl EarlyLintPass for CfgAttrPass {
512512
if_chain! {
513513
// check cfg_attr
514514
if attr.name() == "cfg_attr";
515-
if let Some(ref items) = attr.meta_item_list();
515+
if let Some(items) = attr.meta_item_list();
516516
if items.len() == 2;
517517
// check for `rustfmt`
518518
if let Some(feature_item) = items[0].meta_item();

clippy_lints/src/bit_mask.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// except according to those terms.
99

1010
use crate::consts::{constant, Constant};
11-
use crate::rustc::hir::*;
12-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13-
use crate::rustc::{declare_tool_lint, lint_array};
14-
use crate::rustc_errors::Applicability;
15-
use crate::syntax::ast::LitKind;
16-
use crate::syntax::source_map::Span;
1711
use crate::utils::sugg::Sugg;
1812
use crate::utils::{span_lint, span_lint_and_then};
1913
use if_chain::if_chain;
14+
use rustc::hir::*;
15+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
16+
use rustc::{declare_tool_lint, lint_array};
17+
use rustc_errors::Applicability;
18+
use syntax::ast::LitKind;
19+
use syntax::source_map::Span;
2020

2121
/// **What it does:** Checks for incompatible bit masks in comparisons.
2222
///
@@ -121,7 +121,7 @@ impl LintPass for BitMask {
121121

122122
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
123123
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
124-
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
124+
if let ExprKind::Binary(cmp, left, right) = &e.node {
125125
if cmp.node.is_comparison() {
126126
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
127127
check_compare(cx, left, cmp.node, cmp_opt, e.span)
@@ -131,13 +131,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
131131
}
132132
}
133133
if_chain! {
134-
if let ExprKind::Binary(ref op, ref left, ref right) = e.node;
134+
if let ExprKind::Binary(op, left, right) = &e.node;
135135
if BinOpKind::Eq == op.node;
136-
if let ExprKind::Binary(ref op1, ref left1, ref right1) = left.node;
136+
if let ExprKind::Binary(op1, left1, right1) = &left.node;
137137
if BinOpKind::BitAnd == op1.node;
138-
if let ExprKind::Lit(ref lit) = right1.node;
138+
if let ExprKind::Lit(lit) = &right1.node;
139139
if let LitKind::Int(n, _) = lit.node;
140-
if let ExprKind::Lit(ref lit1) = right.node;
140+
if let ExprKind::Lit(lit1) = &right.node;
141141
if let LitKind::Int(0, _) = lit1.node;
142142
if n.leading_zeros() == n.count_zeros();
143143
if n > u128::from(self.verbose_bit_mask_threshold);
@@ -173,7 +173,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
173173
}
174174

175175
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
176-
if let ExprKind::Binary(ref op, ref left, ref right) = bit_op.node {
176+
if let ExprKind::Binary(op, left, right) = &bit_op.node {
177177
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
178178
return;
179179
}

clippy_lints/src/blacklisted_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::rustc::hir::*;
11-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
12-
use crate::rustc::{declare_tool_lint, lint_array};
1310
use crate::utils::span_lint;
11+
use rustc::hir::*;
12+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13+
use rustc::{declare_tool_lint, lint_array};
1414

1515
/// **What it does:** Checks for usage of blacklisted names for variables, such
1616
/// as `foo`.

clippy_lints/src/block_in_if_condition.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
11-
use crate::rustc::hir::*;
12-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13-
use crate::rustc::{declare_tool_lint, lint_array};
1410
use crate::utils::*;
1511
use matches::matches;
12+
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
13+
use rustc::hir::*;
14+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
15+
use rustc::{declare_tool_lint, lint_array};
1616

1717
/// **What it does:** Checks for `if` conditions that use blocks to contain an
1818
/// expression.
@@ -88,11 +88,11 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks
8888

8989
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
9090
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
91-
if let ExprKind::If(ref check, ref then, _) = expr.node {
92-
if let ExprKind::Block(ref block, _) = check.node {
91+
if let ExprKind::If(check, then, _) = &expr.node {
92+
if let ExprKind::Block(block, _) = &check.node {
9393
if block.rules == DefaultBlock {
9494
if block.stmts.is_empty() {
95-
if let Some(ref ex) = block.expr {
95+
if let Some(ex) = &block.expr {
9696
// don't dig into the expression here, just suggest that they remove
9797
// the block
9898
if in_macro(expr.span) || differing_macro_contexts(expr.span, ex.span) {

0 commit comments

Comments
 (0)