Move impls_future to Type, where it belongs

This commit is contained in:
Aleksey Kladov 2020-01-14 11:27:00 +01:00
parent 0358f5fdeb
commit 52e7f67128
4 changed files with 21 additions and 28 deletions

View file

@ -21,8 +21,8 @@ use hir_expand::{
MacroDefId,
};
use hir_ty::{
autoderef, display::HirFormatter, expr::ExprValidator, ApplicationTy, Canonical, InEnvironment,
TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk,
autoderef, display::HirFormatter, expr::ExprValidator, method_resolution::implements_trait,
ApplicationTy, Canonical, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk,
};
use ra_db::{CrateId, Edition, FileId};
use ra_prof::profile;
@ -878,6 +878,22 @@ impl Type {
}
}
/// 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) -> bool {
let krate = self.krate;
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: self.ty.value.clone(), num_vars: 0 };
implements_trait(&canonical_ty, db, self.ty.environment.clone(), krate, std_future_trait)
}
// FIXME: this method is broken, as it doesn't take closures into account.
pub fn as_callable(&self) -> Option<CallableDef> {
Some(self.ty.value.as_callable()?.0)