Skip to content

Commit cb1ea7e

Browse files
committed
Auto merge of #4104 - Manishearth:beta-backports, r=oli-obk
Backport #4101 to beta This lint has been causing lots of problems. I'll check up on other potential beta backports when I build the new changelog r? @oli-obk
2 parents 37f5c1e + 059019a commit cb1ea7e

File tree

9 files changed

+47
-74
lines changed

9 files changed

+47
-74
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22

3-
rust: nightly
3+
rust: beta
44

55
os:
66
- linux
@@ -17,6 +17,7 @@ branches:
1717
env:
1818
global:
1919
- RUST_BACKTRACE=1
20+
- RUSTC_BOOTSTRAP=1
2021

2122
install:
2223
- |
@@ -90,7 +91,7 @@ matrix:
9091
script:
9192
- |
9293
rm rust-toolchain
93-
./setup-toolchain.sh
94+
rustup override set beta
9495
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
9596
- |
9697
if [ -z ${INTEGRATION} ]; then

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ All notable changes to this project will be documented in this file.
978978
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
979979
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
980980
[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
981+
[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
981982
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
982983
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
983984
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

README.md

Lines changed: 1 addition & 1 deletion
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 298 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 299 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

clippy_lints/src/eta_reduction.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,31 @@ declare_clippy_lint! {
3333
"redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)"
3434
}
3535

36+
declare_clippy_lint! {
37+
/// **What it does:** Checks for closures which only invoke a method on the closure
38+
/// argument and can be replaced by referencing the method directly.
39+
///
40+
/// **Why is this bad?** It's unnecessary to create the closure.
41+
///
42+
/// **Known problems:** rust-lang/rust-clippy#3071, rust-lang/rust-clippy#4002,
43+
/// rust-lang/rust-clippy#3942
44+
///
45+
/// **Example:**
46+
/// ```rust,ignore
47+
/// Some('a').map(|s| s.to_uppercase());
48+
/// ```
49+
/// may be rewritten as
50+
/// ```rust,ignore
51+
/// Some('a').map(char::to_uppercase);
52+
/// ```
53+
pub REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
54+
pedantic,
55+
"redundant closures for method calls"
56+
}
57+
3658
impl LintPass for EtaPass {
3759
fn get_lints(&self) -> LintArray {
38-
lint_array!(REDUNDANT_CLOSURE)
60+
lint_array!(REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS)
3961
}
4062

4163
fn name(&self) -> &'static str {
@@ -110,7 +132,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
110132
if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]);
111133

112134
then {
113-
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
135+
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |db| {
114136
db.span_suggestion(
115137
expr.span,
116138
"remove closure as shown",

clippy_lints/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
611611
enum_glob_use::ENUM_GLOB_USE,
612612
enum_variants::MODULE_NAME_REPETITIONS,
613613
enum_variants::PUB_ENUM_VARIANT_NAMES,
614+
eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
614615
functions::TOO_MANY_LINES,
615616
if_not_else::IF_NOT_ELSE,
616617
infinite_iter::MAYBE_INFINITE_ITER,

tests/ui/eta.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
clippy::option_map_unit_fn,
88
clippy::trivially_copy_pass_by_ref
99
)]
10-
#![warn(clippy::redundant_closure, clippy::needless_borrow)]
10+
#![warn(
11+
clippy::redundant_closure,
12+
redundant_closures_for_method_calls,
13+
clippy::needless_borrow
14+
)]
1115

1216
use std::path::PathBuf;
1317

tests/ui/eta.stderr

Lines changed: 10 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,16 @@
1-
error: redundant closure found
2-
--> $DIR/eta.rs:15:27
1+
error: unknown lint: `redundant_closures_for_method_calls`
2+
--> $DIR/eta.rs:12:5
33
|
4-
LL | let a = Some(1u8).map(|a| foo(a));
5-
| ^^^^^^^^^^ help: remove closure as shown: `foo`
4+
LL | redundant_closures_for_method_calls,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_closure_for_method_calls`
66
|
7-
= note: `-D clippy::redundant-closure` implied by `-D warnings`
7+
= note: `-D unknown-lints` implied by `-D warnings`
88

9-
error: redundant closure found
10-
--> $DIR/eta.rs:16:10
9+
error: unknown lint: `redundant_closures_for_method_calls`
10+
--> $DIR/eta.rs:12:5
1111
|
12-
LL | meta(|a| foo(a));
13-
| ^^^^^^^^^^ help: remove closure as shown: `foo`
12+
LL | redundant_closures_for_method_calls,
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_closure_for_method_calls`
1414

15-
error: redundant closure found
16-
--> $DIR/eta.rs:17:27
17-
|
18-
LL | let c = Some(1u8).map(|a| {1+2; foo}(a));
19-
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `{1+2; foo}`
20-
21-
error: this expression borrows a reference that is immediately dereferenced by the compiler
22-
--> $DIR/eta.rs:19:21
23-
|
24-
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
25-
| ^^^ help: change this to: `&2`
26-
|
27-
= note: `-D clippy::needless-borrow` implied by `-D warnings`
28-
29-
error: redundant closure found
30-
--> $DIR/eta.rs:26:27
31-
|
32-
LL | let e = Some(1u8).map(|a| generic(a));
33-
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
34-
35-
error: redundant closure found
36-
--> $DIR/eta.rs:69:51
37-
|
38-
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
39-
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
40-
41-
error: redundant closure found
42-
--> $DIR/eta.rs:71:51
43-
|
44-
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
45-
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
46-
47-
error: redundant closure found
48-
--> $DIR/eta.rs:74:42
49-
|
50-
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
51-
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
52-
53-
error: redundant closure found
54-
--> $DIR/eta.rs:79:29
55-
|
56-
LL | let e = Some("str").map(|s| s.to_string());
57-
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
58-
59-
error: redundant closure found
60-
--> $DIR/eta.rs:81:27
61-
|
62-
LL | let e = Some('a').map(|s| s.to_uppercase());
63-
| ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase`
64-
65-
error: redundant closure found
66-
--> $DIR/eta.rs:84:65
67-
|
68-
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
69-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
70-
71-
error: aborting due to 11 previous errors
15+
error: aborting due to 2 previous errors
7216

tests/ui/map_clone.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::iter_cloned_collect)]
44
#![allow(clippy::clone_on_copy)]
55
#![allow(clippy::missing_docs_in_private_items)]
6-
#![allow(clippy::redundant_closure)]
6+
#![allow(clippy::redundant_closure_for_method_calls)]
77

88
fn main() {
99
let _: Vec<i8> = vec![5_i8; 6].iter().cloned().collect();

tests/ui/map_clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::iter_cloned_collect)]
44
#![allow(clippy::clone_on_copy)]
55
#![allow(clippy::missing_docs_in_private_items)]
6-
#![allow(clippy::redundant_closure)]
6+
#![allow(clippy::redundant_closure_for_method_calls)]
77

88
fn main() {
99
let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();

0 commit comments

Comments
 (0)