This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -1364,6 +1364,23 @@ impl Function {
1364
1364
Type :: new_with_resolver_inner ( db, & resolver, ty)
1365
1365
}
1366
1366
1367
+ pub fn async_ret_type ( self , db : & dyn HirDatabase ) -> Option < Type > {
1368
+ if !self . is_async ( db) {
1369
+ return None ;
1370
+ }
1371
+ let resolver = self . id . resolver ( db. upcast ( ) ) ;
1372
+ let substs = TyBuilder :: placeholder_subst ( db, self . id ) ;
1373
+ let callable_sig = db. callable_item_signature ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1374
+ let ret_ty = callable_sig. ret ( ) . clone ( ) ;
1375
+ for pred in ret_ty. impl_trait_bounds ( db) . into_iter ( ) . flatten ( ) {
1376
+ if let WhereClause :: AliasEq ( output_eq) = pred. into_value_and_skipped_binders ( ) . 0 {
1377
+ return Type :: new_with_resolver_inner ( db, & resolver, output_eq. ty ) . into ( ) ;
1378
+ }
1379
+ }
1380
+ never ! ( "Async fn ret_type should be impl Future" ) ;
1381
+ None
1382
+ }
1383
+
1367
1384
pub fn self_param ( self , db : & dyn HirDatabase ) -> Option < SelfParam > {
1368
1385
if !db. function_data ( self . id ) . has_self_param ( ) {
1369
1386
return None ;
Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ fn should_add_parens(ctx: &CompletionContext) -> bool {
228
228
}
229
229
230
230
fn detail ( db : & dyn HirDatabase , func : hir:: Function ) -> String {
231
- let ret_ty = func. ret_type ( db) ;
231
+ let ret_ty = func. async_ret_type ( db ) . unwrap_or_else ( || func . ret_type ( db) ) ;
232
232
let mut detail = String :: new ( ) ;
233
233
234
234
if func. is_const ( db) {
Original file line number Diff line number Diff line change @@ -624,20 +624,21 @@ fn main() {
624
624
625
625
#[ test]
626
626
fn detail_async_fn ( ) {
627
- // FIXME: #11438
628
627
check_empty (
629
628
r#"
630
629
//- minicore: future, sized
631
630
trait Trait<T> {}
632
631
async fn foo() -> u8 {}
632
+ async fn bar<U>() -> impl Trait<U> {}
633
633
fn main() {
634
634
self::$0
635
635
}
636
636
"# ,
637
637
expect ! [ [ r"
638
638
tt Trait
639
639
fn main() fn()
640
- fn foo() async fn() -> impl Future<Output = u8>
640
+ fn bar() async fn() -> impl Trait<U>
641
+ fn foo() async fn() -> u8
641
642
" ] ] ,
642
643
) ;
643
644
}
You can’t perform that action at this time.
0 commit comments