FIX: issue-12279
---- UPDATE: add async block into test. FIX: no_effect Fixed asynchronous function parameter names with underscores so that warnings are not displayed when underscores are added to parameter names ADD: test case
This commit is contained in:
parent
6aa5f1ac6f
commit
aa8a82ec26
@ -5,8 +5,8 @@
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{
|
||||
is_range_literal, BinOpKind, BlockCheckMode, Expr, ExprKind, HirId, HirIdMap, ItemKind, Node, PatKind, Stmt,
|
||||
StmtKind, UnsafeSource,
|
||||
is_range_literal, BinOpKind, BlockCheckMode, Expr, ExprKind, HirId, HirIdMap, ItemKind, LocalSource, Node, PatKind,
|
||||
Stmt, StmtKind, UnsafeSource,
|
||||
};
|
||||
use rustc_infer::infer::TyCtxtInferExt as _;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
@ -178,6 +178,7 @@ fn check_no_effect(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
|
||||
}
|
||||
} else if let StmtKind::Local(local) = stmt.kind {
|
||||
if !is_lint_allowed(cx, NO_EFFECT_UNDERSCORE_BINDING, local.hir_id)
|
||||
&& !matches!(local.source, LocalSource::AsyncFn)
|
||||
&& let Some(init) = local.init
|
||||
&& local.els.is_none()
|
||||
&& !local.pat.span.from_expansion()
|
||||
|
50
tests/ui/no_effect_async_fn.rs
Normal file
50
tests/ui/no_effect_async_fn.rs
Normal file
@ -0,0 +1,50 @@
|
||||
#![warn(clippy::no_effect_underscore_binding)]
|
||||
#![no_main]
|
||||
|
||||
trait AsyncTrait {
|
||||
async fn bar(i: u64);
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
|
||||
impl AsyncTrait for Bar {
|
||||
// Shouldn't lint `binding to `_` prefixed variable with no side-effect`
|
||||
async fn bar(_i: u64) {
|
||||
let _a = 0;
|
||||
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
||||
|
||||
// Shouldn't lint `binding to `_` prefixed variable with no side-effect`
|
||||
let _b = num();
|
||||
|
||||
let _ = async {
|
||||
let _c = 0;
|
||||
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
||||
|
||||
// Shouldn't lint `binding to `_` prefixed variable with no side-effect`
|
||||
let _d = num();
|
||||
}
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
// Shouldn't lint `binding to `_` prefixed variable with no side-effect`
|
||||
async fn foo(_i: u64) {
|
||||
let _a = 0;
|
||||
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
||||
|
||||
// Shouldn't lint `binding to `_` prefixed variable with no side-effect`
|
||||
let _b = num();
|
||||
|
||||
let _ = async {
|
||||
let _c = 0;
|
||||
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
||||
|
||||
// Shouldn't lint `binding to `_` prefixed variable with no side-effect`
|
||||
let _d = num();
|
||||
}
|
||||
.await;
|
||||
}
|
||||
|
||||
fn num() -> usize {
|
||||
0
|
||||
}
|
29
tests/ui/no_effect_async_fn.stderr
Normal file
29
tests/ui/no_effect_async_fn.stderr
Normal file
@ -0,0 +1,29 @@
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> tests/ui/no_effect_async_fn.rs:20:17
|
||||
|
|
||||
LL | let _c = 0;
|
||||
| ^^
|
||||
|
|
||||
= note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]`
|
||||
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> tests/ui/no_effect_async_fn.rs:13:13
|
||||
|
|
||||
LL | let _a = 0;
|
||||
| ^^
|
||||
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> tests/ui/no_effect_async_fn.rs:39:13
|
||||
|
|
||||
LL | let _c = 0;
|
||||
| ^^
|
||||
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> tests/ui/no_effect_async_fn.rs:32:9
|
||||
|
|
||||
LL | let _a = 0;
|
||||
| ^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user