Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5ccef56
Explain why borrows can't be held across yield point in async blocks
sledgehammervampire Jan 2, 2021
12f1795
Fix location of error message explanation
sledgehammervampire Jan 2, 2021
2b9c8ff
Update issue-78938-async-block.rs
sledgehammervampire Jan 2, 2021
9e345a5
Revise async block error message
sledgehammervampire Jan 9, 2021
757bd23
Remove trailing whitespace
sledgehammervampire Jan 9, 2021
04b6036
Make `--color always` apply to logging too
jyn514 Jan 11, 2021
3ee3071
Update src/test/ui/async-await/issues/issue-78938-async-block.stderr
sledgehammervampire Jan 12, 2021
b2f5048
stabilize the poll_map feature
KodrAus Jan 13, 2021
c200036
Put all feature gate tests under `feature-gates/`
camelid Jan 13, 2021
7f41465
Move help link to error index
sledgehammervampire Jan 13, 2021
f5c4287
Bless test output
sledgehammervampire Jan 13, 2021
a9ead34
Fix whitespace
sledgehammervampire Jan 13, 2021
174135f
Fix error E0373 documentation
sledgehammervampire Jan 14, 2021
63deae5
Fix E0373 code example
sledgehammervampire Jan 14, 2021
5468d98
Simplify E0373 async code example
sledgehammervampire Jan 15, 2021
0660b8b
Introduce {Ref, RefMut}::try_map for optional projections
udoprog Oct 27, 2020
3e9c95b
Update compiler/rustc_mir/src/borrow_check/diagnostics/conflict_error…
sledgehammervampire Jan 15, 2021
e8757af
Use Result and rename to filter_map
udoprog Dec 17, 2020
e3274fd
Remove doctree::Import
CraftSpider Jan 14, 2021
2a0c9e2
Address nit
CraftSpider Jan 14, 2021
e42c1b9
Fix JSON test
CraftSpider Jan 15, 2021
31b17f5
Add warning to compare.py about error messages
CraftSpider Jan 15, 2021
32a20f4
Change rebuild heuristic in BinaryHeap::append
hanmertens Jan 15, 2021
c625b97
add tracking issue to cell_filter_map
KodrAus Jan 16, 2021
eef383f
doctest: Reset errors before dropping the parse session
osa1 Jan 15, 2021
0ef5557
Add a test
osa1 Jan 16, 2021
b681631
codegen_cranelift: Fix redundant semicolon warn
osa1 Jan 16, 2021
8797986
Add a regression test for #76281
JohnTitor Jan 11, 2021
d0f8553
Rollup merge of #77435 - hanmertens:binary_heap_append, r=scottmcm
JohnTitor Jan 16, 2021
0e5dcaf
Rollup merge of #78455 - udoprog:refcell-opt-map, r=KodrAus
JohnTitor Jan 16, 2021
0d901f2
Rollup merge of #80614 - 1000teslas:issue-78938-fix, r=tmandry
JohnTitor Jan 16, 2021
046da7a
Rollup merge of #80901 - jyn514:better-colors, r=Mark-Simulacrum
JohnTitor Jan 16, 2021
e9a6063
Rollup merge of #80902 - JohnTitor:issue-76281, r=Mark-Simulacrum
JohnTitor Jan 16, 2021
605557f
Rollup merge of #80968 - KodrAus:stabilize/poll_map, r=Mark-Simulacrum
JohnTitor Jan 16, 2021
32e9c33
Rollup merge of #80971 - camelid:feature-gate-testsuite-organization,…
JohnTitor Jan 16, 2021
58c1b90
Rollup merge of #81021 - CraftSpider:rustdoc-remove-import, r=jyn514
JohnTitor Jan 16, 2021
6a131cb
Rollup merge of #81040 - osa1:fix_80992, r=jyn514
JohnTitor Jan 16, 2021
c8bca90
Rollup merge of #81065 - osa1:cranelift_semicolon_warning, r=jyn514
JohnTitor Jan 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Explain why borrows can't be held across yield point in async blocks
  • Loading branch information
sledgehammervampire committed Jan 10, 2021
commit 5ccef564560df65db0cb761cb27751f15821f1af
10 changes: 10 additions & 0 deletions compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
suggestion,
Applicability::MachineApplicable,
);
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");
}
}

let msg = match category {
ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => {
Expand Down
33 changes: 33 additions & 0 deletions src/test/ui/async-await/issues/issue-78938-async-block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// edition:2018

use std::{sync::Arc, future::Future, pin::Pin, task::{Context,Poll}};

async fn f() {
let room_ref = Arc::new(Vec::new());

let gameloop_handle = spawn(async { //~ ERROR E0373
game_loop(Arc::clone(&room_ref))
});
gameloop_handle.await;
}

fn game_loop(v: Arc<Vec<usize>>) {}

fn spawn<F>(future: F) -> JoinHandle
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
loop {}
}

struct JoinHandle;

impl Future for JoinHandle {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
loop {}
}
}

fn main() {}
30 changes: 30 additions & 0 deletions src/test/ui/async-await/issues/issue-78938-async-block.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error[E0373]: async block may outlive the current function, but it borrows `room_ref`, which is owned by the current function
--> $DIR/issue-78938-async-block.rs:8:39
|
LL | let gameloop_handle = spawn(async {
| _______________________________________^
LL | | game_loop(Arc::clone(&room_ref))
| | -------- `room_ref` is borrowed here
LL | | });
| |_____^ may outlive borrowed value `room_ref`
|
= 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
note: function requires argument type to outlive `'static`
--> $DIR/issue-78938-async-block.rs:8:33
|
LL | let gameloop_handle = spawn(async {
| _________________________________^
LL | | game_loop(Arc::clone(&room_ref))
LL | | });
| |_____^
help: to force the async block to take ownership of `room_ref` (and any other referenced variables), use the `move` keyword
|
LL | let gameloop_handle = spawn(async move {
LL | game_loop(Arc::clone(&room_ref))
LL | });
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0373`.