about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/context.rs
diff options
context:
space:
mode:
authorJoshua Nelson <jnelson@cloudflare.com>2022-06-21 19:43:46 -0500
committerJoshua Nelson <jnelson@cloudflare.com>2022-06-21 19:44:53 -0500
commitb052d76586988040c6ae8aef609794ae16cc28dc (patch)
treef9b230c65df00910ef0cf41f603310165f573f5a /compiler/rustc_middle/src/ty/context.rs
parent1deca0425db3e74a61cb732e729c0777904e549c (diff)
downloadrust-b052d76586988040c6ae8aef609794ae16cc28dc.tar.gz
rust-b052d76586988040c6ae8aef609794ae16cc28dc.zip
Address review comments from #98259
It got merged so fast I didn't have time to make changes xD
Diffstat (limited to 'compiler/rustc_middle/src/ty/context.rs')
-rw-r--r--compiler/rustc_middle/src/ty/context.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index c43cf07b3ad..0765928e9b9 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -74,7 +74,7 @@ use std::mem;
 use std::ops::{Bound, Deref};
 use std::sync::Arc;
 
-use super::RvalueScopes;
+use super::{ImplPolarity, RvalueScopes};
 
 pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
     /// Creates a new `OnDiskCache` instance from the serialized data in `data`.
@@ -2224,6 +2224,20 @@ impl<'tcx> TyCtxt<'tcx> {
         })
     }
 
+    /// Given a `ty`, return whether it's an `impl Future<...>`.
+    pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
+        let ty::Opaque(def_id, _) = ty.kind() else { return false };
+        let future_trait = self.lang_items().future_trait().unwrap();
+
+        self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
+            let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
+                return false;
+            };
+            trait_predicate.trait_ref.def_id == future_trait
+                && trait_predicate.polarity == ImplPolarity::Positive
+        })
+    }
+
     /// Computes the def-ids of the transitive supertraits of `trait_def_id`. This (intentionally)
     /// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
     /// to identify which traits may define a given associated type to help avoid cycle errors.