mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
point to await
expr in note
This commit is contained in:
parent
3eeeaa2bc7
commit
8ef6240afb
2 changed files with 15 additions and 7 deletions
|
@ -44,7 +44,7 @@ struct AsyncFnVisitor<'a, 'tcx> {
|
||||||
found_await: bool,
|
found_await: bool,
|
||||||
/// Also keep track of `await`s in nested async blocks so we can mention
|
/// Also keep track of `await`s in nested async blocks so we can mention
|
||||||
/// it in a note
|
/// it in a note
|
||||||
found_await_in_async_block: bool,
|
await_in_async_block: Option<Span>,
|
||||||
async_depth: usize,
|
async_depth: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +55,8 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> {
|
||||||
if let ExprKind::Yield(_, YieldSource::Await { .. }) = ex.kind {
|
if let ExprKind::Yield(_, YieldSource::Await { .. }) = ex.kind {
|
||||||
if self.async_depth == 1 {
|
if self.async_depth == 1 {
|
||||||
self.found_await = true;
|
self.found_await = true;
|
||||||
} else {
|
} else if self.await_in_async_block.is_none() {
|
||||||
self.found_await_in_async_block = true;
|
self.await_in_async_block = Some(ex.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
walk_expr(self, ex);
|
walk_expr(self, ex);
|
||||||
|
@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
|
||||||
cx,
|
cx,
|
||||||
found_await: false,
|
found_await: false,
|
||||||
async_depth: 0,
|
async_depth: 0,
|
||||||
found_await_in_async_block: false,
|
await_in_async_block: None,
|
||||||
};
|
};
|
||||||
walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), def_id);
|
walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), def_id);
|
||||||
if !visitor.found_await {
|
if !visitor.found_await {
|
||||||
|
@ -108,8 +108,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
|
||||||
|diag| {
|
|diag| {
|
||||||
diag.help("consider removing the `async` from this function");
|
diag.help("consider removing the `async` from this function");
|
||||||
|
|
||||||
if visitor.found_await_in_async_block {
|
if let Some(span) = visitor.await_in_async_block {
|
||||||
diag.note("`await` used in an async block, which does not require the enclosing function to be `async`");
|
diag.span_note(
|
||||||
|
span,
|
||||||
|
"`await` used in an async block, which does not require \
|
||||||
|
the enclosing function to be `async`",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,7 +9,11 @@ LL | | }
|
||||||
| |_____^
|
| |_____^
|
||||||
|
|
|
|
||||||
= help: consider removing the `async` from this function
|
= help: consider removing the `async` from this function
|
||||||
= note: `await` used in an async block, which does not require the enclosing function to be `async`
|
note: `await` used in an async block, which does not require the enclosing function to be `async`
|
||||||
|
--> $DIR/unused_async.rs:13:23
|
||||||
|
|
|
||||||
|
LL | ready(()).await;
|
||||||
|
| ^^^^^
|
||||||
= note: `-D clippy::unused-async` implied by `-D warnings`
|
= note: `-D clippy::unused-async` implied by `-D warnings`
|
||||||
|
|
||||||
error: unused `async` for function with no await statements
|
error: unused `async` for function with no await statements
|
||||||
|
|
Loading…
Reference in a new issue