Enforce must_use on associated types and RPITITs
This commit is contained in:
parent
c9c760fc20
commit
d1009a42d8
@ -291,7 +291,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||||||
.map(|inner| MustUsePath::Pinned(Box::new(inner)))
|
.map(|inner| MustUsePath::Pinned(Box::new(inner)))
|
||||||
}
|
}
|
||||||
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
|
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(
|
elaborate(
|
||||||
cx.tcx,
|
cx.tcx,
|
||||||
cx.tcx.explicit_item_bounds(def).instantiate_identity_iter_copied(),
|
cx.tcx.explicit_item_bounds(def).instantiate_identity_iter_copied(),
|
||||||
|
15
tests/ui/lint/unused/assoc-types.assoc_ty.stderr
Normal file
15
tests/ui/lint/unused/assoc-types.assoc_ty.stderr
Normal file
@ -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
|
||||||
|
|
15
tests/ui/lint/unused/assoc-types.rpitit.stderr
Normal file
15
tests/ui/lint/unused/assoc-types.rpitit.stderr
Normal file
@ -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
|
||||||
|
|
23
tests/ui/lint/unused/assoc-types.rs
Normal file
23
tests/ui/lint/unused/assoc-types.rs
Normal file
@ -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() {}
|
Loading…
x
Reference in New Issue
Block a user