Use lang-items to resolve future trait
This commit is contained in:
parent
aedff7cdcf
commit
0358f5fdeb
@ -15,7 +15,6 @@
|
||||
},
|
||||
expr::{ExprId, PatId},
|
||||
nameres::ModuleSource,
|
||||
path::path,
|
||||
resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
|
||||
AssocItemId, DefWithBodyId,
|
||||
};
|
||||
@ -399,20 +398,20 @@ pub fn iterate_path_candidates<T>(
|
||||
/// Checks that particular type `ty` implements `std::future::Future`.
|
||||
/// This function is used in `.await` syntax completion.
|
||||
pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool {
|
||||
let std_future_path = path![std::future::Future];
|
||||
|
||||
let std_future_trait = match self.resolver.resolve_known_trait(db, &std_future_path) {
|
||||
Some(it) => it.into(),
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
let krate = match self.resolver.krate() {
|
||||
Some(krate) => krate,
|
||||
_ => return false,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let std_future_trait =
|
||||
db.lang_item(krate, "future_trait".into()).and_then(|it| it.as_trait());
|
||||
let std_future_trait = match std_future_trait {
|
||||
Some(it) => it,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let canonical_ty = Canonical { value: ty.ty.value, num_vars: 0 };
|
||||
implements_trait(&canonical_ty, db, &self.resolver, krate.into(), std_future_trait)
|
||||
implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait)
|
||||
}
|
||||
|
||||
pub fn expand(
|
||||
|
@ -525,6 +525,7 @@ fn foo(a: A) {
|
||||
|
||||
//- /std/lib.rs
|
||||
pub mod future {
|
||||
#[lang = "future_trait"]
|
||||
pub trait Future {}
|
||||
}
|
||||
"###, CompletionKind::Keyword),
|
||||
|
Loading…
Reference in New Issue
Block a user