diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 0a167b0893c59..c492e7c6fbfb8 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 0000000000000..190c4ef0cea0d --- /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 0000000000000..190c4ef0cea0d --- /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 0000000000000..cebb9b4090ce9 --- /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; + + #[cfg(rpitit)] + fn foo() -> impl Future; + + #[cfg(assoc_ty)] + fn foo() -> Self::Fut; +} + +pub async fn bar() { + T::foo(); + //~^ ERROR unused implementer of `Future` that must be used +} + +fn main() {}