about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-04-28 05:36:30 +0000
committerbors <bors@rust-lang.org>2020-04-28 05:36:30 +0000
commit2c4d5661137933dfe93c03b0f9e514d97bafdada (patch)
tree32f478812a2481056eb209301fb5f1871d872103
parentf2486b3d35efc551ea0b5b549120c05f3ab1d636 (diff)
parentfc5fc6378cfa384c02020c63cbc1472f0844065d (diff)
downloadrust-2c4d5661137933dfe93c03b0f9e514d97bafdada.tar.gz
rust-2c4d5661137933dfe93c03b0f9e514d97bafdada.zip
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
-rw-r--r--clippy_lints/src/misc.rs5
-rw-r--r--tests/ui/used_underscore_binding.rs17
-rw-r--r--tests/ui/used_underscore_binding.stderr18
3 files changed, 32 insertions, 8 deletions
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs
index c49d3ba5dec..e1d524c2231 100644
--- a/clippy_lints/src/misc.rs
+++ b/clippy_lints/src/misc.rs
@@ -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 {
diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs
index 9c06e047c4a..8e0243c49aa 100644
--- a/tests/ui/used_underscore_binding.rs
+++ b/tests/ui/used_underscore_binding.rs
@@ -1,3 +1,4 @@
+// edition:2018
 // aux-build:proc_macro_derive.rs
 
 #![feature(rustc_private)]
@@ -87,6 +88,21 @@ fn non_variables() {
     f();
 }
 
+// Tests that we do not lint if the binding comes from await desugaring,
+// but we do lint the awaited expression. See issue 5360.
+async fn await_desugaring() {
+    async fn foo() {}
+    fn uses_i(_i: i32) {}
+
+    foo().await;
+    ({
+        let _i = 5;
+        uses_i(_i);
+        foo()
+    })
+    .await
+}
+
 fn main() {
     let foo = 0u32;
     // tests of unused_underscore lint
@@ -99,4 +115,5 @@ fn main() {
     let _ = unused_underscore_complex(foo);
     let _ = multiple_underscores(foo);
     non_variables();
+    await_desugaring();
 }
diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr
index 47693518f86..68e96148093 100644
--- a/tests/ui/used_underscore_binding.stderr
+++ b/tests/ui/used_underscore_binding.stderr
@@ -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,28 +7,34 @@ 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;
    |     ^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 5 previous errors
+error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
+  --> $DIR/used_underscore_binding.rs:100:16
+   |
+LL |         uses_i(_i);
+   |                ^^
+
+error: aborting due to 6 previous errors