Simplify checking for GeneratorKind::Async

Adds a helper method around `generator_kind` that makes matching async constructs simpler.
This commit is contained in:
Arpad Borsos 2022-11-26 21:33:12 +01:00
parent 8a09420ac4
commit 2db0dc3297
No known key found for this signature in database
GPG key ID: FC7BCA77824B3298
5 changed files with 10 additions and 22 deletions

View file

@ -322,10 +322,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
ty::Closure(..) => Some(MustUsePath::Closure(span)),
ty::Generator(def_id, ..) => {
// async fn should be treated as "implementor of `Future`"
let must_use = if matches!(
cx.tcx.generator_kind(def_id),
Some(hir::GeneratorKind::Async(..))
) {
let must_use = if cx.tcx.generator_is_async(def_id) {
let def_id = cx.tcx.lang_items().future_trait().unwrap();
is_def_must_use(cx, def_id, span)
.map(|inner| MustUsePath::Opaque(Box::new(inner)))