mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-26 22:50:56 +00:00
redundant_closure_call: split tests into fixable
This commit is contained in:
parent
e4ff86dcd4
commit
a83a8dccba
6 changed files with 35 additions and 17 deletions
|
@ -1,5 +1,6 @@
|
||||||
use crate::utils::{
|
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 if_chain::if_chain;
|
||||||
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
|
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.",
|
"Try not to call a closure in the expression where it is declared.",
|
||||||
|db| {
|
|db| {
|
||||||
if decl.inputs.is_empty() {
|
if decl.inputs.is_empty() {
|
||||||
let hint = snippet(cx, block.span, "..").into_owned();
|
let mut app = Applicability::MachineApplicable;
|
||||||
db.span_suggestion(
|
let hint =
|
||||||
expr.span,
|
snippet_with_applicability(cx, block.span, "..", &mut app).into_owned();
|
||||||
"Try doing something like: ",
|
db.span_suggestion(expr.span, "Try doing something like: ", hint, app);
|
||||||
hint,
|
|
||||||
Applicability::MachineApplicable, // snippet
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
// non rustfixable, see redundant_closure_call_fixable.rs
|
||||||
|
|
||||||
#![warn(clippy::redundant_closure_call)]
|
#![warn(clippy::redundant_closure_call)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = (|| 42)();
|
|
||||||
|
|
||||||
let mut i = 1;
|
let mut i = 1;
|
||||||
let mut k = (|m| m + 1)(i);
|
let mut k = (|m| m + 1)(i);
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,6 @@ error: Closure called just once immediately after it was declared
|
||||||
LL | i = closure(3);
|
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.
|
error: Try not to call a closure in the expression where it is declared.
|
||||||
--> $DIR/redundant_closure_call.rs:7:17
|
--> $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);
|
LL | k = (|a, b| a * b)(1, 5);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
8
tests/ui/redundant_closure_call_fixable.fixed
Normal file
8
tests/ui/redundant_closure_call_fixable.fixed
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![warn(clippy::redundant_closure_call)]
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = 42;
|
||||||
|
}
|
8
tests/ui/redundant_closure_call_fixable.rs
Normal file
8
tests/ui/redundant_closure_call_fixable.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![warn(clippy::redundant_closure_call)]
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = (|| 42)();
|
||||||
|
}
|
10
tests/ui/redundant_closure_call_fixable.stderr
Normal file
10
tests/ui/redundant_closure_call_fixable.stderr
Normal 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
|
||||||
|
|
Loading…
Reference in a new issue