diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 24 |
2 files changed, 19 insertions, 25 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) |
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index bd5ef1466..3df48842d 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -21,10 +21,7 @@ use hir_def::{ | |||
21 | use hir_expand::{ | 21 | use hir_expand::{ |
22 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, | 22 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, |
23 | }; | 23 | }; |
24 | use hir_ty::{ | 24 | use hir_ty::{method_resolution, Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty}; |
25 | method_resolution::{self, implements_trait}, | ||
26 | Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty, | ||
27 | }; | ||
28 | use ra_prof::profile; | 25 | use ra_prof::profile; |
29 | use ra_syntax::{ | 26 | use ra_syntax::{ |
30 | ast::{self, AstNode}, | 27 | ast::{self, AstNode}, |
@@ -395,25 +392,6 @@ impl SourceAnalyzer { | |||
395 | ) | 392 | ) |
396 | } | 393 | } |
397 | 394 | ||
398 | /// Checks that particular type `ty` implements `std::future::Future`. | ||
399 | /// This function is used in `.await` syntax completion. | ||
400 | pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool { | ||
401 | let krate = match self.resolver.krate() { | ||
402 | Some(krate) => krate, | ||
403 | None => return false, | ||
404 | }; | ||
405 | |||
406 | let std_future_trait = | ||
407 | db.lang_item(krate, "future_trait".into()).and_then(|it| it.as_trait()); | ||
408 | let std_future_trait = match std_future_trait { | ||
409 | Some(it) => it, | ||
410 | None => return false, | ||
411 | }; | ||
412 | |||
413 | let canonical_ty = Canonical { value: ty.ty.value, num_vars: 0 }; | ||
414 | implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait) | ||
415 | } | ||
416 | |||
417 | pub fn expand( | 395 | pub fn expand( |
418 | &self, | 396 | &self, |
419 | db: &impl HirDatabase, | 397 | db: &impl HirDatabase, |