about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-08-17 08:21:43 -0700
committerEsteban Küber <esteban@kuber.com.ar>2022-11-10 18:06:59 -0800
commit8bd8484972ccfb4134c39b93c6ec68406bd1e63e (patch)
tree5678051f8ca2cb2090c36b571f948fbbe2a894f5
parent243496e1299bc6dddb3824a91f026da34f732199 (diff)
downloadrust-8bd8484972ccfb4134c39b93c6ec68406bd1e63e.tar.gz
rust-8bd8484972ccfb4134c39b93c6ec68406bd1e63e.zip
review comments
-rw-r--r--compiler/rustc_lint/src/unused.rs13
-rw-r--r--src/test/ui/lint/unused/unused-async.rs4
-rw-r--r--src/test/ui/lint/unused/unused-async.stderr4
3 files changed, 14 insertions, 7 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 1a5515530ae..045d76cac62 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -95,10 +95,17 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
 
         if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
             && let ty = cx.typeck_results().expr_ty(&await_expr)
-            && let ty::Opaque(def_id, _) = ty.kind()
+            && let ty::Opaque(future_def_id, _) = ty.kind()
             && cx.tcx.ty_is_opaque_future(ty)
-            && let parent = cx.tcx.parent(*def_id)
-            && check_must_use_def(cx, parent, expr.span, "awaited future returned by ", "")
+            // FIXME: This also includes non-async fns that return `impl Future`.
+            && let async_fn_def_id = cx.tcx.parent(*future_def_id)
+            && check_must_use_def(
+                cx,
+                async_fn_def_id,
+                expr.span,
+                "output of future returned by ",
+                "",
+            )
         {
             // We have a bare `foo().await;` on an opaque type from an async function that was
             // annotated with `#[must_use]`.
diff --git a/src/test/ui/lint/unused/unused-async.rs b/src/test/ui/lint/unused/unused-async.rs
index eda28dab27f..4be93aa155a 100644
--- a/src/test/ui/lint/unused/unused-async.rs
+++ b/src/test/ui/lint/unused/unused-async.rs
@@ -30,10 +30,10 @@ impl Wowee {
 async fn test() {
     foo(); //~ ERROR unused return value of `foo` that must be used
     //~^ ERROR unused implementer of `Future` that must be used
-    foo().await; //~ ERROR unused awaited future returned by `foo` that must be used
+    foo().await; //~ ERROR unused output of future returned by `foo` that must be used
     bar(); //~ ERROR unused return value of `bar` that must be used
     //~^ ERROR unused implementer of `Future` that must be used
-    bar().await; //~ ERROR unused awaited future returned by `bar` that must be used
+    bar().await; //~ ERROR unused output of future returned by `bar` that must be used
     baz(); //~ ERROR unused implementer of `Future` that must be used
     baz().await; // ok
 }
diff --git a/src/test/ui/lint/unused/unused-async.stderr b/src/test/ui/lint/unused/unused-async.stderr
index ae284681720..abc49599309 100644
--- a/src/test/ui/lint/unused/unused-async.stderr
+++ b/src/test/ui/lint/unused/unused-async.stderr
@@ -17,7 +17,7 @@ error: unused return value of `foo` that must be used
 LL |     foo();
    |     ^^^^^
 
-error: unused awaited future returned by `foo` that must be used
+error: unused output of future returned by `foo` that must be used
   --> $DIR/unused-async.rs:33:5
    |
 LL |     foo().await;
@@ -37,7 +37,7 @@ error: unused return value of `bar` that must be used
 LL |     bar();
    |     ^^^^^
 
-error: unused awaited future returned by `bar` that must be used
+error: unused output of future returned by `bar` that must be used
   --> $DIR/unused-async.rs:36:5
    |
 LL |     bar().await;