Skip to content

Commit 2c4d566

Browse files
committed
Auto merge of #5535 - ebroto:issue_5360, r=phansch
used_underscore_binding: do not lint on `await` desugaring changelog: used_underscore_binding: do not lint on `await` desugaring Fixes #5360
2 parents f2486b3 + fc5fc63 commit 2c4d566

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
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

+17
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)]
@@ -87,6 +88,21 @@ fn non_variables() {
8788
f();
8889
}
8990

91+
// Tests that we do not lint if the binding comes from await desugaring,
92+
// but we do lint the awaited expression. See issue 5360.
93+
async fn await_desugaring() {
94+
async fn foo() {}
95+
fn uses_i(_i: i32) {}
96+
97+
foo().await;
98+
({
99+
let _i = 5;
100+
uses_i(_i);
101+
foo()
102+
})
103+
.await
104+
}
105+
90106
fn main() {
91107
let foo = 0u32;
92108
// tests of unused_underscore lint
@@ -99,4 +115,5 @@ fn main() {
99115
let _ = unused_underscore_complex(foo);
100116
let _ = multiple_underscores(foo);
101117
non_variables();
118+
await_desugaring();
102119
}
+12-6
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
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
| ^^^^^^^^^^^^^^^^^^^
3232

33-
error: aborting due to 5 previous errors
33+
error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
34+
--> $DIR/used_underscore_binding.rs:100:16
35+
|
36+
LL | uses_i(_i);
37+
| ^^
38+
39+
error: aborting due to 6 previous errors
3440

0 commit comments

Comments
 (0)