From 5ccef564560df65db0cb761cb27751f15821f1af Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Sat, 2 Jan 2021 22:03:21 +1100 Subject: [PATCH 01/13] Explain why borrows can't be held across yield point in async blocks --- .../diagnostics/conflict_errors.rs | 10 ++++++ .../issues/issue-78938-async-block.rs | 33 +++++++++++++++++++ .../issues/issue-78938-async-block.stderr | 30 +++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/test/ui/async-await/issues/issue-78938-async-block.rs create mode 100644 src/test/ui/async-await/issues/issue-78938-async-block.stderr diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index 0bb09e26f03e8..1dd102f4f347f 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -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 => { diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.rs b/src/test/ui/async-await/issues/issue-78938-async-block.rs new file mode 100644 index 0000000000000..e3d8eb7377223 --- /dev/null +++ b/src/test/ui/async-await/issues/issue-78938-async-block.rs @@ -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>) {} + +fn spawn(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 { + loop {} + } +} + +fn main() {} \ No newline at end of file diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.stderr b/src/test/ui/async-await/issues/issue-78938-async-block.stderr new file mode 100644 index 0000000000000..83cf1a5bc46e8 --- /dev/null +++ b/src/test/ui/async-await/issues/issue-78938-async-block.stderr @@ -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`. From 12f17957432fa03a8fe57c2b6063c662add45c2c Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Sun, 3 Jan 2021 03:53:50 +1100 Subject: [PATCH 02/13] Fix location of error message explanation --- .../diagnostics/conflict_errors.rs | 22 ++++++++++--------- .../issues/issue-78938-async-block.rs | 6 ++--- .../issues/issue-78938-async-block.stderr | 4 ++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index 1dd102f4f347f..43e9701aa25ac 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -1323,16 +1323,6 @@ 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 => { @@ -1349,6 +1339,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ), }; 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 } diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.rs b/src/test/ui/async-await/issues/issue-78938-async-block.rs index e3d8eb7377223..a16061fd979d9 100644 --- a/src/test/ui/async-await/issues/issue-78938-async-block.rs +++ b/src/test/ui/async-await/issues/issue-78938-async-block.rs @@ -16,7 +16,7 @@ fn game_loop(v: Arc>) {} fn spawn(future: F) -> JoinHandle where F: Future + Send + 'static, - F::Output: Send + 'static, + F::Output: Send + 'static, { loop {} } @@ -26,8 +26,8 @@ struct JoinHandle; impl Future for JoinHandle { type Output = (); fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - loop {} + loop {} } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.stderr b/src/test/ui/async-await/issues/issue-78938-async-block.stderr index 83cf1a5bc46e8..604c47b430f82 100644 --- a/src/test/ui/async-await/issues/issue-78938-async-block.stderr +++ b/src/test/ui/async-await/issues/issue-78938-async-block.stderr @@ -8,8 +8,6 @@ LL | | game_loop(Arc::clone(&room_ref)) 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 | @@ -18,6 +16,8 @@ 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: 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 { From 2b9c8ff6b37e0fd9143ba0f5a1fd11057880cebc Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Sun, 3 Jan 2021 04:00:51 +1100 Subject: [PATCH 03/13] Update issue-78938-async-block.rs Fix whitespace --- src/test/ui/async-await/issues/issue-78938-async-block.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.rs b/src/test/ui/async-await/issues/issue-78938-async-block.rs index a16061fd979d9..86afef08fc7c9 100644 --- a/src/test/ui/async-await/issues/issue-78938-async-block.rs +++ b/src/test/ui/async-await/issues/issue-78938-async-block.rs @@ -26,7 +26,7 @@ struct JoinHandle; impl Future for JoinHandle { type Output = (); fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - loop {} + loop {} } } From 9e345a58936edc81acf09d89675f71711f3d2439 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Sat, 9 Jan 2021 19:46:19 +1100 Subject: [PATCH 04/13] Revise async block error message --- .../diagnostics/conflict_errors.rs | 31 +++++++++---------- .../issues/issue-78938-async-block.stderr | 10 +----- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index 43e9701aa25ac..85ea70cefba3f 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -1324,33 +1324,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Applicability::MachineApplicable, ); - let msg = match category { + match category { ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => { - format!("{} is returned here", kind) + let msg = format!("{} is returned here", kind); + err.span_note(constraint_span, &msg); } ConstraintCategory::CallArgument => { 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!( "report_escaping_closure_capture called with unexpected constraint \ 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 } diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.stderr b/src/test/ui/async-await/issues/issue-78938-async-block.stderr index 604c47b430f82..4468975b2f5c3 100644 --- a/src/test/ui/async-await/issues/issue-78938-async-block.stderr +++ b/src/test/ui/async-await/issues/issue-78938-async-block.stderr @@ -8,15 +8,7 @@ LL | | game_loop(Arc::clone(&room_ref)) LL | | }); | |_____^ may outlive borrowed value `room_ref` | -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 | | }); - | |_____^ - = note: borrows cannot be held across a yield point, because the stack space of the current function is not preserved + = note: async blocks are not executed immediately and either must take a reference or ownership of outside variables they use = 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 | From 757bd23503e16311190c943efba093d70d6b3454 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Sat, 9 Jan 2021 20:02:47 +1100 Subject: [PATCH 05/13] Remove trailing whitespace --- .../src/borrow_check/diagnostics/conflict_errors.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index 85ea70cefba3f..49cdf8c3cbec8 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -1331,11 +1331,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } ConstraintCategory::CallArgument => { fr_name.highlight_region_name(&mut err); - if matches!(use_span.generator_kind(), Some(generator_kind) + 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.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 { From 3ee3071344334a0ac9defe876d6781d2d9658933 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Tue, 12 Jan 2021 14:12:12 +1100 Subject: [PATCH 06/13] Update src/test/ui/async-await/issues/issue-78938-async-block.stderr Co-authored-by: Esteban Kuber --- src/test/ui/async-await/issues/issue-78938-async-block.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.stderr b/src/test/ui/async-await/issues/issue-78938-async-block.stderr index 4468975b2f5c3..5450038c0d956 100644 --- a/src/test/ui/async-await/issues/issue-78938-async-block.stderr +++ b/src/test/ui/async-await/issues/issue-78938-async-block.stderr @@ -8,7 +8,7 @@ LL | | game_loop(Arc::clone(&room_ref)) LL | | }); | |_____^ may outlive borrowed value `room_ref` | - = note: async blocks are not executed immediately and either must take a reference or ownership of outside variables they use + = note: async blocks are not executed immediately and must either take a reference or ownership of outside variables they use = 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 | From 7f41465f6d025445374626c14958f8181a54c639 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Wed, 13 Jan 2021 23:37:49 +1100 Subject: [PATCH 07/13] Move help link to error index --- .../src/error_codes/E0373.md | 22 +++++++++++++++++++ .../diagnostics/conflict_errors.rs | 4 +--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0373.md b/compiler/rustc_error_codes/src/error_codes/E0373.md index fd96987793115..1dec705260a61 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0373.md +++ b/compiler/rustc_error_codes/src/error_codes/E0373.md @@ -50,3 +50,25 @@ fn foo() -> Box u32> { Now that the closure has its own copy of the data, there's no need to worry about safety. + +This error may also be encountered while using `async` blocks: + +```compile_fail,E0373 +use std::sync::Arc; +use tokio::runtime::Runtime; // 0.3.1 + +async fn f() { + let room_ref = Arc::new(Vec::new()); + + let gameloop_handle = Runtime::new().unwrap().spawn(async { + game_loop(Arc::clone(&room_ref)) + }); + gameloop_handle.await; +} + +fn game_loop(v: Arc>) {} +``` + +Similarly to closures, `async` blocks are not executed immediately and may +capture closed-over data by reference. For more information, see +https://rust-lang.github.io/async-book/03_async_await/01_chapter.html. \ No newline at end of file diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index 49cdf8c3cbec8..fb817d3ca1e72 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -1335,11 +1335,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if matches!(generator_kind, GeneratorKind::Async(_))) { err.note( - "async blocks are not executed immediately and either must take a \ + "async blocks are not executed immediately and must either 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); From f5c428799f42a34cc22621cc865fba787a32b405 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Thu, 14 Jan 2021 01:02:49 +1100 Subject: [PATCH 08/13] Bless test output --- src/test/ui/async-await/issues/issue-78938-async-block.stderr | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.stderr b/src/test/ui/async-await/issues/issue-78938-async-block.stderr index 5450038c0d956..01ffc48d6542e 100644 --- a/src/test/ui/async-await/issues/issue-78938-async-block.stderr +++ b/src/test/ui/async-await/issues/issue-78938-async-block.stderr @@ -9,7 +9,6 @@ LL | | }); | |_____^ may outlive borrowed value `room_ref` | = note: async blocks are not executed immediately and must either take a reference or ownership of outside variables they use - = 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 | LL | let gameloop_handle = spawn(async move { From a9ead34371e92767f0dfcf0d6d347a65988420af Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Thu, 14 Jan 2021 01:21:27 +1100 Subject: [PATCH 09/13] Fix whitespace --- compiler/rustc_error_codes/src/error_codes/E0373.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0373.md b/compiler/rustc_error_codes/src/error_codes/E0373.md index 1dec705260a61..8da16eb6e5235 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0373.md +++ b/compiler/rustc_error_codes/src/error_codes/E0373.md @@ -70,5 +70,5 @@ fn game_loop(v: Arc>) {} ``` Similarly to closures, `async` blocks are not executed immediately and may -capture closed-over data by reference. For more information, see -https://rust-lang.github.io/async-book/03_async_await/01_chapter.html. \ No newline at end of file +capture closed-over data by reference. For more information, see +https://rust-lang.github.io/async-book/03_async_await/01_chapter.html. From 174135fb3b212f53c4b24ffb243398306b9146d0 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Thu, 14 Jan 2021 17:15:04 +1100 Subject: [PATCH 10/13] Fix error E0373 documentation --- .../src/error_codes/E0373.md | 30 ++++++++++++++----- .../issues/issue-78938-async-block.rs | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0373.md b/compiler/rustc_error_codes/src/error_codes/E0373.md index 8da16eb6e5235..0723897614f79 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0373.md +++ b/compiler/rustc_error_codes/src/error_codes/E0373.md @@ -54,19 +54,35 @@ about safety. This error may also be encountered while using `async` blocks: ```compile_fail,E0373 -use std::sync::Arc; -use tokio::runtime::Runtime; // 0.3.1 +use std::{sync::Arc, future::Future, pin::Pin, task::{Context, Poll}}; async fn f() { - let room_ref = Arc::new(Vec::new()); + let v = Arc::new(Vec::new()); - let gameloop_handle = Runtime::new().unwrap().spawn(async { - game_loop(Arc::clone(&room_ref)) + let handle = spawn(async { //~ ERROR E0373 + g(Arc::clone(&v)) }); - gameloop_handle.await; + handle.await; } -fn game_loop(v: Arc>) {} +fn g(v: Arc>) {} + +fn spawn(future: F) -> JoinHandle +where + F: Future + Send + 'static, + F::Output: Send + 'static, +{ + unimplemented!() +} + +struct JoinHandle; + +impl Future for JoinHandle { + type Output = (); + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + unimplemented!() + } +} ``` Similarly to closures, `async` blocks are not executed immediately and may diff --git a/src/test/ui/async-await/issues/issue-78938-async-block.rs b/src/test/ui/async-await/issues/issue-78938-async-block.rs index 86afef08fc7c9..36f7160198526 100644 --- a/src/test/ui/async-await/issues/issue-78938-async-block.rs +++ b/src/test/ui/async-await/issues/issue-78938-async-block.rs @@ -1,6 +1,6 @@ // edition:2018 -use std::{sync::Arc, future::Future, pin::Pin, task::{Context,Poll}}; +use std::{sync::Arc, future::Future, pin::Pin, task::{Context, Poll}}; async fn f() { let room_ref = Arc::new(Vec::new()); From 63deae5e2525ab7428b205d13953423a6cd91bdd Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Thu, 14 Jan 2021 21:52:38 +1100 Subject: [PATCH 11/13] Fix E0373 code example --- compiler/rustc_error_codes/src/error_codes/E0373.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0373.md b/compiler/rustc_error_codes/src/error_codes/E0373.md index 0723897614f79..540a88a0d959a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0373.md +++ b/compiler/rustc_error_codes/src/error_codes/E0373.md @@ -53,7 +53,7 @@ about safety. This error may also be encountered while using `async` blocks: -```compile_fail,E0373 +```compile_fail,E0373,edition2018 use std::{sync::Arc, future::Future, pin::Pin, task::{Context, Poll}}; async fn f() { From 5468d9805aba869e7712b5aadabb021e692ba1d0 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Fri, 15 Jan 2021 16:50:48 +1100 Subject: [PATCH 12/13] Simplify E0373 async code example --- .../src/error_codes/E0373.md | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0373.md b/compiler/rustc_error_codes/src/error_codes/E0373.md index 540a88a0d959a..effa597aad918 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0373.md +++ b/compiler/rustc_error_codes/src/error_codes/E0373.md @@ -54,35 +54,18 @@ about safety. This error may also be encountered while using `async` blocks: ```compile_fail,E0373,edition2018 -use std::{sync::Arc, future::Future, pin::Pin, task::{Context, Poll}}; +use std::future::Future; async fn f() { - let v = Arc::new(Vec::new()); - - let handle = spawn(async { //~ ERROR E0373 - g(Arc::clone(&v)) + let v = vec![1, 2, 3i32]; + spawn(async { //~ ERROR E0373 + println!("{:?}", v) }); - handle.await; } -fn g(v: Arc>) {} - -fn spawn(future: F) -> JoinHandle -where - F: Future + Send + 'static, - F::Output: Send + 'static, -{ +fn spawn(future: F) { unimplemented!() } - -struct JoinHandle; - -impl Future for JoinHandle { - type Output = (); - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - unimplemented!() - } -} ``` Similarly to closures, `async` blocks are not executed immediately and may From 3e9c95b9d44aba57ee70a596b73af514046b4b26 Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Sat, 16 Jan 2021 03:32:54 +1100 Subject: [PATCH 13/13] Update compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs Co-authored-by: Esteban Kuber --- .../rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index fb817d3ca1e72..9325f94393ff1 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -1331,9 +1331,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } ConstraintCategory::CallArgument => { fr_name.highlight_region_name(&mut err); - if matches!(use_span.generator_kind(), Some(generator_kind) - if matches!(generator_kind, GeneratorKind::Async(_))) - { + if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) { err.note( "async blocks are not executed immediately and must either take a \ reference or ownership of outside variables they use",