diff options
author | Aleksey Kladov <[email protected]> | 2020-01-14 10:13:07 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-01-14 10:29:43 +0000 |
commit | 0358f5fdebb7f462e72aaf77eea8c842709127fc (patch) | |
tree | 17b58eacb9a6fbad911e4e62815d066a139782b7 /crates/ra_hir | |
parent | aedff7cdcfb2340a3a23b540b50cadc94a367428 (diff) |
Use lang-items to resolve future trait
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index f0511c742..bd5ef1466 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -15,7 +15,6 @@ use hir_def::{ | |||
15 | }, | 15 | }, |
16 | expr::{ExprId, PatId}, | 16 | expr::{ExprId, PatId}, |
17 | nameres::ModuleSource, | 17 | nameres::ModuleSource, |
18 | path::path, | ||
19 | resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, | 18 | resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, |
20 | AssocItemId, DefWithBodyId, | 19 | AssocItemId, DefWithBodyId, |
21 | }; | 20 | }; |
@@ -399,20 +398,20 @@ impl SourceAnalyzer { | |||
399 | /// Checks that particular type `ty` implements `std::future::Future`. | 398 | /// Checks that particular type `ty` implements `std::future::Future`. |
400 | /// This function is used in `.await` syntax completion. | 399 | /// This function is used in `.await` syntax completion. |
401 | pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool { | 400 | pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool { |
402 | let std_future_path = path![std::future::Future]; | ||
403 | |||
404 | let std_future_trait = match self.resolver.resolve_known_trait(db, &std_future_path) { | ||
405 | Some(it) => it.into(), | ||
406 | _ => return false, | ||
407 | }; | ||
408 | |||
409 | let krate = match self.resolver.krate() { | 401 | let krate = match self.resolver.krate() { |
410 | Some(krate) => krate, | 402 | Some(krate) => krate, |
411 | _ => return false, | 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, | ||
412 | }; | 411 | }; |
413 | 412 | ||
414 | let canonical_ty = Canonical { value: ty.ty.value, num_vars: 0 }; | 413 | let canonical_ty = Canonical { value: ty.ty.value, num_vars: 0 }; |
415 | implements_trait(&canonical_ty, db, &self.resolver, krate.into(), std_future_trait) | 414 | implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait) |
416 | } | 415 | } |
417 | 416 | ||
418 | pub fn expand( | 417 | pub fn expand( |