Skip to content

Commit eddf806

Browse files
Suggest returning tail expressions in async fn's
1 parent 83b15bf commit eddf806

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir as hir;
99
use rustc_hir::def::{CtorOf, DefKind};
1010
use rustc_hir::lang_items::LangItem;
1111
use rustc_hir::{Expr, ExprKind, ItemKind, Node, Path, QPath, Stmt, StmtKind, TyKind};
12-
use rustc_infer::infer;
12+
use rustc_infer::infer::{self, TyCtxtInferExt};
1313
use rustc_middle::lint::in_external_macro;
1414
use rustc_middle::ty::{self, Binder, Ty};
1515
use rustc_span::symbol::{kw, sym};
@@ -608,6 +608,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608608
let bound_vars = self.tcx.late_bound_vars(fn_id);
609609
let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars));
610610
let ty = self.normalize_associated_types_in(expr.span, ty);
611+
let ty = match self.tcx.asyncness(fn_id.owner) {
612+
hir::IsAsync::Async => self.tcx.infer_ctxt().enter(|infcx| {
613+
infcx.get_impl_future_output_ty(ty).unwrap_or_else(|| {
614+
span_bug!(
615+
fn_decl.output.span(),
616+
"failed to get output type of async function"
617+
)
618+
})
619+
}),
620+
hir::IsAsync::NotAsync => ty,
621+
};
611622
if self.can_coerce(found, ty) {
612623
err.multipart_suggestion(
613624
"you might have meant to return this value",

0 commit comments

Comments
 (0)