Use lang-items to resolve future trait
This commit is contained in:
parent
aedff7cdcf
commit
0358f5fdeb
@ -15,7 +15,6 @@ use hir_def::{
|
|||||||
},
|
},
|
||||||
expr::{ExprId, PatId},
|
expr::{ExprId, PatId},
|
||||||
nameres::ModuleSource,
|
nameres::ModuleSource,
|
||||||
path::path,
|
|
||||||
resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
|
resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
|
||||||
AssocItemId, DefWithBodyId,
|
AssocItemId, DefWithBodyId,
|
||||||
};
|
};
|
||||||
@ -399,20 +398,20 @@ impl SourceAnalyzer {
|
|||||||
/// Checks that particular type `ty` implements `std::future::Future`.
|
/// Checks that particular type `ty` implements `std::future::Future`.
|
||||||
/// This function is used in `.await` syntax completion.
|
/// This function is used in `.await` syntax completion.
|
||||||
pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool {
|
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() {
|
let krate = match self.resolver.krate() {
|
||||||
Some(krate) => 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 };
|
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(
|
pub fn expand(
|
||||||
|
@ -525,6 +525,7 @@ mod tests {
|
|||||||
|
|
||||||
//- /std/lib.rs
|
//- /std/lib.rs
|
||||||
pub mod future {
|
pub mod future {
|
||||||
|
#[lang = "future_trait"]
|
||||||
pub trait Future {}
|
pub trait Future {}
|
||||||
}
|
}
|
||||||
"###, CompletionKind::Keyword),
|
"###, CompletionKind::Keyword),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user