Skip to content

Commit a86bdd3

Browse files
committed
Update clippy
1 parent 95f14a9 commit a86bdd3

18 files changed

+141
-75
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ matrix:
7878
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7979
- env: INTEGRATION=bluss/rust-itertools
8080
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
81+
- env: INTEGRATION=Marwes/combine
82+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
8183
allow_failures:
8284
- os: windows
8385
env: CARGO_INCREMENTAL=0 BASE_TESTS=true

CHANGELOG.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,59 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased / In Rust Beta or Nightly
66

7-
[1b89724...master](https://github.com/rust-lang/rust-clippy/compare/1b89724...master)
7+
[eb9f9b1...master](https://github.com/rust-lang/rust-clippy/compare/eb9f9b1...master)
8+
9+
## Rust 1.35 (beta)
10+
[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e)
11+
12+
* New lint: [`drop_bounds`] to detect `T: Drop` bounds
13+
* Rename `cyclomatic_complexity` to [`cognitive_complexity`], start work on making lint more practical for Rust code
14+
* Move [`get_unwrap`] to the restriction category
15+
* Improve suggestions for [`iter_cloned_collect`]
16+
* Improve suggestions for [`cast_lossless`] to suggest suffixed literals
17+
* Fix false positives in [`print_with_newline`] and [`write_with_newline`] pertaining to raw strings
18+
* Fix false positive in [`needless_range_loop`] pertaining to structs without a `.iter()`
19+
* Fix false positive in [`bool_comparison`] pertaining to non-bool types
20+
* Fix false positive in [`redundant_closure`] pertaining to differences in borrows
21+
* Fix false positive in [`option_map_unwrap_or`] on non-copy types
22+
* Fix false positives in [`missing_const_for_fn`] pertaining to macros and trait method impls
23+
* Fix false positive in [`needless_pass_by_value`] pertaining to procedural macros
24+
* Fix false positive in [`needless_continue`] pertaining to loop labels
25+
* Fix false positive for [`boxed_local`] pertaining to arguments moved into closures
26+
* Fix false positive for [`use_self`] in nested functions
27+
* Fix suggestion for [`expect_fun_call`] (https://github.com/rust-lang/rust-clippy/pull/3846)
28+
* Fix suggestion for [`explicit_counter_loop`] to deal with parenthesizing range variables
29+
* Fix suggestion for [`single_char_pattern`] to correctly escape single quotes
30+
* Avoid triggering [`redundant_closure`] in macros
31+
* ICE fixes: [#3805](https://github.com/rust-lang/rust-clippy/pull/3805), [#3772](https://github.com/rust-lang/rust-clippy/pull/3772), [#3741](https://github.com/rust-lang/rust-clippy/pull/3741)
32+
33+
## Rust 1.34 (2019-04-10)
34+
35+
[1b89724...1fac380](https://github.com/rust-lang/rust-clippy/compare/1b89724...1fac380)
36+
37+
* New lint: [`assertions_on_constants`] to detect for example `assert!(true)`
38+
* New lint: [`dbg_macro`] to detect uses of the `dbg!` macro
39+
* New lint: [`missing_const_for_fn`] that can suggest functions to be made `const`
40+
* New lint: [`too_many_lines`] to detect functions with excessive LOC. It can be
41+
configured using the `too-many-lines-threshold` configuration.
42+
* New lint: [`wildcard_enum_match_arm`] to check for wildcard enum matches using `_`
43+
* Expand `redundant_closure` to also work for methods (not only functions)
44+
* Fix ICEs in `vec_box`, `needless_pass_by_value` and `implicit_hasher`
45+
* Fix false positive in `cast_sign_loss`
46+
* Fix false positive in `integer_arithmetic`
47+
* Fix false positive in `unit_arg`
48+
* Fix false positives in `implicit_return`
49+
* Add suggestion to `explicit_write`
50+
* Improve suggestions for `question_mark` lint
51+
* Fix incorrect suggestion for `cast_lossless`
52+
* Fix incorrect suggestion for `expect_fun_call`
53+
* Fix incorrect suggestion for `needless_bool`
54+
* Fix incorrect suggestion for `needless_range_loop`
55+
* Fix incorrect suggestion for `use_self`
56+
* Fix incorrect suggestion for `while_let_on_iterator`
57+
* Clippy is now slightly easier to invoke in non-cargo contexts. See
58+
[#3665][pull3665] for more details.
59+
* We now have [improved documentation][adding_lints] on how to add new lints
860

961
## Rust 1.33 (2019-02-26)
1062

@@ -763,6 +815,8 @@ All notable changes to this project will be documented in this file.
763815
[`AsMut`]: https://doc.rust-lang.org/std/convert/trait.AsMut.html
764816
[`AsRef`]: https://doc.rust-lang.org/std/convert/trait.AsRef.html
765817
[configuration file]: ./rust-clippy#configuration
818+
[pull3665]: https://github.com/rust-lang/rust-clippy/pull/3665
819+
[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
766820

767821
<!-- begin autogenerated links to lint list -->
768822
[`absurd_extreme_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons

clippy_lints/src/eval_order_dependence.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc::hir::*;
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::ty;
77
use rustc::{declare_tool_lint, lint_array};
8-
use syntax::ast;
98

109
declare_clippy_lint! {
1110
/// **What it does:** Checks for a read and a write to the same variable where
@@ -287,7 +286,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> St
287286
struct ReadVisitor<'a, 'tcx: 'a> {
288287
cx: &'a LateContext<'a, 'tcx>,
289288
/// The ID of the variable we're looking for.
290-
var: ast::NodeId,
289+
var: HirId,
291290
/// The expressions where the write to the variable occurred (for reporting
292291
/// in the lint).
293292
write_expr: &'tcx Expr,

clippy_lints/src/format.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
9191
ExprKind::Match(ref matchee, _, _) => {
9292
if let ExprKind::Tup(ref tup) = matchee.node {
9393
if tup.is_empty() {
94-
let sugg = format!("{}.to_string()", snippet(cx, expr.span, "<expr>").into_owned());
94+
let actual_snippet = snippet(cx, expr.span, "<expr>").to_string();
95+
let actual_snippet = actual_snippet.replace("{{}}", "{}");
96+
let sugg = format!("{}.to_string()", actual_snippet);
9597
span_useless_format(cx, span, "consider using .to_string()", sugg);
9698
}
9799
}

clippy_lints/src/formatting.rs

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
2+
use if_chain::if_chain;
23
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintPass};
34
use rustc::{declare_tool_lint, lint_array};
45
use syntax::ast;
@@ -146,44 +147,39 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &ast::Expr) {
146147

147148
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else`.
148149
fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
149-
if let Some((then, &Some(ref else_))) = unsugar_if(expr) {
150-
if (is_block(else_) || unsugar_if(else_).is_some())
151-
&& !differing_macro_contexts(then.span, else_.span)
152-
&& !in_macro(then.span)
153-
&& !in_external_macro(cx.sess, expr.span)
154-
{
155-
// workaround for rust-lang/rust#43081
156-
if expr.span.lo().0 == 0 && expr.span.hi().0 == 0 {
157-
return;
158-
}
150+
if_chain! {
151+
if let Some((then, &Some(ref else_))) = unsugar_if(expr);
152+
if is_block(else_) || unsugar_if(else_).is_some();
153+
if !differing_macro_contexts(then.span, else_.span);
154+
if !in_macro(then.span) && !in_external_macro(cx.sess, expr.span);
159155

160-
// this will be a span from the closing ‘}’ of the “then” block (excluding) to
161-
// the
162-
// “if” of the “else if” block (excluding)
163-
let else_span = then.span.between(else_.span);
156+
// workaround for rust-lang/rust#43081
157+
if expr.span.lo().0 != 0 && expr.span.hi().0 != 0;
164158

165-
// the snippet should look like " else \n " with maybe comments anywhere
166-
// it’s bad when there is a ‘\n’ after the “else”
167-
if let Some(else_snippet) = snippet_opt(cx, else_span) {
168-
let else_pos = else_snippet.find("else").expect("there must be a `else` here");
159+
// this will be a span from the closing ‘}’ of the “then” block (excluding) to
160+
// the “if” of the “else if” block (excluding)
161+
let else_span = then.span.between(else_.span);
169162

170-
if else_snippet[else_pos..].contains('\n') {
171-
let else_desc = if unsugar_if(else_).is_some() { "if" } else { "{..}" };
163+
// the snippet should look like " else \n " with maybe comments anywhere
164+
// it’s bad when there is a ‘\n’ after the “else”
165+
if let Some(else_snippet) = snippet_opt(cx, else_span);
166+
if let Some(else_pos) = else_snippet.find("else");
167+
if else_snippet[else_pos..].contains('\n');
168+
let else_desc = if unsugar_if(else_).is_some() { "if" } else { "{..}" };
172169

173-
span_note_and_lint(
174-
cx,
175-
SUSPICIOUS_ELSE_FORMATTING,
176-
else_span,
177-
&format!("this is an `else {}` but the formatting might hide it", else_desc),
178-
else_span,
179-
&format!(
180-
"to remove this lint, remove the `else` or remove the new line between \
181-
`else` and `{}`",
182-
else_desc,
183-
),
184-
);
185-
}
186-
}
170+
then {
171+
span_note_and_lint(
172+
cx,
173+
SUSPICIOUS_ELSE_FORMATTING,
174+
else_span,
175+
&format!("this is an `else {}` but the formatting might hide it", else_desc),
176+
else_span,
177+
&format!(
178+
"to remove this lint, remove the `else` or remove the new line between \
179+
`else` and `{}`",
180+
else_desc,
181+
),
182+
);
187183
}
188184
}
189185
}

clippy_lints/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a, 'tcx: 'a> DerefVisitor<'a, 'tcx> {
327327
fn check_arg(&self, ptr: &hir::Expr) {
328328
if let hir::ExprKind::Path(ref qpath) = ptr.node {
329329
if let Def::Local(id) = self.cx.tables.qpath_def(qpath, ptr.hir_id) {
330-
if self.ptrs.contains(&self.cx.tcx.hir().node_to_hir_id(id)) {
330+
if self.ptrs.contains(&id) {
331331
span_lint(
332332
self.cx,
333333
NOT_UNSAFE_PTR_ARG_DEREF,

clippy_lints/src/let_if_seq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
150150
if_chain! {
151151
if let hir::ExprKind::Path(ref qpath) = expr.node;
152152
if let Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id);
153-
if self.id == self.cx.tcx.hir().node_to_hir_id(local_id);
153+
if self.id == local_id;
154154
then {
155155
self.used = true;
156156
return;
@@ -175,7 +175,7 @@ fn check_assign<'a, 'tcx>(
175175
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
176176
if let hir::ExprKind::Path(ref qpath) = var.node;
177177
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id);
178-
if decl == cx.tcx.hir().node_to_hir_id(local_id);
178+
if decl == local_id;
179179
then {
180180
let mut v = UsedVisitor {
181181
cx,

clippy_lints/src/loops.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bo
790790
if path.segments.len() == 1;
791791
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, expr.hir_id);
792792
// our variable!
793-
if cx.tcx.hir().node_to_hir_id(local_id) == var;
793+
if local_id == var;
794794
then {
795795
return true;
796796
}
@@ -1657,13 +1657,13 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
16571657
then {
16581658
let def = cx.tables.qpath_def(qpath, bound.hir_id);
16591659
if let Def::Local(node_id) = def {
1660-
let node_str = cx.tcx.hir().get(node_id);
1660+
let node_str = cx.tcx.hir().get_by_hir_id(node_id);
16611661
if_chain! {
16621662
if let Node::Binding(pat) = node_str;
16631663
if let PatKind::Binding(bind_ann, ..) = pat.node;
16641664
if let BindingAnnotation::Mutable = bind_ann;
16651665
then {
1666-
return Some(cx.tcx.hir().node_to_hir_id(node_id));
1666+
return Some(node_id);
16671667
}
16681668
}
16691669
}
@@ -1792,9 +1792,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17921792
}
17931793
let def = self.cx.tables.qpath_def(seqpath, seqexpr.hir_id);
17941794
match def {
1795-
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
1796-
let hir_id = self.cx.tcx.hir().node_to_hir_id(node_id);
1797-
1795+
Def::Local(hir_id) | Def::Upvar(hir_id, ..) => {
17981796
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
17991797
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
18001798
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
@@ -1856,15 +1854,15 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18561854
then {
18571855
match self.cx.tables.qpath_def(qpath, expr.hir_id) {
18581856
Def::Upvar(local_id, ..) => {
1859-
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
1857+
if local_id == self.var {
18601858
// we are not indexing anything, record that
18611859
self.nonindex = true;
18621860
}
18631861
}
18641862
Def::Local(local_id) =>
18651863
{
18661864

1867-
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
1865+
if local_id == self.var {
18681866
self.nonindex = true;
18691867
} else {
18701868
// not the correct variable, but still a variable
@@ -2209,7 +2207,7 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
22092207
if let ExprKind::Path(ref qpath) = expr.node {
22102208
let path_res = cx.tables.qpath_def(qpath, expr.hir_id);
22112209
if let Def::Local(node_id) = path_res {
2212-
return Some(cx.tcx.hir().node_to_hir_id(node_id));
2210+
return Some(node_id);
22132211
}
22142212
}
22152213
None
@@ -2404,7 +2402,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
24042402
then {
24052403
match def {
24062404
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
2407-
self.ids.insert(self.cx.tcx.hir().node_to_hir_id(node_id));
2405+
self.ids.insert(node_id);
24082406
},
24092407
Def::Static(def_id, mutable) => {
24102408
self.def_ids.insert(def_id, mutable);

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn check_expression<'a, 'tcx: 'a>(
6868
if let hir::ExprKind::Path(path) = &args[0].node;
6969
if let Def::Local(ref local) = cx.tables.qpath_def(path, args[0].hir_id);
7070
then {
71-
if arg_id == cx.tcx.hir().node_to_hir_id(*local) {
71+
if arg_id == *local {
7272
return (false, false)
7373
}
7474
}

clippy_lints/src/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ fn in_attributes_expansion(expr: &Expr) -> bool {
612612
/// Tests whether `def` is a variable defined outside a macro.
613613
fn non_macro_local(cx: &LateContext<'_, '_>, def: &def::Def) -> bool {
614614
match *def {
615-
def::Def::Local(id) | def::Def::Upvar(id, _, _) => !in_macro(cx.tcx.hir().span(id)),
615+
def::Def::Local(id) | def::Def::Upvar(id, _, _) => !in_macro(cx.tcx.hir().span_by_hir_id(id)),
616616
_ => false,
617617
}
618618
}

0 commit comments

Comments
 (0)