diff options
author | Aleksey Kladov <[email protected]> | 2020-01-14 10:27:00 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-01-14 10:29:43 +0000 |
commit | 52e7f67128fdaf604e4563eb6445fdd69d42c91e (patch) | |
tree | ef22688ef7d1486ac4f084ead6bcb7e69d520b65 /crates/ra_hir/src/code_model.rs | |
parent | 0358f5fdebb7f462e72aaf77eea8c842709127fc (diff) |
Move impls_future to Type, where it belongs
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 |
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 | }; |
23 | use hir_ty::{ | 23 | use 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 | }; |
27 | use ra_db::{CrateId, Edition, FileId}; | 27 | use ra_db::{CrateId, Edition, FileId}; |
28 | use ra_prof::profile; | 28 | use 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) |