Skip to content

Commit 8c540dc

Browse files
committed
Improve the redundant_closure message
1 parent bf98aa6 commit 8c540dc

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

clippy_lints/src/eta_reduction.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
9999
cx,
100100
REDUNDANT_CLOSURE,
101101
expr.span,
102-
"redundant closure found",
103-
"remove closure as shown",
102+
"redundant closure",
103+
"replace the closure with `Vec::new`",
104104
"std::vec::Vec::new".into(),
105105
Applicability::MachineApplicable,
106106
);
@@ -129,11 +129,11 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
129129
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter());
130130

131131
then {
132-
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |diag| {
132+
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
133133
if let Some(snippet) = snippet_opt(cx, caller.span) {
134134
diag.span_suggestion(
135135
expr.span,
136-
"remove closure as shown",
136+
"replace the closure with the function itself",
137137
snippet,
138138
Applicability::MachineApplicable,
139139
);
@@ -163,8 +163,8 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
163163
cx,
164164
REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
165165
expr.span,
166-
"redundant closure found",
167-
"remove closure as shown",
166+
"redundant closure",
167+
"replace the closure with the method itself",
168168
format!("{}::{}", name, path.ident.name),
169169
Applicability::MachineApplicable,
170170
);

tests/ui/eta.stderr

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
error: redundant closure found
1+
error: redundant closure
22
--> $DIR/eta.rs:32:27
33
|
44
LL | let a = Some(1u8).map(|a| foo(a));
5-
| ^^^^^^^^^^ help: remove closure as shown: `foo`
5+
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
66
|
77
= note: `-D clippy::redundant-closure` implied by `-D warnings`
88

9-
error: redundant closure found
9+
error: redundant closure
1010
--> $DIR/eta.rs:33:10
1111
|
1212
LL | meta(|a| foo(a));
13-
| ^^^^^^^^^^ help: remove closure as shown: `foo`
13+
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
1414

15-
error: redundant closure found
15+
error: redundant closure
1616
--> $DIR/eta.rs:37:40
1717
|
1818
LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec!
19-
| ^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::new`
19+
| ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
2020

2121
error: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler
2222
--> $DIR/eta.rs:39:21
@@ -26,61 +26,61 @@ LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
2626
|
2727
= note: `-D clippy::needless-borrow` implied by `-D warnings`
2828

29-
error: redundant closure found
29+
error: redundant closure
3030
--> $DIR/eta.rs:46:27
3131
|
3232
LL | let e = Some(1u8).map(|a| generic(a));
33-
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
33+
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
3434

35-
error: redundant closure found
35+
error: redundant closure
3636
--> $DIR/eta.rs:89:51
3737
|
3838
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
39-
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
39+
| ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo`
4040
|
4141
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
4242

43-
error: redundant closure found
43+
error: redundant closure
4444
--> $DIR/eta.rs:91:51
4545
|
4646
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
47-
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
47+
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo`
4848

49-
error: redundant closure found
49+
error: redundant closure
5050
--> $DIR/eta.rs:94:42
5151
|
5252
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
53-
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
53+
| ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear`
5454

55-
error: redundant closure found
55+
error: redundant closure
5656
--> $DIR/eta.rs:99:29
5757
|
5858
LL | let e = Some("str").map(|s| s.to_string());
59-
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
59+
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
6060

61-
error: redundant closure found
61+
error: redundant closure
6262
--> $DIR/eta.rs:101:27
6363
|
6464
LL | let e = Some('a').map(|s| s.to_uppercase());
65-
| ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase`
65+
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase`
6666

67-
error: redundant closure found
67+
error: redundant closure
6868
--> $DIR/eta.rs:104:65
6969
|
7070
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
71-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase`
7272

73-
error: redundant closure found
73+
error: redundant closure
7474
--> $DIR/eta.rs:187:27
7575
|
7676
LL | let a = Some(1u8).map(|a| foo_ptr(a));
77-
| ^^^^^^^^^^^^^^ help: remove closure as shown: `foo_ptr`
77+
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr`
7878

79-
error: redundant closure found
79+
error: redundant closure
8080
--> $DIR/eta.rs:192:27
8181
|
8282
LL | let a = Some(1u8).map(|a| closure(a));
83-
| ^^^^^^^^^^^^^^ help: remove closure as shown: `closure`
83+
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure`
8484

8585
error: aborting due to 13 previous errors
8686

0 commit comments

Comments
 (0)