@@ -27,6 +27,7 @@ use hir_def::{
2727use hir_expand:: {
2828 builtin_fn_macro:: BuiltinFnLikeExpander ,
2929 hygiene:: Hygiene ,
30+ mod_path:: path,
3031 name,
3132 name:: { AsName , Name } ,
3233 HirFileId , InFile ,
@@ -269,14 +270,35 @@ impl SourceAnalyzer {
269270 db : & dyn HirDatabase ,
270271 await_expr : & ast:: AwaitExpr ,
271272 ) -> Option < FunctionId > {
272- let ty = self . ty_of_expr ( db, & await_expr. expr ( ) ?. into ( ) ) ?;
273+ let mut ty = self . ty_of_expr ( db, & await_expr. expr ( ) ?. into ( ) ) ?. clone ( ) ;
274+
275+ let into_future_trait = self
276+ . resolver
277+ . resolve_known_trait ( db. upcast ( ) , & path ! [ core:: future:: IntoFuture ] )
278+ . map ( Trait :: from) ;
279+
280+ if let Some ( into_future_trait) = into_future_trait {
281+ let type_ = Type :: new_with_resolver ( db, & self . resolver , ty. clone ( ) ) ;
282+ if type_. impls_trait ( db, into_future_trait, & [ ] ) {
283+ let items = into_future_trait. items ( db) ;
284+ let into_future_type = items. into_iter ( ) . find_map ( |item| match item {
285+ AssocItem :: TypeAlias ( alias)
286+ if alias. name ( db) == hir_expand:: name![ IntoFuture ] =>
287+ {
288+ Some ( alias)
289+ }
290+ _ => None ,
291+ } ) ?;
292+ let future_trait = type_. normalize_trait_assoc_type ( db, & [ ] , into_future_type) ?;
293+ ty = future_trait. ty ;
294+ }
295+ }
273296
274- let op_fn = db
297+ let poll_fn = db
275298 . lang_item ( self . resolver . krate ( ) , hir_expand:: name![ poll] . to_smol_str ( ) ) ?
276299 . as_function ( ) ?;
277- let substs = hir_ty:: TyBuilder :: subst_for_def ( db, op_fn) . push ( ty. clone ( ) ) . build ( ) ;
278-
279- Some ( self . resolve_impl_method_or_trait_def ( db, op_fn, & substs) )
300+ let substs = hir_ty:: TyBuilder :: subst_for_def ( db, poll_fn) . push ( ty. clone ( ) ) . build ( ) ;
301+ Some ( self . resolve_impl_method_or_trait_def ( db, poll_fn, & substs) )
280302 }
281303
282304 pub ( crate ) fn resolve_prefix_expr (
0 commit comments