@@ -1324,33 +1324,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1324
1324
Applicability :: MachineApplicable ,
1325
1325
) ;
1326
1326
1327
- let msg = match category {
1327
+ match category {
1328
1328
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) ;
1330
1331
}
1331
1332
ConstraintCategory :: CallArgument => {
1332
1333
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
+ }
1334
1345
}
1335
1346
_ => bug ! (
1336
1347
"report_escaping_closure_capture called with unexpected constraint \
1337
1348
category: `{:?}`",
1338
1349
category
1339
1350
) ,
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
- }
1353
1351
}
1352
+
1354
1353
err
1355
1354
}
1356
1355
0 commit comments