Skip to content

Commit d1009a4

Browse files
Enforce must_use on associated types and RPITITs
1 parent c9c760f commit d1009a4

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

compiler/rustc_lint/src/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
291291
.map(|inner| MustUsePath::Pinned(Box::new(inner)))
292292
}
293293
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
294-
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
294+
ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => {
295295
elaborate(
296296
cx.tcx,
297297
cx.tcx.explicit_item_bounds(def).instantiate_identity_iter_copied(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: unused implementer of `Future` that must be used
2+
--> $DIR/assoc-types.rs:19:5
3+
|
4+
LL | T::foo();
5+
| ^^^^^^^^
6+
|
7+
= note: futures do nothing unless you `.await` or poll them
8+
note: the lint level is defined here
9+
--> $DIR/assoc-types.rs:4:9
10+
|
11+
LL | #![deny(unused_must_use)]
12+
| ^^^^^^^^^^^^^^^
13+
14+
error: aborting due to 1 previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: unused implementer of `Future` that must be used
2+
--> $DIR/assoc-types.rs:19:5
3+
|
4+
LL | T::foo();
5+
| ^^^^^^^^
6+
|
7+
= note: futures do nothing unless you `.await` or poll them
8+
note: the lint level is defined here
9+
--> $DIR/assoc-types.rs:4:9
10+
|
11+
LL | #![deny(unused_must_use)]
12+
| ^^^^^^^^^^^^^^^
13+
14+
error: aborting due to 1 previous error
15+

tests/ui/lint/unused/assoc-types.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// edition: 2021
2+
// revisions: rpitit assoc_ty
3+
4+
#![deny(unused_must_use)]
5+
6+
use std::future::Future;
7+
8+
pub trait Tr {
9+
type Fut: Future<Output = ()>;
10+
11+
#[cfg(rpitit)]
12+
fn foo() -> impl Future<Output = ()>;
13+
14+
#[cfg(assoc_ty)]
15+
fn foo() -> Self::Fut;
16+
}
17+
18+
pub async fn bar<T: Tr>() {
19+
T::foo();
20+
//~^ ERROR unused implementer of `Future` that must be used
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)