@@ -27,6 +27,7 @@ use hir_def::{
27
27
use hir_expand:: {
28
28
builtin_fn_macro:: BuiltinFnLikeExpander ,
29
29
hygiene:: Hygiene ,
30
+ mod_path:: path,
30
31
name,
31
32
name:: { AsName , Name } ,
32
33
HirFileId , InFile ,
@@ -269,14 +270,35 @@ impl SourceAnalyzer {
269
270
db : & dyn HirDatabase ,
270
271
await_expr : & ast:: AwaitExpr ,
271
272
) -> 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
+ }
273
296
274
- let op_fn = db
297
+ let poll_fn = db
275
298
. lang_item ( self . resolver . krate ( ) , hir_expand:: name![ poll] . to_smol_str ( ) ) ?
276
299
. 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) )
280
302
}
281
303
282
304
pub ( crate ) fn resolve_prefix_expr (
0 commit comments