Change:
Given the following code: The current output is: <!-- The following is not always necessary. --Ideally the output should look like it does for the : <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
label +A-async-await +D-papercut
I'm gonna try and take a shot at this. claim
Thanks for putting up a PR so quickly, label +AsyncAwait-Triaged +AsyncAwait-Polish

Discussion:
use rustc_hir::def::{CtorOf, DefKind}; use rustc_hir::lang_items::LangItem; use rustc_hir::{Expr, ExprKind, ItemKind, Node, Path, QPath, Stmt, StmtKind, TyKind}; <del> use rustc_infer::infer; </del> <ins> use rustc_infer::infer::{self, TyCtxtInferExt}; </ins> use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, Binder, Ty}; use rustc_span::symbol::{kw, sym};

let bound_vars = self.tcx.late_bound_vars(fn_id); let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars)); let ty = self.normalize_associated_types_in(expr.span, ty); <ins> let ty = match self.tcx.asyncness(fn_id.owner) { hir::IsAsync::Async => self.tcx.infer_ctxt().enter(|infcx| { infcx.get_impl_future_output_ty(ty).unwrap_or_else(|| { span_bug!( fn_decl.output.span(), "failed to get output type of async function" ) }) }), hir::IsAsync::NotAsync => ty, }; </ins> if self.can_coerce(found, ty) { err.multipart_suggestion( "you might have meant to return this value",

<ins> // > Suggest `return`ing tail expressions that match return type // > // > Some newcomers are confused by the behavior of tail expressions, // > interpreting that "leaving out the `;` makes it the return value". // > To help them go in the right direction, suggest using `return` instead // > when applicable. // (original commit description for this test) // // This test was amended to also serve as a regression test for #92308, where // this suggestion would not trigger with async functions. // // edition:2018 </ins> fn main() { let _ = foo(true); }

fn foo(x: bool) -> Result<f64, i32> { if x { Err(42) //~ ERROR mismatched types <ins> //| HELP you might have meant to return this value } Ok(42.0) } async fn bar(x: bool) -> Result<f64, i32> { if x { Err(42) //~ ERROR mismatched types //| HELP you might have meant to return this value </ins> } Ok(42.0) }

error[E0308]: mismatched types <del> --> $DIR/tail-expr-as-potential-return.rs:7:9 </del> <ins> --> $DIR/tail-expr-as-potential-return.rs:28:9 </ins> | LL | /     if x { LL | |         Err(42) | |         ^^^^^^^ expected `()`, found enum `Result` <ins> LL | |                 //| HELP you might have meant to return this value </ins> LL | |     } | |_____- expected this to be `()` |

LL |         return Err(42); |         ++++++        + <del> error: aborting due to previous error </del> <ins> error[E0308]: mismatched types --> $DIR/tail-expr-as-potential-return.rs:20:9 | LL | /     if x { LL | |         Err(42) | |         ^^^^^^^ expected `()`, found enum `Result` LL | |                 //| HELP you might have meant to return this value LL | |     } | |_____- expected this to be `()` | = note: expected unit type `()` found enum `Result<_, {integer}>` help: you might have meant to return this value | LL |         return Err(42); |         ++++++        + error: aborting due to 2 previous errors </ins> For more information about this error, try `rustc --explain E0308`.