Skip to content

Commit 443fd14

Browse files
committed
Use Sugg for redundant_closure_call implementation
1 parent 6d60066 commit 443fd14

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

clippy_lints/src/redundant_closure_call.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
2-
use clippy_utils::source::snippet_with_applicability;
2+
use clippy_utils::sugg::Sugg;
33
use if_chain::if_chain;
44
use rustc_ast::ast;
55
use rustc_ast::visit as ast_visit;
@@ -81,18 +81,19 @@ impl EarlyLintPass for RedundantClosureCall {
8181
"try not to call a closure in the expression where it is declared",
8282
|diag| {
8383
if decl.inputs.is_empty() {
84-
let mut app = Applicability::MachineApplicable;
85-
let mut hint =
86-
snippet_with_applicability(cx, block.span, "..", &mut app).into_owned();
84+
let app = Applicability::MachineApplicable;
85+
let mut hint = Sugg::ast(cx, block, "..");
86+
8787
if r#async.is_async() {
88-
if let ast::ExprKind::Block(_, _) = block.kind {
89-
hint = format!("async {}", hint);
90-
} else {
91-
// `async x` is a syntax error, so it becomes `async { x }`
92-
hint = format!("async {{ {} }}", hint);
88+
// `async x` is a syntax error, so it becomes `async { x }`
89+
if !matches!(block.kind, ast::ExprKind::Block(_, _)) {
90+
hint = hint.blockify();
9391
}
92+
93+
hint = hint.asyncify();
9494
}
95-
diag.span_suggestion(expr.span, "try doing something like", hint, app);
95+
96+
diag.span_suggestion(expr.span, "try doing something like", hint.to_string(), app);
9697
}
9798
},
9899
);

0 commit comments

Comments
 (0)