Skip to content

Commit 3a96f54

Browse files
committed
used_underscore_binding: do not lint on await desugaring
1 parent f2486b3 commit 3a96f54

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

clippy_lints/src/misc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir::{
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty;
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
12+
use rustc_span::hygiene::DesugaringKind;
1213
use rustc_span::source_map::{ExpnKind, Span};
1314

1415
use crate::consts::{constant, Constant};
@@ -399,8 +400,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
399400
},
400401
_ => {},
401402
}
402-
if in_attributes_expansion(expr) {
403-
// Don't lint things expanded by #[derive(...)], etc
403+
if in_attributes_expansion(expr) || expr.span.is_desugaring(DesugaringKind::Await) {
404+
// Don't lint things expanded by #[derive(...)], etc or `await` desugaring
404405
return;
405406
}
406407
let binding = match expr.kind {

tests/ui/used_underscore_binding.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// edition:2018
12
// aux-build:proc_macro_derive.rs
23

34
#![feature(rustc_private)]
@@ -86,6 +87,12 @@ fn non_variables() {
8687
let f = _fn_test;
8788
f();
8889
}
90+
// Tests that we do not lint if the binding comes from await desugaring.
91+
// See issue 5360.
92+
async fn await_desugaring() {
93+
async fn foo() {}
94+
foo().await;
95+
}
8996

9097
fn main() {
9198
let foo = 0u32;
@@ -99,4 +106,5 @@ fn main() {
99106
let _ = unused_underscore_complex(foo);
100107
let _ = multiple_underscores(foo);
101108
non_variables();
109+
await_desugaring();
102110
}

tests/ui/used_underscore_binding.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
2-
--> $DIR/used_underscore_binding.rs:25:5
2+
--> $DIR/used_underscore_binding.rs:26:5
33
|
44
LL | _foo + 1
55
| ^^^^
66
|
77
= note: `-D clippy::used-underscore-binding` implied by `-D warnings`
88

99
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
10-
--> $DIR/used_underscore_binding.rs:30:20
10+
--> $DIR/used_underscore_binding.rs:31:20
1111
|
1212
LL | println!("{}", _foo);
1313
| ^^^^
1414

1515
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
16-
--> $DIR/used_underscore_binding.rs:31:16
16+
--> $DIR/used_underscore_binding.rs:32:16
1717
|
1818
LL | assert_eq!(_foo, _foo);
1919
| ^^^^
2020

2121
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
22-
--> $DIR/used_underscore_binding.rs:31:22
22+
--> $DIR/used_underscore_binding.rs:32:22
2323
|
2424
LL | assert_eq!(_foo, _foo);
2525
| ^^^^
2626

2727
error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
28-
--> $DIR/used_underscore_binding.rs:44:5
28+
--> $DIR/used_underscore_binding.rs:45:5
2929
|
3030
LL | s._underscore_field += 1;
3131
| ^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)