redundant_closure_call: split tests into fixable

This commit is contained in:
Manish Goregaokar 2019-09-25 09:30:27 -07:00
parent e4ff86dcd4
commit a83a8dccba
6 changed files with 35 additions and 17 deletions

View file

@ -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};
@ -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);
}
},
);

View file

@ -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);

View file

@ -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
|
@ -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

View file

@ -0,0 +1,8 @@
// run-rustfix
#![warn(clippy::redundant_closure_call)]
#![allow(unused)]
fn main() {
let a = 42;
}

View file

@ -0,0 +1,8 @@
// run-rustfix
#![warn(clippy::redundant_closure_call)]
#![allow(unused)]
fn main() {
let a = (|| 42)();
}

View file

@ -0,0 +1,10 @@
error: Try not to call a closure in the expression where it is declared.
--> $DIR/redundant_closure_call_fixable.rs:7:13
|
LL | let a = (|| 42)();
| ^^^^^^^^^ help: Try doing something like: : `42`
|
= note: `-D clippy::redundant-closure-call` implied by `-D warnings`
error: aborting due to previous error