mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
used_underscore_binding: do not lint on await
desugaring
This commit is contained in:
parent
f2486b3d35
commit
3a96f548d1
3 changed files with 16 additions and 7 deletions
|
@ -9,6 +9,7 @@ use rustc_hir::{
|
|||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
use rustc_span::source_map::{ExpnKind, Span};
|
||||
|
||||
use crate::consts::{constant, Constant};
|
||||
|
@ -399,8 +400,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
},
|
||||
_ => {},
|
||||
}
|
||||
if in_attributes_expansion(expr) {
|
||||
// Don't lint things expanded by #[derive(...)], etc
|
||||
if in_attributes_expansion(expr) || expr.span.is_desugaring(DesugaringKind::Await) {
|
||||
// Don't lint things expanded by #[derive(...)], etc or `await` desugaring
|
||||
return;
|
||||
}
|
||||
let binding = match expr.kind {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// edition:2018
|
||||
// aux-build:proc_macro_derive.rs
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
@ -86,6 +87,12 @@ fn non_variables() {
|
|||
let f = _fn_test;
|
||||
f();
|
||||
}
|
||||
// Tests that we do not lint if the binding comes from await desugaring.
|
||||
// See issue 5360.
|
||||
async fn await_desugaring() {
|
||||
async fn foo() {}
|
||||
foo().await;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let foo = 0u32;
|
||||
|
@ -99,4 +106,5 @@ fn main() {
|
|||
let _ = unused_underscore_complex(foo);
|
||||
let _ = multiple_underscores(foo);
|
||||
non_variables();
|
||||
await_desugaring();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
--> $DIR/used_underscore_binding.rs:25:5
|
||||
--> $DIR/used_underscore_binding.rs:26:5
|
||||
|
|
||||
LL | _foo + 1
|
||||
| ^^^^
|
||||
|
@ -7,25 +7,25 @@ LL | _foo + 1
|
|||
= note: `-D clippy::used-underscore-binding` implied by `-D warnings`
|
||||
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
--> $DIR/used_underscore_binding.rs:30:20
|
||||
--> $DIR/used_underscore_binding.rs:31:20
|
||||
|
|
||||
LL | println!("{}", _foo);
|
||||
| ^^^^
|
||||
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
--> $DIR/used_underscore_binding.rs:31:16
|
||||
--> $DIR/used_underscore_binding.rs:32:16
|
||||
|
|
||||
LL | assert_eq!(_foo, _foo);
|
||||
| ^^^^
|
||||
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
--> $DIR/used_underscore_binding.rs:31:22
|
||||
--> $DIR/used_underscore_binding.rs:32:22
|
||||
|
|
||||
LL | assert_eq!(_foo, _foo);
|
||||
| ^^^^
|
||||
|
||||
error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
--> $DIR/used_underscore_binding.rs:44:5
|
||||
--> $DIR/used_underscore_binding.rs:45:5
|
||||
|
|
||||
LL | s._underscore_field += 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue