Skip to content

Commit

Permalink
redundant_closure_call: split tests into fixable
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 25, 2019
1 parent b1a345e commit 0cbd51b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
14 changes: 6 additions & 8 deletions clippy_lints/src/misc_early.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::utils::{
constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then,
constants, snippet_opt, snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg,
span_lint_and_then,
};
use if_chain::if_chain;
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
Expand Down Expand Up @@ -414,13 +415,10 @@ impl EarlyLintPass for MiscEarlyLints {
"Try not to call a closure in the expression where it is declared.",
|db| {
if decl.inputs.is_empty() {
let hint = snippet(cx, block.span, "..").into_owned();
db.span_suggestion(
expr.span,
"Try doing something like: ",
hint,
Applicability::MachineApplicable, // snippet
);
let mut app = Applicability::MachineApplicable;
let hint =
snippet_with_applicability(cx, block.span, "..", &mut app).into_owned();
db.span_suggestion(expr.span, "Try doing something like: ", hint, app);
}
},
);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/redundant_closure_call.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// non rustfixable, see redundant_closure_call_fixable.rs

#![warn(clippy::redundant_closure_call)]

fn main() {
let a = (|| 42)();

let mut i = 1;
let mut k = (|m| m + 1)(i);

Expand Down
8 changes: 1 addition & 7 deletions tests/ui/redundant_closure_call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ error: Closure called just once immediately after it was declared
LL | i = closure(3);
| ^^^^^^^^^^^^^^

error: Try not to call a closure in the expression where it is declared.
--> $DIR/redundant_closure_call.rs:4:13
|
LL | let a = (|| 42)();
| ^^^^^^^^^ help: Try doing something like: : `42`

error: Try not to call a closure in the expression where it is declared.
--> $DIR/redundant_closure_call.rs:7:17
|
Expand All @@ -30,5 +24,5 @@ error: Try not to call a closure in the expression where it is declared.
LL | k = (|a, b| a * b)(1, 5);
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

8 changes: 8 additions & 0 deletions tests/ui/redundant_closure_call_fixable.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-rustfix

#![warn(clippy::redundant_closure_call)]
#![allow(unused)]

fn main() {
let a = 42;
}

0 comments on commit 0cbd51b

Please sign in to comment.