Skip to content

Commit ee1aa9a

Browse files
committed
Update clippy
1 parent 3d15d56 commit ee1aa9a

Some content is hidden

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

69 files changed

+1441
-390
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cache:
1212
directories:
1313
- $HOME/.cargo
1414
before_cache:
15-
- cargo install -Z install-upgrade cargo-cache --debug
15+
- cargo install cargo-cache --debug
1616
- find $HOME/.cargo/bin/ ! -type d -exec strip {} \;
1717
- cargo cache --autoclean
1818

@@ -28,7 +28,7 @@ install:
2828
- |
2929
if [[ -z ${INTEGRATION} ]]; then
3030
if ! rustup component add rustfmt; then
31-
cargo install -Z install-upgrade --git https://github.com/rust-lang/rustfmt --bin rustfmt
31+
cargo install --git https://github.com/rust-lang/rustfmt --bin rustfmt
3232
fi
3333
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
3434
. $HOME/.nvm/nvm.sh

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ Released 2018-09-13
10591059
[`just_underscores_and_digits`]: https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits
10601060
[`large_digit_groups`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_digit_groups
10611061
[`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
1062+
[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays
10621063
[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
10631064
[`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
10641065
[`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
@@ -1176,6 +1177,7 @@ Released 2018-09-13
11761177
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
11771178
[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used
11781179
[`reverse_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#reverse_range_loop
1180+
[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition
11791181
[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
11801182
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
11811183
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
@@ -1201,6 +1203,7 @@ Released 2018-09-13
12011203
[`suspicious_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_map
12021204
[`suspicious_op_assign_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_op_assign_impl
12031205
[`suspicious_unary_op_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_unary_op_formatting
1206+
[`tabs_in_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
12041207
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
12051208
[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
12061209
[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some
@@ -1273,4 +1276,5 @@ Released 2018-09-13
12731276
[`zero_prefixed_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_prefixed_literal
12741277
[`zero_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_ptr
12751278
[`zero_width_space`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_width_space
1279+
[`zst_offset`]: https://rust-lang.github.io/rust-clippy/master/index.html#zst_offset
12761280
<!-- end autogenerated links to lint list -->

README.md

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

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

9-
[There are 333 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 337 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

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

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cache:
1818
- '%USERPROFILE%\.cargo'
1919
# before cache
2020
after_test:
21-
- cargo install -Z install-upgrade cargo-cache --debug
21+
- cargo install cargo-cache --debug
2222
- cargo cache --autoclean
2323

2424
install:
@@ -27,7 +27,7 @@ install:
2727
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
2828
- rustup component add rustfmt --toolchain nightly & exit 0 # Format test handles missing rustfmt
2929
- del rust-toolchain
30-
- cargo install -Z install-upgrade rustup-toolchain-install-master
30+
- cargo install rustup-toolchain-install-master
3131
- rustup-toolchain-install-master -f -n master -c rustc-dev
3232
- rustup override set master
3333
- rustc -V

clippy_lints/src/bytecount.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ fn check_arg(name: Name, arg: Name, needle: &Expr) -> bool {
101101

102102
fn get_path_name(expr: &Expr) -> Option<Name> {
103103
match expr.kind {
104-
ExprKind::Box(ref e) | ExprKind::AddrOf(_, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => get_path_name(e),
104+
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => {
105+
get_path_name(e)
106+
},
105107
ExprKind::Block(ref b, _) => {
106108
if b.stmts.is_empty() {
107109
b.expr.as_ref().and_then(|p| get_path_name(p))

clippy_lints/src/copies.rs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,53 @@ declare_clippy_lint! {
4040
"consecutive `ifs` with the same condition"
4141
}
4242

43+
declare_clippy_lint! {
44+
/// **What it does:** Checks for consecutive `if`s with the same function call.
45+
///
46+
/// **Why is this bad?** This is probably a copy & paste error.
47+
/// Despite the fact that function can have side effects and `if` works as
48+
/// intended, such an approach is implicit and can be considered a "code smell".
49+
///
50+
/// **Known problems:** Hopefully none.
51+
///
52+
/// **Example:**
53+
/// ```ignore
54+
/// if foo() == bar {
55+
/// …
56+
/// } else if foo() == bar {
57+
/// …
58+
/// }
59+
/// ```
60+
///
61+
/// This probably should be:
62+
/// ```ignore
63+
/// if foo() == bar {
64+
/// …
65+
/// } else if foo() == baz {
66+
/// …
67+
/// }
68+
/// ```
69+
///
70+
/// or if the original code was not a typo and called function mutates a state,
71+
/// consider move the mutation out of the `if` condition to avoid similarity to
72+
/// a copy & paste error:
73+
///
74+
/// ```ignore
75+
/// let first = foo();
76+
/// if first == bar {
77+
/// …
78+
/// } else {
79+
/// let second = foo();
80+
/// if second == bar {
81+
/// …
82+
/// }
83+
/// }
84+
/// ```
85+
pub SAME_FUNCTIONS_IN_IF_CONDITION,
86+
pedantic,
87+
"consecutive `ifs` with the same function call"
88+
}
89+
4390
declare_clippy_lint! {
4491
/// **What it does:** Checks for `if/else` with the same body as the *then* part
4592
/// and the *else* part.
@@ -102,7 +149,7 @@ declare_clippy_lint! {
102149
"`match` with identical arm bodies"
103150
}
104151

105-
declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]);
152+
declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, SAME_FUNCTIONS_IN_IF_CONDITION, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]);
106153

107154
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
108155
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
@@ -119,6 +166,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
119166
let (conds, blocks) = if_sequence(expr);
120167
lint_same_then_else(cx, &blocks);
121168
lint_same_cond(cx, &conds);
169+
lint_same_fns_in_if_cond(cx, &conds);
122170
lint_match_arms(cx, expr);
123171
}
124172
}
@@ -163,6 +211,34 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
163211
}
164212
}
165213

214+
/// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`.
215+
fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
216+
let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 {
217+
let mut h = SpanlessHash::new(cx, cx.tables);
218+
h.hash_expr(expr);
219+
h.finish()
220+
};
221+
222+
let eq: &dyn Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool {
223+
// Do not spawn warning if `IFS_SAME_COND` already produced it.
224+
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) {
225+
return false;
226+
}
227+
SpanlessEq::new(cx).eq_expr(lhs, rhs)
228+
};
229+
230+
for (i, j) in search_same(conds, hash, eq) {
231+
span_note_and_lint(
232+
cx,
233+
SAME_FUNCTIONS_IN_IF_CONDITION,
234+
j.span,
235+
"this `if` has the same function call as a previous if",
236+
i.span,
237+
"same as this",
238+
);
239+
}
240+
}
241+
166242
/// Implementation of `MATCH_SAME_ARMS`.
167243
fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
168244
fn same_bindings<'tcx>(

clippy_lints/src/derive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ fn check_hash_peq<'a, 'tcx>(
9090
if_chain! {
9191
if match_path(&trait_ref.path, &paths::HASH);
9292
if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait();
93+
if !&trait_ref.trait_def_id().is_local();
9394
then {
9495
// Look for the PartialEq implementations for `ty`
9596
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {

clippy_lints/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn check_cond<'a, 'tcx, 'b>(
105105
if let ExprKind::MethodCall(ref path, _, ref params) = check.kind;
106106
if params.len() >= 2;
107107
if path.ident.name == sym!(contains_key);
108-
if let ExprKind::AddrOf(_, ref key) = params[1].kind;
108+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind;
109109
then {
110110
let map = &params[0];
111111
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(map));

clippy_lints/src/eq_op.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
8686
// do not suggest to dereference literals
8787
(&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {},
8888
// &foo == &bar
89-
(&ExprKind::AddrOf(_, ref l), &ExprKind::AddrOf(_, ref r)) => {
89+
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
9090
let lty = cx.tables.expr_ty(l);
9191
let rty = cx.tables.expr_ty(r);
9292
let lcpy = is_copy(cx, lty);
@@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
143143
}
144144
},
145145
// &foo == bar
146-
(&ExprKind::AddrOf(_, ref l), _) => {
146+
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => {
147147
let lty = cx.tables.expr_ty(l);
148148
let lcpy = is_copy(cx, lty);
149149
if (requires_ref || lcpy)
@@ -161,7 +161,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
161161
}
162162
},
163163
// foo == &bar
164-
(_, &ExprKind::AddrOf(_, ref r)) => {
164+
(_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
165165
let rty = cx.tables.expr_ty(r);
166166
let rcpy = is_copy(cx, rty);
167167
if (requires_ref || rcpy)

clippy_lints/src/eval_order_dependence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
328328
// ```
329329
//
330330
// TODO: fix this
331-
ExprKind::AddrOf(_, _) => {
331+
ExprKind::AddrOf(_, _, _) => {
332332
return;
333333
}
334334
_ => {}

0 commit comments

Comments
 (0)