aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/source_binder.rs41
1 files changed, 10 insertions, 31 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 67cb19615..7720329e3 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -24,6 +24,7 @@ use crate::{
24 BodySourceMap, 24 BodySourceMap,
25 }, 25 },
26 ids::LocationCtx, 26 ids::LocationCtx,
27 lang_item::LangItemTarget,
27 ty::method_resolution::implements_trait, 28 ty::method_resolution::implements_trait,
28 AsName, AstId, Const, Crate, DefWithBody, Either, Enum, Function, HirDatabase, HirFileId, 29 AsName, AstId, Const, Crate, DefWithBody, Either, Enum, Function, HirDatabase, HirFileId,
29 MacroDef, Module, Name, Path, PerNs, Resolver, Static, Struct, Trait, Ty, 30 MacroDef, Module, Name, Path, PerNs, Resolver, Static, Struct, Trait, Ty,
@@ -410,40 +411,18 @@ impl SourceAnalyzer {
410 crate::ty::autoderef(db, &self.resolver, canonical).map(|canonical| canonical.value) 411 crate::ty::autoderef(db, &self.resolver, canonical).map(|canonical| canonical.value)
411 } 412 }
412 413
413 /// Checks that particular type `ty` implements `std::future::Future` trait. 414 /// Checks that particular type `ty` implements `Future` trait (`future_trait` lang item).
414 /// This function is used in `.await` syntax completion. 415 /// This function is used in `.await` syntax completion.
415 pub fn impls_future(&self, db: &impl HirDatabase, ty: Ty) -> bool { 416 pub fn impls_future(&self, db: &impl HirDatabase, ty: Ty) -> bool {
416 // Search for std::future::Future trait in scope 417 let krate = self.resolver.krate();
417 let future_trait = self 418 if let Some(krate) = krate {
418 .resolver 419 let future_trait = match db.lang_item(krate, "future_trait".into()) {
419 .traits_in_scope(db) 420 Some(LangItemTarget::Trait(t)) => t,
420 .into_iter() 421 _ => return false,
421 .filter(|t| { 422 };
422 let std = t
423 .module(db)
424 .parent(db)
425 .and_then(|m| m.name(db).and_then(|n| Some(n.to_string() == "std")))
426 .unwrap_or(false);
427
428 let future = t
429 .module(db)
430 .name(db)
431 .and_then(|n| Some(n.to_string() == "future"))
432 .unwrap_or(false);
433
434 let future_trait =
435 t.name(db).and_then(|n| Some(n.to_string() == "Future")).unwrap_or(false);
436
437 std && future && future_trait
438 })
439 .nth(0);
440 423
441 if let Some(trait_) = future_trait { 424 let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 };
442 let krate = self.resolver.krate(); 425 return implements_trait(&canonical_ty, db, &self.resolver, krate, future_trait);
443 if let Some(krate) = krate {
444 let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 };
445 return implements_trait(&canonical_ty, db, &self.resolver, krate, trait_);
446 }
447 } 426 }
448 427
449 false 428 false