aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index a177cebca..346118350 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -21,8 +21,8 @@ use hir_expand::{
21 MacroDefId, 21 MacroDefId,
22}; 22};
23use hir_ty::{ 23use hir_ty::{
24 autoderef, display::HirFormatter, expr::ExprValidator, ApplicationTy, Canonical, InEnvironment, 24 autoderef, display::HirFormatter, expr::ExprValidator, method_resolution::implements_trait,
25 TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk, 25 ApplicationTy, Canonical, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk,
26}; 26};
27use ra_db::{CrateId, Edition, FileId}; 27use ra_db::{CrateId, Edition, FileId};
28use ra_prof::profile; 28use ra_prof::profile;
@@ -878,6 +878,22 @@ impl Type {
878 } 878 }
879 } 879 }
880 880
881 /// Checks that particular type `ty` implements `std::future::Future`.
882 /// This function is used in `.await` syntax completion.
883 pub fn impls_future(&self, db: &impl HirDatabase) -> bool {
884 let krate = self.krate;
885
886 let std_future_trait =
887 db.lang_item(krate, "future_trait".into()).and_then(|it| it.as_trait());
888 let std_future_trait = match std_future_trait {
889 Some(it) => it,
890 None => return false,
891 };
892
893 let canonical_ty = Canonical { value: self.ty.value.clone(), num_vars: 0 };
894 implements_trait(&canonical_ty, db, self.ty.environment.clone(), krate, std_future_trait)
895 }
896
881 // FIXME: this method is broken, as it doesn't take closures into account. 897 // FIXME: this method is broken, as it doesn't take closures into account.
882 pub fn as_callable(&self) -> Option<CallableDef> { 898 pub fn as_callable(&self) -> Option<CallableDef> {
883 Some(self.ty.value.as_callable()?.0) 899 Some(self.ty.value.as_callable()?.0)