Change:
emits the following error The correct code needs the to be part of the block because it is a stack allocation that needs to be in the generator: Ideally, the error message would mention : thanks to for bringing this up! CC <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
We could also consider suggesting an block, similar to the hints we provide for closures.
Marking this as a focus item. assign

Discussion:
let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0)); let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place); <ins> debug!( "report_borrowed_value_does_not_live_long_enough(place_desc: {:?}, explanation: {:?})", place_desc, explanation ); </ins> let err = match (place_desc, explanation) { (Some(_), _) if self.is_place_thread_local(root_place) => { self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span)

&format!("`{}`", name), ), ( <ins> Some(ref name), BorrowExplanation::MustBeValidFor { category: category @ ConstraintCategory::OpaqueType, from_closure: false, ref region_name, span, .. }, ) if borrow_spans.for_generator() => self.report_escaping_closure_capture( borrow_spans.args_or_use(), borrow_span, region_name, category, span, &format!("`{}`", name), ), ( </ins> ref name, BorrowExplanation::MustBeValidFor { category: ConstraintCategory::Assignment,

ConstraintCategory::Return => { err.span_note(constraint_span, "closure is returned here"); } <ins> ConstraintCategory::OpaqueType => { err.span_note(constraint_span, "generator is returned here"); } </ins> ConstraintCategory::CallArgument => { fr_name.highlight_region_name(&mut err); err.span_note(

mod find_use; <ins> #[derive(Debug)] </ins> pub(in crate::borrow_check) enum BorrowExplanation { UsedLater(LaterUseKind, Span), UsedLaterInLoop(LaterUseKind, Span),

Unexplained, } <del> #[derive(Clone, Copy)] </del> <ins> #[derive(Clone, Copy, Debug)] </ins> pub(in crate::borrow_check) enum LaterUseKind { TraitCapture, ClosureCapture,

<ins> // edition:2018 // run-rustfix fn foo() -> Box<impl std::future::Future<Output = u32>> { let x = 0u32; Box::new(async move { x } ) //~^ ERROR E0373 } fn main() { let _foo = foo(); } </ins>

<ins> // edition:2018 // run-rustfix fn foo() -> Box<impl std::future::Future<Output = u32>> { let x = 0u32; Box::new(async { x } ) //~^ ERROR E0373 } fn main() { let _foo = foo(); } </ins>

<ins> error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function --> $DIR/async-borrowck-escaping-block-error.rs:6:20 | LL |     Box::new(async { x } ) |                    ^^-^^ |                    | | |                    | `x` is borrowed here |                    may outlive borrowed value `x` | note: generator is returned here --> $DIR/async-borrowck-escaping-block-error.rs:4:13 | LL | fn foo() -> Box<impl std::future::Future<Output = u32>> { |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword | LL |     Box::new(async move { x } ) |                    ^^^^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0373`. </ins>