Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain why borrows can't be held across yield point in async blocks #80614

Merged
merged 13 commits into from
Jan 16, 2021

Conversation

sledgehammervampire
Copy link
Contributor

For #78938.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @matthewjasper (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 2, 2021
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
Checking which error codes lack tests...
Found 435 error codes
Found 0 error codes with no tests
Done!
tidy error: /checkout/src/test/ui/async-await/issues/issue-78938-async-block.rs:19: trailing whitespace
tidy error: /checkout/src/test/ui/async-await/issues/issue-78938-async-block.rs: missing trailing newline
some tidy checks failed

command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build"
expected success, got: exit code: 1

"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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add // ignore-tidy-linelength to the top of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I add // ignore-tidy-linelength to the top of the file and then run ./x.py test tidy I get the error ignoring line length unnecessarily.

@sledgehammervampire
Copy link
Contributor Author

@jyn514 I've fixed the error message to be part of the "function requires..." error now

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I know nothing about the borrow checker and this should probably have review from someone who does.

r? @tmandry maybe?

Comment on lines 1364 to 1365
"borrows cannot be held across a yield point, because the stack \
space of the current function is not preserved",
Copy link
Member

@jyn514 jyn514 Jan 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect I'm not sure this is actually correct, since it works as long as the executor isn't multi-threaded. I'm still a little hazy on how async borrows work, maybe we should go with @tmandry's explanation instead:

note: async blocks are not executed immediately and either must take a reference or ownership of outside variables they use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I actually don't understand that error message from @tmandry. How else could you use a variable, if not by reference or ownership? I'm contributing to the compiler in hopes of furthering my understanding of Rust. I find that the rules for the borrow checker are apparently simple, but because borrowing is so pervasively used throughout Rust, there are non obvious consequences, especially around things like closures (I actually haven't used async that much, but looking into the code, it seems like async and closures are somewhat similar regarding borrowing).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmandry's message is trying to succinctly explain that async blocks need to be turned into a struct internally that owns or directly references every binding it touches coming from outside the block. The wording as it stands isn't very "newcomer friendly", but I find it hard to improve on its use of jargon, and for people that don't understand it the link to the async book should still be helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the confusion. Maybe just this, plus the help text, is enough to get the point across?

note: async blocks are not executed immediately
help: to force the async block to take ownership of room_ref (and any other referenced variables), use the move keyword

or something like

note: async blocks are not executed immediately and by default refer to captured variables by reference

which seems a bit long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @estebank, your explanation of the error from @tmandry clears it up for me. I will use the original explanation.

@jyn514 jyn514 added A-async-await Area: Async & Await A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 4, 2021
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some unrelated comments for things I noticed that we can tackle elsewhere.

The logic seems correct and the link to the book will come in very handy. For the wording I'd prefer to follow Tyler's which is correct, if harder to understand for newcomers.

Comment on lines 11 to 18
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 | | });
| |_____^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would change or remove this note when caused by async blocks, particularly when we suggest async move...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this in my latest commit.

Comment on lines +21 to +17
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 | });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to check the suggestion that generates this becuase it seems to me we don't really need to show the whole block for this and we could make it less verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps show only the line with async?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing that requires "only" to modify the following

let args_span = use_span.args_or_use();
let suggestion = match tcx.sess.source_map().span_to_snippet(args_span) {
Ok(mut string) => {
if string.starts_with("async ") {
string.insert_str(6, "move ");
} else if string.starts_with("async|") {
string.insert_str(5, " move");
} else {
string.insert_str(0, "move ");
};
string
}
Err(_) => "move |<args>| <body>".to_string(),
};

The args_span should only point at the async { and the suggested code sould only be "async move {", where now it is the whole thing.

If you wish to tackle this in this PR, it'd be great, but I don't consider it a must have yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'll leave that for later or someone else.

Comment on lines 1364 to 1365
"borrows cannot be held across a yield point, because the stack \
space of the current function is not preserved",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmandry's message is trying to succinctly explain that async blocks need to be turned into a struct internally that owns or directly references every binding it touches coming from outside the block. The wording as it stands isn't very "newcomer friendly", but I find it hard to improve on its use of jargon, and for people that don't understand it the link to the async book should still be helpful.

Comment on lines 1360 to 1362
if let ConstraintCategory::CallArgument = category {
if let Some(generator_kind) = use_span.generator_kind() {
if let GeneratorKind::Async(_) = generator_kind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of some unnecessary nesting by writing

Suggested change
if let ConstraintCategory::CallArgument = category {
if let Some(generator_kind) = use_span.generator_kind() {
if let GeneratorKind::Async(_) = generator_kind {
if let (ConstraintCategory::CallArgument, Some(GeneratorKind::Async(_))) = (category, use_span.generator_kind()) {

"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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried this link can go stale. It seems like using the error index would be better, we can update this link there if it ever changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this page the error index? If so, which error are you referring to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the error index. I believe @tmandry's idea is to modify https://github.com/rust-lang/rust/blob/9e5f7d5631b8f4009ac1c693e585d4b7108d4275/compiler/rustc_error_codes/src/error_codes/E0373.md to include information from and/or a link to chapter 1 of the async book.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the link to error index in my latest commit.

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
extracting /checkout/obj/build/cache/2020-12-30/rustc-beta-x86_64-unknown-linux-gnu.tar.xz
downloading https://static.rust-lang.org/dist/2020-12-30/cargo-beta-x86_64-unknown-linux-gnu.tar.xz
#=#=#                                                                         
##O#- #                                                                       
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to static.rust-lang.org:443 
spurious failure, trying again
downloading https://static.rust-lang.org/dist/2020-12-30/cargo-beta-x86_64-unknown-linux-gnu.tar.xz

######################################################################## 100.0%
---
Checking which error codes lack tests...
Found 435 error codes
Found 0 error codes with no tests
Done!
tidy error: /checkout/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs:1334: trailing whitespace
some tidy checks failed

command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build"
expected success, got: exit code: 1

@sledgehammervampire
Copy link
Contributor Author

Uhh, sorry for the huge number of commits. I'm not very familiar with git, and tried rebasing on to master as per the rustc dev guide. Is there a way for me to fix this?

@seritools
Copy link
Contributor

fixed :)

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-9 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
.................................................................................................... 9000/11248
.................................................................................................... 9100/11248
.................................................................................................... 9200/11248
............................................i......i................................................ 9300/11248
...................................................................................iiiiii...iiiiiii. 9400/11248
.................................................................................................... 9600/11248
.................................................................................................... 9700/11248
.................................................................................................... 9800/11248
.................................................................................................... 9900/11248
---

---- [ui] ui/async-await/issues/issue-78938-async-block.rs stdout ----
diff of stderr:

8 LL | |     });
9    | |_____^ may outlive borrowed value `room_ref`
10    |
-    = note: async blocks are not executed immediately and must either take a reference or ownership of outside variables they use
+    = note: async blocks are not executed immediately and either must take a reference or ownership of outside variables they use
12    = help: see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor for more information
13 help: to force the async block to take ownership of `room_ref` (and any other referenced variables), use the `move` keyword


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/issues/issue-78938-async-block/issue-78938-async-block.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/issues/issue-78938-async-block/issue-78938-async-block.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args async-await/issues/issue-78938-async-block.rs`
error: 1 errors occurred comparing output.
status: exit code: 1
status: exit code: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/async-await/issues/issue-78938-async-block.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/issues/issue-78938-async-block" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/issues/issue-78938-async-block/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0373]: async block may outlive the current function, but it borrows `room_ref`, which is owned by the current function
   |
   |
LL |       let gameloop_handle = spawn(async { //~ ERROR E0373
   |  _______________________________________^
LL | |         game_loop(Arc::clone(&room_ref))
   | |                               -------- `room_ref` is borrowed here
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
   = 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 { //~ ERROR E0373
LL |         game_loop(Arc::clone(&room_ref))
LL |     });

error: aborting due to previous error

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

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu


command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--suite" "ui" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-9/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "9.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test --exclude src/tools/tidy
Build completed unsuccessfully in 0:16:35

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
Checking which error codes lack tests...
Found 435 error codes
Found 0 error codes with no tests
Done!
tidy error: /checkout/compiler/rustc_error_codes/src/error_codes/E0373.md:73: trailing whitespace
tidy error: /checkout/compiler/rustc_error_codes/src/error_codes/E0373.md: missing trailing newline
some tidy checks failed

command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build"
expected success, got: exit code: 1

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
Checking which error codes lack tests...
Found 435 error codes
Found 0 error codes with no tests
Done!
tidy error: /checkout/compiler/rustc_error_codes/src/error_codes/E0373.md:73: trailing whitespace
tidy error: /checkout/compiler/rustc_error_codes/src/error_codes/E0373.md: missing trailing newline
some tidy checks failed

command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build"
expected success, got: exit code: 1

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-9 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
.................................................................................................... 9000/11256
.................................................................................................... 9100/11256
.................................................................................................... 9200/11256
...................................................i......i......................................... 9300/11256
..........................................................................................iiiiii..ii 9400/11256
.................................................................................................... 9600/11256
.................................................................................................... 9700/11256
.................................................................................................... 9800/11256
.................................................................................................... 9900/11256
---
Suite("src/test/assembly") not skipped for "bootstrap::test::Assembly" -- not in ["src/tools/tidy"]
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 27 tests
iiiiiiiiiiiiiiiiiiiiiiiiiii

 finished in 0.081 seconds
Suite("src/test/incremental") not skipped for "bootstrap::test::Incremental" -- not in ["src/tools/tidy"]
Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
Suite("src/test/debuginfo") not skipped for "bootstrap::test::Debuginfo" -- not in ["src/tools/tidy"]
Check compiletest suite=debuginfo mode=debuginfo (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 116 tests
iiiiiiiiii.i.i..i...i.ii....i..i...ii..........iiii.........i.....i...i.......ii.i.ii......iiii....i 100/116
test result: ok. 78 passed; 0 failed; 38 ignored; 0 measured; 0 filtered out; finished in 2.41s

 finished in 2.494 seconds
Suite("src/test/ui-fulldeps") not skipped for "bootstrap::test::UiFullDeps" -- not in ["src/tools/tidy"]
---
Testing error-index stage2
doc tests for: /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md


command did not execute successfully: "/checkout/obj/build/bootstrap/debug/rustdoc" "-Winvalid_codeblock_attributes" "-Dwarnings" "-Znormalize-docs" "--test" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md" "--test-args" ""

stdout ----

running 982 tests
---
test /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index::E0778 (line 15672) ... ok

failures:

---- /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index::E0373 (line 6089) stdout ----
error[E0670]: `async fn` is not permitted in Rust 2015
 --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:6093:1
  |
6 | async fn f() {
  | ^^^^^ to use `async fn`, switch to Rust 2018 or later
  |
  = help: set `edition = "2018"` in `Cargo.toml`
  = note: for more on editions, read https://doc.rust-lang.org/edition-guide

error: expected one of `,` or `}`, found `(`
  --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:6097:18
   |
9  |     let gameloop_handle = Runtime::new().unwrap().spawn(async {
   |                                                         ----- `async` blocks are only allowed in Rust 2018 or later
10 |         game_loop(Arc::clone(&room_ref))
   |                  ^ expected one of `,` or `}`
   |
   = help: set `edition = "2018"` in `Cargo.toml`
   = note: for more on editions, read https://doc.rust-lang.org/edition-guide

error[E0433]: failed to resolve: maybe a missing crate `tokio`?
 --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:6091:5
  |
4 | use tokio::runtime::Runtime; // 0.3.1
  |     ^^^^^ maybe a missing crate `tokio`?
error[E0433]: failed to resolve: use of undeclared type `Runtime`
 --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:6096:27
  |
  |
9 |     let gameloop_handle = Runtime::new().unwrap().spawn(async {
  |                           ^^^^^^^ use of undeclared type `Runtime`
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0433, E0670.
For more information about an error, try `rustc --explain E0433`.
For more information about an error, try `rustc --explain E0433`.
Some expected error codes were not found: ["E0373"]
failures:
    /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index::E0373 (line 6089)

test result: FAILED. 960 passed; 1 failed; 21 ignored; 0 measured; 0 filtered out; finished in 8.41s


```compile_fail,E0373
use std::sync::Arc;
use tokio::runtime::Runtime; // 0.3.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need to use only std for these, external libraries won't work.

use tokio::runtime::Runtime; // 0.3.1

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: style-wise, these examples usually use more "bland" variable names to put the focus on the code structure. use(), x, y, foo, task or task_handle, etc.


This error may also be encountered while using `async` blocks:

```compile_fail,E0373,edition2018
Copy link
Member

@tmandry tmandry Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this test passes now! It can still be simplified though:

use std::future::Future;

async fn f() {
    let v = vec![1, 2, 3i32];
    spawn(async { //~ ERROR E0373
        println!("{:?}", v)
    });
}

fn spawn<F: Future + Send + 'static>(future: F) {
    unimplemented!()
}

Otherwise this change LGTM.

Copy link
Contributor Author

@sledgehammervampire sledgehammervampire Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the code snippet to yours in my latest commit.

@sledgehammervampire sledgehammervampire marked this pull request as ready for review January 15, 2021 06:46
…s.rs

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
@tmandry
Copy link
Member

tmandry commented Jan 16, 2021

Thanks @1000teslas!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 16, 2021

📌 Commit 3e9c95b has been approved by tmandry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jan 16, 2021
Explain why borrows can't be held across yield point in async blocks

For rust-lang#78938.
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 16, 2021
Explain why borrows can't be held across yield point in async blocks

For rust-lang#78938.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 16, 2021
Rollup of 17 pull requests

Successful merges:

 - rust-lang#78455 (Introduce {Ref, RefMut}::try_map for optional projections in RefCell)
 - rust-lang#80144 (Remove giant badge in README)
 - rust-lang#80614 (Explain why borrows can't be held across yield point in async blocks)
 - rust-lang#80670 (TrustedRandomAaccess specialization composes incorrectly for nested iter::Zips)
 - rust-lang#80681 (Clarify what the effects of a 'logic error' are)
 - rust-lang#80764 (Re-stabilize Weak::as_ptr and friends for unsized T)
 - rust-lang#80901 (Make `x.py --color always` apply to logging too)
 - rust-lang#80902 (Add a regression test for rust-lang#76281)
 - rust-lang#80941 (Do not suggest invalid code in pattern with loop)
 - rust-lang#80968 (Stabilize the poll_map feature)
 - rust-lang#80971 (Put all feature gate tests under `feature-gates/`)
 - rust-lang#81021 (Remove doctree::Import)
 - rust-lang#81040 (doctest: Reset errors before dropping the parse session)
 - rust-lang#81060 (Add a regression test for rust-lang#50041)
 - rust-lang#81065 (codegen_cranelift: Fix redundant semicolon warn)
 - rust-lang#81069 (Add sample code for Rc::new_cyclic)
 - rust-lang#81081 (Add test for rust-lang#34792)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit af5b0d9 into rust-lang:master Jan 16, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 16, 2021
@sledgehammervampire sledgehammervampire deleted the issue-78938-fix branch January 18, 2021 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants