about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-11-30 02:24:11 +0000
committerMichael Goulet <michael@errs.io>2023-11-30 02:24:52 +0000
commitd1009a42d820ded1d446c62d3acb69dffc5117c8 (patch)
tree33f80c4211999bcdbb118454186c1d4ff8b34704
parentc9c760fc206345d0d7b7b4d989e2d95cd63ce9c0 (diff)
downloadrust-d1009a42d820ded1d446c62d3acb69dffc5117c8.tar.gz
rust-d1009a42d820ded1d446c62d3acb69dffc5117c8.zip
Enforce must_use on associated types and RPITITs
-rw-r--r--compiler/rustc_lint/src/unused.rs2
-rw-r--r--tests/ui/lint/unused/assoc-types.assoc_ty.stderr15
-rw-r--r--tests/ui/lint/unused/assoc-types.rpitit.stderr15
-rw-r--r--tests/ui/lint/unused/assoc-types.rs23
4 files changed, 54 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 0a167b0893c..c492e7c6fbf 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -291,7 +291,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
                         .map(|inner| MustUsePath::Pinned(Box::new(inner)))
                 }
                 ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
-                ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
+                ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => {
                     elaborate(
                         cx.tcx,
                         cx.tcx.explicit_item_bounds(def).instantiate_identity_iter_copied(),
diff --git a/tests/ui/lint/unused/assoc-types.assoc_ty.stderr b/tests/ui/lint/unused/assoc-types.assoc_ty.stderr
new file mode 100644
index 00000000000..190c4ef0cea
--- /dev/null
+++ b/tests/ui/lint/unused/assoc-types.assoc_ty.stderr
@@ -0,0 +1,15 @@
+error: unused implementer of `Future` that must be used
+  --> $DIR/assoc-types.rs:19:5
+   |
+LL |     T::foo();
+   |     ^^^^^^^^
+   |
+   = note: futures do nothing unless you `.await` or poll them
+note: the lint level is defined here
+  --> $DIR/assoc-types.rs:4:9
+   |
+LL | #![deny(unused_must_use)]
+   |         ^^^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/lint/unused/assoc-types.rpitit.stderr b/tests/ui/lint/unused/assoc-types.rpitit.stderr
new file mode 100644
index 00000000000..190c4ef0cea
--- /dev/null
+++ b/tests/ui/lint/unused/assoc-types.rpitit.stderr
@@ -0,0 +1,15 @@
+error: unused implementer of `Future` that must be used
+  --> $DIR/assoc-types.rs:19:5
+   |
+LL |     T::foo();
+   |     ^^^^^^^^
+   |
+   = note: futures do nothing unless you `.await` or poll them
+note: the lint level is defined here
+  --> $DIR/assoc-types.rs:4:9
+   |
+LL | #![deny(unused_must_use)]
+   |         ^^^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/lint/unused/assoc-types.rs b/tests/ui/lint/unused/assoc-types.rs
new file mode 100644
index 00000000000..cebb9b4090c
--- /dev/null
+++ b/tests/ui/lint/unused/assoc-types.rs
@@ -0,0 +1,23 @@
+// edition: 2021
+// revisions: rpitit assoc_ty
+
+#![deny(unused_must_use)]
+
+use std::future::Future;
+
+pub trait Tr {
+    type Fut: Future<Output = ()>;
+
+    #[cfg(rpitit)]
+    fn foo() -> impl Future<Output = ()>;
+
+    #[cfg(assoc_ty)]
+    fn foo() -> Self::Fut;
+}
+
+pub async fn bar<T: Tr>() {
+    T::foo();
+    //~^ ERROR unused implementer of `Future` that must be used
+}
+
+fn main() {}