1
Fork 0

Revise async block error message

This commit is contained in:
1000teslas 2021-01-09 19:46:19 +11:00
parent 2b9c8ff6b3
commit 9e345a5893
2 changed files with 16 additions and 25 deletions

View file

@ -1324,33 +1324,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
let msg = match category { match category {
ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => { ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => {
format!("{} is returned here", kind) let msg = format!("{} is returned here", kind);
err.span_note(constraint_span, &msg);
} }
ConstraintCategory::CallArgument => { ConstraintCategory::CallArgument => {
fr_name.highlight_region_name(&mut err); fr_name.highlight_region_name(&mut err);
format!("function requires argument type to outlive `{}`", fr_name) if matches!(use_span.generator_kind(), Some(generator_kind)
if matches!(generator_kind, GeneratorKind::Async(_)))
{
err.note("async blocks are not executed immediately and either must take a \
reference or ownership of outside variables they use");
err.help("see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor \
for more information");
} else {
let msg = format!("function requires argument type to outlive `{}`", fr_name);
err.span_note(constraint_span, &msg);
}
} }
_ => bug!( _ => bug!(
"report_escaping_closure_capture called with unexpected constraint \ "report_escaping_closure_capture called with unexpected constraint \
category: `{:?}`", category: `{:?}`",
category category
), ),
};
err.span_note(constraint_span, &msg);
if let ConstraintCategory::CallArgument = category {
if let Some(generator_kind) = use_span.generator_kind() {
if let GeneratorKind::Async(_) = generator_kind {
err.note(
"borrows cannot be held across a yield point, because the stack \
space of the current function is not preserved",
);
err.help("see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor \
for more information");
}
}
} }
err err
} }

View file

@ -8,15 +8,7 @@ LL | | game_loop(Arc::clone(&room_ref))
LL | | }); LL | | });
| |_____^ may outlive borrowed value `room_ref` | |_____^ may outlive borrowed value `room_ref`
| |
note: function requires argument type to outlive `'static` = note: async blocks are not executed immediately and either must take a reference or ownership of outside variables they use
--> $DIR/issue-78938-async-block.rs:8:33
|
LL | let gameloop_handle = spawn(async {
| _________________________________^
LL | | game_loop(Arc::clone(&room_ref))
LL | | });
| |_____^
= note: borrows cannot be held across a yield point, because the stack space of the current function is not preserved
= help: see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor for more information = help: see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor for more information
help: to force the async block to take ownership of `room_ref` (and any other referenced variables), use the `move` keyword help: to force the async block to take ownership of `room_ref` (and any other referenced variables), use the `move` keyword
| |