forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#127827 - compiler-errors:async-closure-closur…
…e-async, r=<try> [EXPERIMENT] Rewrite closure-of-async to async-closure to see what the fallout is, to gauge how forwards-compatible `async || {}` is w/ `|| async {}`. uwuwuwu
- Loading branch information
Showing
14 changed files
with
175 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//@ aux-build:block-on.rs | ||
//@ edition:2021 | ||
//@ run-pass | ||
//@ check-run-results | ||
|
||
#![feature(async_closure)] | ||
|
||
extern crate block_on; | ||
|
||
async fn for_each(f: impl async FnOnce(&str) + Clone) { | ||
f.clone()("world").await; | ||
f.clone()("world2").await; | ||
} | ||
|
||
fn main() { | ||
block_on::block_on(async_main()); | ||
} | ||
|
||
async fn async_main() { | ||
let x = String::from("Hello,"); | ||
for_each(async move |s| { | ||
println!("{x} {s}"); | ||
}).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello, world | ||
Hello, world2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
error: captured variable cannot escape `FnMut` closure body | ||
--> $DIR/issue-69446-fnmut-capture.rs:19:17 | ||
error: async closure does not implement `FnMut` because it captures state from its environment | ||
--> $DIR/issue-69446-fnmut-capture.rs:19:9 | ||
| | ||
LL | let mut x = Foo; | ||
| ----- variable defined here | ||
LL | bar(move || async { | ||
| _______________-_^ | ||
| | | | ||
| | inferred to be a `FnMut` closure | ||
LL | | x.foo(); | ||
| | - variable captured here | ||
LL | | }); | ||
| |_____^ returns an `async` block that contains a reference to a captured variable, which then escapes the closure body | ||
LL | bar(move || async { | ||
| --- ^^^^^^^ | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: `FnMut` closures only have access to their captured variables while they are executing... | ||
= note: ...therefore, they cannot allow references to captured variables to escape | ||
note: required by a bound in `bar` | ||
--> $DIR/issue-69446-fnmut-capture.rs:12:25 | ||
| | ||
LL | async fn bar<T>(_: impl FnMut() -> T) | ||
| ^^^^^^^^^^^^ required by this bound in `bar` | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters