@@ -1324,33 +1324,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13241324 Applicability :: MachineApplicable ,
13251325 ) ;
13261326
1327- let msg = match category {
1327+ match category {
13281328 ConstraintCategory :: Return ( _) | ConstraintCategory :: OpaqueType => {
1329- format ! ( "{} is returned here" , kind)
1329+ let msg = format ! ( "{} is returned here" , kind) ;
1330+ err. span_note ( constraint_span, & msg) ;
13301331 }
13311332 ConstraintCategory :: CallArgument => {
13321333 fr_name. highlight_region_name ( & mut err) ;
1333- format ! ( "function requires argument type to outlive `{}`" , fr_name)
1334+ if matches ! ( use_span. generator_kind( ) , Some ( generator_kind)
1335+ if matches!( generator_kind, GeneratorKind :: Async ( _) ) )
1336+ {
1337+ err. note ( "async blocks are not executed immediately and either must take a \
1338+ reference or ownership of outside variables they use") ;
1339+ err. help ( "see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor \
1340+ for more information") ;
1341+ } else {
1342+ let msg = format ! ( "function requires argument type to outlive `{}`" , fr_name) ;
1343+ err. span_note ( constraint_span, & msg) ;
1344+ }
13341345 }
13351346 _ => bug ! (
13361347 "report_escaping_closure_capture called with unexpected constraint \
13371348 category: `{:?}`",
13381349 category
13391350 ) ,
1340- } ;
1341- err. span_note ( constraint_span, & msg) ;
1342- if let ConstraintCategory :: CallArgument = category {
1343- if let Some ( generator_kind) = use_span. generator_kind ( ) {
1344- if let GeneratorKind :: Async ( _) = generator_kind {
1345- err. note (
1346- "borrows cannot be held across a yield point, because the stack \
1347- space of the current function is not preserved",
1348- ) ;
1349- err. help ( "see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor \
1350- for more information") ;
1351- }
1352- }
13531351 }
1352+
13541353 err
13551354 }
13561355
0 commit comments