Skip to content

Commit 0cbd51b

Browse files
committed
redundant_closure_call: split tests into fixable
1 parent b1a345e commit 0cbd51b

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

clippy_lints/src/misc_early.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::utils::{
2-
constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then,
2+
constants, snippet_opt, snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg,
3+
span_lint_and_then,
34
};
45
use if_chain::if_chain;
56
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
@@ -414,13 +415,10 @@ impl EarlyLintPass for MiscEarlyLints {
414415
"Try not to call a closure in the expression where it is declared.",
415416
|db| {
416417
if decl.inputs.is_empty() {
417-
let hint = snippet(cx, block.span, "..").into_owned();
418-
db.span_suggestion(
419-
expr.span,
420-
"Try doing something like: ",
421-
hint,
422-
Applicability::MachineApplicable, // snippet
423-
);
418+
let mut app = Applicability::MachineApplicable;
419+
let hint =
420+
snippet_with_applicability(cx, block.span, "..", &mut app).into_owned();
421+
db.span_suggestion(expr.span, "Try doing something like: ", hint, app);
424422
}
425423
},
426424
);

tests/ui/redundant_closure_call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
// non rustfixable, see redundant_closure_call_fixable.rs
2+
13
#![warn(clippy::redundant_closure_call)]
24

35
fn main() {
4-
let a = (|| 42)();
5-
66
let mut i = 1;
77
let mut k = (|m| m + 1)(i);
88

tests/ui/redundant_closure_call.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ error: Closure called just once immediately after it was declared
1212
LL | i = closure(3);
1313
| ^^^^^^^^^^^^^^
1414

15-
error: Try not to call a closure in the expression where it is declared.
16-
--> $DIR/redundant_closure_call.rs:4:13
17-
|
18-
LL | let a = (|| 42)();
19-
| ^^^^^^^^^ help: Try doing something like: : `42`
20-
2115
error: Try not to call a closure in the expression where it is declared.
2216
--> $DIR/redundant_closure_call.rs:7:17
2317
|
@@ -30,5 +24,5 @@ error: Try not to call a closure in the expression where it is declared.
3024
LL | k = (|a, b| a * b)(1, 5);
3125
| ^^^^^^^^^^^^^^^^^^^^
3226

33-
error: aborting due to 5 previous errors
27+
error: aborting due to 4 previous errors
3428

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-rustfix
2+
3+
#![warn(clippy::redundant_closure_call)]
4+
#![allow(unused)]
5+
6+
fn main() {
7+
let a = 42;
8+
}

0 commit comments

Comments
 (0)