Skip to content

Commit db0d014

Browse files
committed
submodules: Update clippy from 5a11ed7 to 8c80b65
1 parent 2a559e5 commit db0d014

22 files changed

+226
-100
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Build Status](https://travis-ci.com/rust-lang/rust-clippy.svg?branch=master)](https://travis-ci.com/rust-lang/rust-clippy)
44
[![Windows Build status](https://ci.appveyor.com/api/projects/status/id677xpw1dguo7iw?svg=true)](https://ci.appveyor.com/project/rust-lang-libs/rust-clippy)
5-
[![Current Version](https://meritbadge.herokuapp.com/clippy)](https://crates.io/crates/clippy)
65
[![License: MIT/Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license)
76

87
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
@@ -12,7 +11,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://g
1211
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1312

1413
* `clippy::all` (everything that is on by default: all the categories below except for `nursery`, `pedantic`, and `cargo`)
15-
* **`clippy::correctness`** (code that is just outright wrong or very very useless, causes hard errors by default)
14+
* `clippy::correctness` (code that is just **outright wrong** or **very very useless**, causes hard errors by default)
1615
* `clippy::style` (code that should be written in a more idiomatic way)
1716
* `clippy::complexity` (code that does something simple but in a complex way)
1817
* `clippy::perf` (code that can be written in a faster way)

clippy_lints/src/collapsible_if.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,14 @@ impl EarlyLintPass for CollapsibleIf {
8484
}
8585

8686
fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
87-
match expr.node {
88-
ast::ExprKind::If(ref check, ref then, ref else_) => {
89-
if let Some(ref else_) = *else_ {
90-
check_collapsible_maybe_if_let(cx, else_);
91-
} else {
92-
check_collapsible_no_if_let(cx, expr, check, then);
93-
}
94-
},
95-
ast::ExprKind::IfLet(_, _, _, Some(ref else_)) => {
87+
if let ast::ExprKind::If(check, then, else_) = &expr.node {
88+
if let Some(else_) = else_ {
9689
check_collapsible_maybe_if_let(cx, else_);
97-
},
98-
_ => (),
90+
} else if let ast::ExprKind::Let(..) = check.node {
91+
// Prevent triggering on `if let a = b { if c { .. } }`.
92+
} else {
93+
check_collapsible_no_if_let(cx, expr, check, then);
94+
}
9995
}
10096
}
10197

@@ -113,22 +109,18 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
113109
if !block_starts_with_comment(cx, block);
114110
if let Some(else_) = expr_block(block);
115111
if !in_macro_or_desugar(else_.span);
112+
if let ast::ExprKind::If(..) = else_.node;
116113
then {
117-
match else_.node {
118-
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {
119-
let mut applicability = Applicability::MachineApplicable;
120-
span_lint_and_sugg(
121-
cx,
122-
COLLAPSIBLE_IF,
123-
block.span,
124-
"this `else { if .. }` block can be collapsed",
125-
"try",
126-
snippet_block_with_applicability(cx, else_.span, "..", &mut applicability).into_owned(),
127-
applicability,
128-
);
129-
}
130-
_ => (),
131-
}
114+
let mut applicability = Applicability::MachineApplicable;
115+
span_lint_and_sugg(
116+
cx,
117+
COLLAPSIBLE_IF,
118+
block.span,
119+
"this `else { if .. }` block can be collapsed",
120+
"try",
121+
snippet_block_with_applicability(cx, else_.span, "..", &mut applicability).into_owned(),
122+
applicability,
123+
);
132124
}
133125
}
134126
}
@@ -139,6 +131,11 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
139131
if let Some(inner) = expr_block(then);
140132
if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node;
141133
then {
134+
if let ast::ExprKind::Let(..) = check_inner.node {
135+
// Prevent triggering on `if c { if let a = b { .. } }`.
136+
return;
137+
}
138+
142139
if expr.span.ctxt() != inner.span.ctxt() {
143140
return;
144141
}

clippy_lints/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Constant {
154154
}
155155

156156
/// Parses a `LitKind` to a `Constant`.
157-
pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
157+
pub fn lit_to_constant(lit: &LitKind, ty: Ty<'_>) -> Constant {
158158
use syntax::ast::*;
159159

160160
match *lit {

clippy_lints/src/formatting.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ fn is_block(expr: &ast::Expr) -> bool {
248248
/// Match `if` or `if let` expressions and return the `then` and `else` block.
249249
fn unsugar_if(expr: &ast::Expr) -> Option<(&P<ast::Block>, &Option<P<ast::Expr>>)> {
250250
match expr.node {
251-
ast::ExprKind::If(_, ref then, ref else_) | ast::ExprKind::IfLet(_, _, ref then, ref else_) => {
252-
Some((then, else_))
253-
},
251+
ast::ExprKind::If(_, ref then, ref else_) => Some((then, else_)),
254252
_ => None,
255253
}
256254
}

clippy_lints/src/identity_conversion.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
5050
};
5151
if let ExprKind::Call(_, ref args) = e.node {
5252
self.try_desugar_arm.push(args[0].hir_id);
53-
} else {
54-
return;
5553
}
5654
},
5755

clippy_lints/src/invalid_ref.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,5 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef {
5151
span_help_and_lint(cx, INVALID_REF, expr.span, msg, HELP);
5252
}
5353
}
54-
return;
5554
}
5655
}

clippy_lints/src/loops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
16471647
then {
16481648
let res = cx.tables.qpath_res(qpath, bound.hir_id);
16491649
if let Res::Local(node_id) = res {
1650-
let node_str = cx.tcx.hir().get_by_hir_id(node_id);
1650+
let node_str = cx.tcx.hir().get(node_id);
16511651
if_chain! {
16521652
if let Node::Binding(pat) = node_str;
16531653
if let PatKind::Binding(bind_ann, ..) = pat.node;

clippy_lints/src/methods/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
14241424
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
14251425
} else {
14261426
let parent = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
1427-
match cx.tcx.hir().get_by_hir_id(parent) {
1427+
match cx.tcx.hir().get(parent) {
14281428
hir::Node::Expr(parent) => match parent.node {
14291429
// &*x is a nop, &x.clone() is not
14301430
hir::ExprKind::AddrOf(..) |
@@ -1648,16 +1648,15 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
16481648
);
16491649

16501650
// Check if the first argument to .fold is a suitable literal
1651-
match fold_args[1].node {
1652-
hir::ExprKind::Lit(ref lit) => match lit.node {
1651+
if let hir::ExprKind::Lit(ref lit) = fold_args[1].node {
1652+
match lit.node {
16531653
ast::LitKind::Bool(false) => check_fold_with_op(cx, fold_args, hir::BinOpKind::Or, "any", true),
16541654
ast::LitKind::Bool(true) => check_fold_with_op(cx, fold_args, hir::BinOpKind::And, "all", true),
16551655
ast::LitKind::Int(0, _) => check_fold_with_op(cx, fold_args, hir::BinOpKind::Add, "sum", false),
16561656
ast::LitKind::Int(1, _) => check_fold_with_op(cx, fold_args, hir::BinOpKind::Mul, "product", false),
1657-
_ => return,
1658-
},
1659-
_ => return,
1660-
};
1657+
_ => (),
1658+
}
1659+
}
16611660
}
16621661

16631662
fn lint_iter_nth<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_args: &'tcx [hir::Expr], is_mut: bool) {

clippy_lints/src/missing_inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute]
6868
}
6969
}
7070

71-
fn is_executable<'a, 'tcx>(cx: &LateContext<'a, 'tcx>) -> bool {
71+
fn is_executable(cx: &LateContext<'_, '_>) -> bool {
7272
use rustc::session::config::CrateType;
7373

7474
cx.tcx.sess.crate_types.get().iter().any(|t: &CrateType| match t {

clippy_lints/src/needless_bool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
116116

117117
fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool {
118118
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
119-
let parent_node = cx.tcx.hir().get_by_hir_id(parent_id);
119+
let parent_node = cx.tcx.hir().get(parent_id);
120120

121121
if let rustc::hir::Node::Expr(e) = parent_node {
122122
if higher::if_block(&e).is_some() {

0 commit comments

Comments
 (0)