diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_dot.rs | 2 |
4 files changed, 21 insertions, 28 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, |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 888dc3116..55435e6ea 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -465,7 +465,7 @@ fn transform_receiver_ty( | |||
465 | pub fn implements_trait( | 465 | pub fn implements_trait( |
466 | ty: &Canonical<Ty>, | 466 | ty: &Canonical<Ty>, |
467 | db: &impl HirDatabase, | 467 | db: &impl HirDatabase, |
468 | resolver: &Resolver, | 468 | env: Arc<TraitEnvironment>, |
469 | krate: CrateId, | 469 | krate: CrateId, |
470 | trait_: TraitId, | 470 | trait_: TraitId, |
471 | ) -> bool { | 471 | ) -> bool { |
@@ -474,7 +474,6 @@ pub fn implements_trait( | |||
474 | // anyway, but currently Chalk doesn't implement `dyn/impl Trait` yet | 474 | // anyway, but currently Chalk doesn't implement `dyn/impl Trait` yet |
475 | return true; | 475 | return true; |
476 | } | 476 | } |
477 | let env = TraitEnvironment::lower(db, resolver); | ||
478 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); | 477 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); |
479 | let solution = db.trait_solve(krate.into(), goal); | 478 | let solution = db.trait_solve(krate.into(), goal); |
480 | 479 | ||
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs index fe02e36b3..9ab43644e 100644 --- a/crates/ra_ide/src/completion/complete_dot.rs +++ b/crates/ra_ide/src/completion/complete_dot.rs | |||
@@ -27,7 +27,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | |||
27 | complete_methods(acc, ctx, &receiver_ty); | 27 | complete_methods(acc, ctx, &receiver_ty); |
28 | 28 | ||
29 | // Suggest .await syntax for types that implement Future trait | 29 | // Suggest .await syntax for types that implement Future trait |
30 | if ctx.analyzer.impls_future(ctx.db, receiver_ty) { | 30 | if receiver_ty.impls_future(ctx.db) { |
31 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") | 31 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") |
32 | .detail("expr.await") | 32 | .detail("expr.await") |
33 | .insert_text("await") | 33 | .insert_text("await") |