|
1 | 1 | use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
|
2 |
| -use clippy_utils::source::snippet_with_applicability; |
| 2 | +use clippy_utils::sugg::Sugg; |
3 | 3 | use if_chain::if_chain;
|
4 | 4 | use rustc_ast::ast;
|
5 | 5 | use rustc_ast::visit as ast_visit;
|
@@ -81,18 +81,19 @@ impl EarlyLintPass for RedundantClosureCall {
|
81 | 81 | "try not to call a closure in the expression where it is declared",
|
82 | 82 | |diag| {
|
83 | 83 | 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 | + |
87 | 87 | 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(); |
93 | 91 | }
|
| 92 | + |
| 93 | + hint = hint.asyncify(); |
94 | 94 | }
|
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); |
96 | 97 | }
|
97 | 98 | },
|
98 | 99 | );
|
|
0 commit comments