mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Suggest .await
when type impls IntoFuture
This commit is contained in:
parent
5810c8188a
commit
dc3219bb11
2 changed files with 42 additions and 7 deletions
|
@ -2780,19 +2780,28 @@ 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: &dyn HirDatabase) -> bool {
|
||||
// FIXME: This should be checking for IntoFuture trait, but I don't know how to find the
|
||||
// right TraitId in this crate.
|
||||
let std_future_trait = db
|
||||
.lang_item(self.env.krate, SmolStr::new_inline("future_trait"))
|
||||
.and_then(|it| it.as_trait());
|
||||
let std_future_trait = match std_future_trait {
|
||||
let trait_ = db
|
||||
.lang_item(self.env.krate, SmolStr::new_inline("into_future"))
|
||||
.and_then(|it| {
|
||||
let into_future_fn = it.as_function()?;
|
||||
let assoc_item = as_assoc_item(db, AssocItem::Function, into_future_fn)?;
|
||||
let into_future_trait = assoc_item.containing_trait_or_trait_impl(db)?;
|
||||
Some(into_future_trait.id)
|
||||
})
|
||||
.or_else(|| {
|
||||
let future_trait =
|
||||
db.lang_item(self.env.krate, SmolStr::new_inline("future_trait"))?;
|
||||
future_trait.as_trait()
|
||||
});
|
||||
|
||||
let trait_ = match trait_ {
|
||||
Some(it) => it,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let canonical_ty =
|
||||
Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(Interner) };
|
||||
method_resolution::implements_trait(&canonical_ty, db, self.env.clone(), std_future_trait)
|
||||
method_resolution::implements_trait(&canonical_ty, db, self.env.clone(), trait_)
|
||||
}
|
||||
|
||||
/// Checks that particular type `ty` implements `std::ops::FnOnce`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue