replace HashMap with Vec, use span_lint_hir_and_then
This commit is contained in:
parent
37b83660bc
commit
482d5fafc9
@ -1,6 +1,5 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
||||||
use clippy_utils::is_def_id_trait_method;
|
use clippy_utils::is_def_id_trait_method;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::intravisit::{walk_body, walk_expr, walk_fn, FnKind, Visitor};
|
use rustc_hir::intravisit::{walk_body, walk_expr, walk_fn, FnKind, Visitor};
|
||||||
use rustc_hir::{Body, Expr, ExprKind, FnDecl, Node, YieldSource};
|
use rustc_hir::{Body, Expr, ExprKind, FnDecl, Node, YieldSource};
|
||||||
@ -47,11 +46,12 @@ pub struct UnusedAsync {
|
|||||||
async_fns_as_value: LocalDefIdSet,
|
async_fns_as_value: LocalDefIdSet,
|
||||||
/// Functions with unused `async`, linted post-crate after we've found all uses of local async
|
/// Functions with unused `async`, linted post-crate after we've found all uses of local async
|
||||||
/// functions
|
/// functions
|
||||||
unused_async_fns: FxHashMap<LocalDefId, UnusedAsyncFn>,
|
unused_async_fns: Vec<UnusedAsyncFn>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct UnusedAsyncFn {
|
struct UnusedAsyncFn {
|
||||||
|
def_id: LocalDefId,
|
||||||
fn_span: Span,
|
fn_span: Span,
|
||||||
await_in_async_block: Option<Span>,
|
await_in_async_block: Option<Span>,
|
||||||
}
|
}
|
||||||
@ -122,13 +122,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
|
|||||||
// Don't lint just yet, but store the necessary information for later.
|
// Don't lint just yet, but store the necessary information for later.
|
||||||
// The actual linting happens in `check_crate_post`, once we've found all
|
// The actual linting happens in `check_crate_post`, once we've found all
|
||||||
// uses of local async functions that do require asyncness to pass typeck
|
// uses of local async functions that do require asyncness to pass typeck
|
||||||
self.unused_async_fns.insert(
|
self.unused_async_fns.push(UnusedAsyncFn {
|
||||||
|
await_in_async_block: visitor.await_in_async_block,
|
||||||
|
fn_span: span,
|
||||||
def_id,
|
def_id,
|
||||||
UnusedAsyncFn {
|
});
|
||||||
await_in_async_block: visitor.await_in_async_block,
|
|
||||||
fn_span: span,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,12 +162,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
|
|||||||
let iter = self
|
let iter = self
|
||||||
.unused_async_fns
|
.unused_async_fns
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(did, item)| (!self.async_fns_as_value.contains(did)).then_some(item));
|
.filter(|UnusedAsyncFn { def_id, .. }| (!self.async_fns_as_value.contains(def_id)));
|
||||||
|
|
||||||
for fun in iter {
|
for fun in iter {
|
||||||
span_lint_and_then(
|
span_lint_hir_and_then(
|
||||||
cx,
|
cx,
|
||||||
UNUSED_ASYNC,
|
UNUSED_ASYNC,
|
||||||
|
cx.tcx.local_def_id_to_hir_id(fun.def_id),
|
||||||
fun.fn_span,
|
fun.fn_span,
|
||||||
"unused `async` for function with no await statements",
|
"unused `async` for function with no await statements",
|
||||||
|diag| {
|
|diag| {
|
||||||
|
@ -1,22 +1,3 @@
|
|||||||
error: unused `async` for function with no await statements
|
|
||||||
--> $DIR/unused_async.rs:45:5
|
|
||||||
|
|
|
||||||
LL | async fn f3() {}
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: consider removing the `async` from this function
|
|
||||||
= note: `-D clippy::unused-async` implied by `-D warnings`
|
|
||||||
|
|
||||||
error: unused `async` for function with no await statements
|
|
||||||
--> $DIR/unused_async.rs:57:1
|
|
||||||
|
|
|
||||||
LL | / async fn foo() -> i32 {
|
|
||||||
LL | | 4
|
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
|
||||||
= help: consider removing the `async` from this function
|
|
||||||
|
|
||||||
error: unused `async` for function with no await statements
|
error: unused `async` for function with no await statements
|
||||||
--> $DIR/unused_async.rs:13:5
|
--> $DIR/unused_async.rs:13:5
|
||||||
|
|
|
|
||||||
@ -33,6 +14,25 @@ note: `await` used in an async block, which does not require the enclosing funct
|
|||||||
|
|
|
|
||||||
LL | ready(()).await;
|
LL | ready(()).await;
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
= note: `-D clippy::unused-async` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: unused `async` for function with no await statements
|
||||||
|
--> $DIR/unused_async.rs:45:5
|
||||||
|
|
|
||||||
|
LL | async fn f3() {}
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: consider removing the `async` from this function
|
||||||
|
|
||||||
|
error: unused `async` for function with no await statements
|
||||||
|
--> $DIR/unused_async.rs:57:1
|
||||||
|
|
|
||||||
|
LL | / async fn foo() -> i32 {
|
||||||
|
LL | | 4
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
|
||||||
|
= help: consider removing the `async` from this function
|
||||||
|
|
||||||
error: unused `async` for function with no await statements
|
error: unused `async` for function with no await statements
|
||||||
--> $DIR/unused_async.rs:68:5
|
--> $DIR/unused_async.rs:68:5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user