Skip to content

Commit e429763

Browse files
committed
Update Clippy
1 parent 1d02bd0 commit e429763

File tree

119 files changed

+1232
-775
lines changed

Some content is hidden

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

119 files changed

+1232
-775
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ matrix:
5656
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
5757
- env: INTEGRATION=rust-lang-nursery/chalk
5858
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
59-
- env: INTEGRATION=rust-lang/rls
60-
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
59+
# - env: INTEGRATION=rust-lang/rls
60+
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6161
- env: INTEGRATION=Geal/nom
6262
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6363
- env: INTEGRATION=rust-lang/rustfmt
@@ -82,7 +82,10 @@ matrix:
8282
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
8383
- env: INTEGRATION=chronotope/chrono
8484
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
85-
# prevent these jobs with default env vars
85+
allow_failures:
86+
- os: windows
87+
env: CARGO_INCREMENTAL=0 BASE_TESTS=true OS_WINDOWS=true
88+
# prevent these jobs with default env vars
8689
exclude:
8790
- os: linux
8891
- os: osx

CHANGELOG.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,51 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased / In Rust Beta or Nightly
66

7-
[01ab9fe6...master](https://github.com/rust-lang/rust-clippy/compare/01ab9fe6...master)
7+
[72da101...master](https://github.com/rust-lang/rust-clippy/compare/72da101...master)
88

9+
## Rust 1.38
10+
11+
Current Beta
12+
13+
[e3cb40e...72da101](https://github.com/rust-lang/rust-clippy/compare/e3cb40e...72da101)
14+
15+
## Rust 1.37
16+
17+
Current stable, released 2019-08-15
18+
19+
[082cfa7...e3cb40e](https://github.com/rust-lang/rust-clippy/compare/082cfa7...e3cb40e)
20+
21+
* New Lints:
22+
* [`checked_conversions`] [#4088](https://github.com/rust-lang/rust-clippy/pull/4088)
23+
* [`get_last_with_len`] [#3832](https://github.com/rust-lang/rust-clippy/pull/3832)
24+
* [`integer_division`] [#4195](https://github.com/rust-lang/rust-clippy/pull/4195)
25+
* Renamed Lint: `const_static_lifetime` is now called [`redundant_static_lifetimes`].
26+
The lint now covers statics in addition to consts [#4162](https://github.com/rust-lang/rust-clippy/pull/4162)
27+
* [`match_same_arms`] now warns for all identical arms, instead of only the first one [#4102](https://github.com/rust-lang/rust-clippy/pull/4102)
28+
* [`needless_return`] now works with void functions [#4220](https://github.com/rust-lang/rust-clippy/pull/4220)
29+
* Fix false positive in [`redundant_closure`] [#4190](https://github.com/rust-lang/rust-clippy/pull/4190)
30+
* Fix false positive in [`useless_attribute`] [#4107](https://github.com/rust-lang/rust-clippy/pull/4107)
31+
* Fix incorrect suggestion for [`float_cmp`] [#4214](https://github.com/rust-lang/rust-clippy/pull/4214)
32+
* Add suggestions for [`print_with_newline`] and [`write_with_newline`] [#4136](https://github.com/rust-lang/rust-clippy/pull/4136)
33+
* Improve suggestions for [`option_map_unwrap_or_else`] and [`result_map_unwrap_or_else`] [#4164](https://github.com/rust-lang/rust-clippy/pull/4164)
34+
* Improve suggestions for [`non_ascii_literal`] [#4119](https://github.com/rust-lang/rust-clippy/pull/4119)
35+
* Improve diagnostics for [`let_and_return`] [#4137](https://github.com/rust-lang/rust-clippy/pull/4137)
36+
* Improve diagnostics for [`trivially_copy_pass_by_ref`] [#4071](https://github.com/rust-lang/rust-clippy/pull/4071)
37+
* Add macro check for [`unreadable_literal`] [#4099](https://github.com/rust-lang/rust-clippy/pull/4099)
938

1039
## Rust 1.36
1140

12-
Current beta
41+
Released 2019-07-04
1342

14-
[eb9f9b1...71be6f62](https://github.com/rust-lang/rust-clippy/compare/eb9f9b1...71be6f62)
43+
[eb9f9b1...082cfa7](https://github.com/rust-lang/rust-clippy/compare/eb9f9b1...082cfa7)
1544

1645
* New lints: [`find_map`], [`filter_map_next`] [#4039](https://github.com/rust-lang/rust-clippy/pull/4039)
1746
* New lint: [`path_buf_push_overwrite`] [#3954](https://github.com/rust-lang/rust-clippy/pull/3954)
1847
* Move `path_buf_push_overwrite` to the nursery [#4013](https://github.com/rust-lang/rust-clippy/pull/4013)
1948
* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101)
2049
* Allow allowing of [`toplevel_ref_arg`] lint [#4007](https://github.com/rust-lang/rust-clippy/pull/4007)
2150
* Fix false negative in [`or_fun_call`] pertaining to nested constructors [#4084](https://github.com/rust-lang/rust-clippy/pull/4084)
22-
* Fixed false positive in [`or_fn_call`] pertaining to enum variant constructors [#4018](https://github.com/rust-lang/rust-clippy/pull/4018)
51+
* Fix false positive in [`or_fn_call`] pertaining to enum variant constructors [#4018](https://github.com/rust-lang/rust-clippy/pull/4018)
2352
* Fix false positive in [`useless_let_if_seq`] pertaining to interior mutability [#4035](https://github.com/rust-lang/rust-clippy/pull/4035)
2453
* Fix false positive in [`redundant_closure`] pertaining to non-function types [#4008](https://github.com/rust-lang/rust-clippy/pull/4008)
2554
* Fix false positive in [`let_and_return`] pertaining to attributes on `let`s [#4024](https://github.com/rust-lang/rust-clippy/pull/4024)
@@ -40,7 +69,7 @@ Current beta
4069

4170
## Rust 1.35
4271

43-
Current stable, released 2019-05-20
72+
Released 2019-05-20
4473

4574
[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e)
4675

@@ -947,6 +976,7 @@ Released 2018-09-13
947976
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
948977
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
949978
[`find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#find_map
979+
[`flat_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_identity
950980
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
951981
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
952982
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const
@@ -982,6 +1012,7 @@ Released 2018-09-13
9821012
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
9831013
[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array
9841014
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
1015+
[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref
9851016
[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex
9861017
[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
9871018
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
@@ -1057,6 +1088,7 @@ Released 2018-09-13
10571088
[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
10581089
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
10591090
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
1091+
[`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some
10601092
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none
10611093
[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
10621094
[`option_map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or
@@ -1121,6 +1153,7 @@ Released 2018-09-13
11211153
[`suspicious_arithmetic_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_arithmetic_impl
11221154
[`suspicious_assignment_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_assignment_formatting
11231155
[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting
1156+
[`suspicious_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_map
11241157
[`suspicious_op_assign_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_op_assign_impl
11251158
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
11261159
[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Hello fellow Rustacean! Great to see your interest in compiler internals and lin
77
Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document explains how
88
you can contribute and how to get started.
99
If you have any questions about contributing or need help with anything, feel free to ask questions on issues or
10-
visit the `#clippy` IRC channel on `irc.mozilla.org` or meet us in `#wg-clippy` on [Discord](https://discord.gg/rust-lang).
10+
visit the `#clippy` IRC channel on `irc.mozilla.org` or meet us in `#clippy` on [Discord](https://discord.gg/rust-lang).
1111

1212
All contributors are expected to follow the [Rust Code of Conduct](http://www.rust-lang.org/conduct.html).
1313

@@ -90,7 +90,7 @@ Clippy is a [rustc compiler plugin][compiler_plugin]. The main entry point is at
9090
pub mod else_if_without_else;
9191
// ...
9292

93-
pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
93+
pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry) {
9494
// ...
9595
reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
9696
// ...
@@ -103,7 +103,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
103103
}
104104
```
105105

106-
The [`rustc_plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
106+
The [`plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
107107
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
108108
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
109109

@@ -193,9 +193,9 @@ or the [MIT](http://opensource.org/licenses/MIT) license.
193193
[lint_crate_entry]: https://github.com/rust-lang/rust-clippy/blob/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/clippy_lints/src/lib.rs
194194
[else_if_without_else]: https://github.com/rust-lang/rust-clippy/blob/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/clippy_lints/src/else_if_without_else.rs
195195
[compiler_plugin]: https://doc.rust-lang.org/unstable-book/language-features/plugin.html#lint-plugins
196-
[plugin_registry]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin/registry/struct.Registry.html
197-
[reg_early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin/registry/struct.Registry.html#method.register_early_lint_pass
198-
[reg_late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin/registry/struct.Registry.html#method.register_late_lint_pass
196+
[plugin_registry]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html
197+
[reg_early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html#method.register_early_lint_pass
198+
[reg_late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html#method.register_late_lint_pass
199199
[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/trait.EarlyLintPass.html
200200
[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/trait.LateLintPass.html
201201
[toolstate_commit_history]: https://github.com/rust-lang-nursery/rust-toolstate/commits/master

PUBLISH.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

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 309 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 311 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

clippy_dev/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
123123
lints
124124
.iter()
125125
.filter_map(|l| {
126-
l.clone().deprecation.and_then(|depr_text| {
127-
Some(vec![
126+
l.clone().deprecation.map(|depr_text| {
127+
vec![
128128
" store.register_removed(".to_string(),
129-
format!(" \"{}\",", l.name),
129+
format!(" \"clippy::{}\",", l.name),
130130
format!(" \"{}\",", depr_text),
131131
" );".to_string(),
132-
])
132+
]
133133
})
134134
})
135135
.flatten()
@@ -442,11 +442,11 @@ fn test_gen_deprecated() {
442442
];
443443
let expected: Vec<String> = vec![
444444
" store.register_removed(",
445-
" \"should_assert_eq\",",
445+
" \"clippy::should_assert_eq\",",
446446
" \"has been superseded by should_assert_eq2\",",
447447
" );",
448448
" store.register_removed(",
449-
" \"another_deprecated\",",
449+
" \"clippy::another_deprecated\",",
450450
" \"will be removed\",",
451451
" );",
452452
]

clippy_lints/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ quine-mc_cluskey = "0.2.2"
2525
regex-syntax = "0.6"
2626
semver = "0.9.0"
2727
serde = { version = "1.0", features = ["derive"] }
28-
toml = "0.5"
28+
toml = "0.5.3"
2929
unicode-normalization = "0.1"
3030
pulldown-cmark = "0.5.3"
31-
url = "1.7.0"
31+
url = { version = "2.1.0", features = ["serde"] } # cargo requires serde feat in its url dep
32+
# see https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864
3233
if_chain = "1.0.0"
3334
smallvec = { version = "0.6.5", features = ["union"] }
3435

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use if_chain::if_chain;
21
use rustc::hir::{Expr, ExprKind};
32
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
43
use rustc::{declare_lint_pass, declare_tool_lint};
5-
use syntax_pos::Span;
64

75
use crate::consts::{constant, Constant};
8-
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};
6+
use crate::utils::{is_direct_expn_of, is_expn_of, span_help_and_lint};
97

108
declare_clippy_lint! {
119
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
@@ -33,42 +31,39 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3331

3432
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
3533
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
36-
let mut is_debug_assert = false;
37-
let debug_assert_not_in_macro_or_desugar = |span: Span| {
38-
is_debug_assert = true;
39-
// Check that `debug_assert!` itself is not inside a macro
40-
!in_macro_or_desugar(span)
41-
};
42-
if_chain! {
43-
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
44-
if !in_macro_or_desugar(assert_span)
45-
|| is_direct_expn_of(assert_span, "debug_assert")
46-
.map_or(false, debug_assert_not_in_macro_or_desugar);
47-
if let ExprKind::Unary(_, ref lit) = e.node;
48-
if let Some(bool_const) = constant(cx, cx.tables, lit);
49-
then {
50-
match bool_const.0 {
51-
Constant::Bool(true) => {
34+
let lint_assert_cb = |is_debug_assert: bool| {
35+
if let ExprKind::Unary(_, ref lit) = e.node {
36+
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit) {
37+
if is_true {
5238
span_help_and_lint(
5339
cx,
5440
ASSERTIONS_ON_CONSTANTS,
5541
e.span,
5642
"`assert!(true)` will be optimized out by the compiler",
57-
"remove it"
43+
"remove it",
5844
);
59-
},
60-
Constant::Bool(false) if !is_debug_assert => {
45+
} else if !is_debug_assert {
6146
span_help_and_lint(
6247
cx,
6348
ASSERTIONS_ON_CONSTANTS,
6449
e.span,
6550
"`assert!(false)` should probably be replaced",
66-
"use `panic!()` or `unreachable!()`"
51+
"use `panic!()` or `unreachable!()`",
6752
);
68-
},
69-
_ => (),
53+
}
7054
}
7155
}
56+
};
57+
if let Some(debug_assert_span) = is_expn_of(e.span, "debug_assert") {
58+
if debug_assert_span.from_expansion() {
59+
return;
60+
}
61+
lint_assert_cb(true);
62+
} else if let Some(assert_span) = is_direct_expn_of(e.span, "assert") {
63+
if assert_span.from_expansion() {
64+
return;
65+
}
66+
lint_assert_cb(false);
7267
}
7368
}
7469
}

clippy_lints/src/attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::reexport::*;
44
use crate::utils::{
5-
in_macro_or_desugar, is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint,
6-
span_lint_and_sugg, span_lint_and_then, without_block_comments,
5+
is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg,
6+
span_lint_and_then, without_block_comments,
77
};
88
use if_chain::if_chain;
99
use rustc::hir::*;
@@ -412,7 +412,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
412412
}
413413

414414
fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) {
415-
if in_macro_or_desugar(span) {
415+
if span.from_expansion() {
416416
return;
417417
}
418418

clippy_lints/src/block_in_if_condition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
5454
if let ExprKind::Closure(_, _, eid, _, _) = expr.node {
5555
let body = self.cx.tcx.hir().body(eid);
5656
let ex = &body.value;
57-
if matches!(ex.node, ExprKind::Block(_, _)) && !in_macro_or_desugar(body.value.span) {
57+
if matches!(ex.node, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
5858
self.found_block = Some(ex);
5959
return;
6060
}
@@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
7979
if let Some(ex) = &block.expr {
8080
// don't dig into the expression here, just suggest that they remove
8181
// the block
82-
if in_macro_or_desugar(expr.span) || differing_macro_contexts(expr.span, ex.span) {
82+
if expr.span.from_expansion() || differing_macro_contexts(expr.span, ex.span) {
8383
return;
8484
}
8585
span_help_and_lint(
@@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
9696
}
9797
} else {
9898
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
99-
if in_macro_or_desugar(span) || differing_macro_contexts(expr.span, span) {
99+
if span.from_expansion() || differing_macro_contexts(expr.span, span) {
100100
return;
101101
}
102102
// move block higher

0 commit comments

Comments
 (0)