chore: use multipart_suggestions for manual_async_fn (#13788)
This addresses #13099 for the manual_async_fn test. changelog: [manual_async_fn]: Updated manual_async_fn to use multipart_suggestions where appropriate
This commit is contained in:
commit
c4aeb32f1d
4 changed files with 166 additions and 108 deletions
|
|
@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
|
|||
if let Some(vis_snip) = vis_span.get_source_text(cx)
|
||||
&& let Some(header_snip) = header_span.get_source_text(cx)
|
||||
&& let Some(ret_pos) = position_before_rarrow(&header_snip)
|
||||
&& let Some((ret_sugg, ret_snip)) = suggested_ret(cx, output)
|
||||
&& let Some((_, ret_snip)) = suggested_ret(cx, output)
|
||||
{
|
||||
let header_snip = if vis_snip.is_empty() {
|
||||
format!("async {}", &header_snip[..ret_pos])
|
||||
|
|
@ -82,19 +82,14 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
|
|||
format!("{} async {}", vis_snip, &header_snip[vis_snip.len() + 1..ret_pos])
|
||||
};
|
||||
|
||||
let help = format!("make the function `async` and {ret_sugg}");
|
||||
diag.span_suggestion(
|
||||
header_span,
|
||||
help,
|
||||
format!("{header_snip}{ret_snip}"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block.span)).to_string();
|
||||
|
||||
let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block.span));
|
||||
diag.span_suggestion(
|
||||
block.span,
|
||||
"move the body of the async block to the enclosing function",
|
||||
body_snip,
|
||||
diag.multipart_suggestion(
|
||||
"make the function `async` and return the output of the future directly",
|
||||
vec![
|
||||
(header_span, format!("{header_snip}{ret_snip}")),
|
||||
(block.span, body_snip),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue