-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[wg-async-await] Drop async fn arguments in async block
#59823
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8b57be1
Add test for drop order in async functions.
davidtwco 41c6bb1
Introduce `LocalSource` into the AST.
davidtwco 879abb1
Add `AsyncArgument` to AST.
davidtwco 7c6dc7a
Move `async fn` arguments into closure.
davidtwco 6134655
Enforce consistent drop order w/ async methods.
davidtwco 92e72df
Do not specify type in generated let bindings.
davidtwco 9d7da82
Introduce `ArgSource` for diagnostics.
davidtwco 44ddbc5
Correct lowering order to avoid ICE after rebase.
davidtwco 09c707f
Display original pattern in rustdoc.
davidtwco 119e67a
Reduce noise and document test case.
davidtwco File filter
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
Add test for drop order in async functions.
This tests that async functions drop parameters in the same order as regular functions.
- Loading branch information
commit 8b57be1bb3be3be5ac431ed9a0a310d2023b1c9d
There are no files selected for viewing
This file contains hidden or 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,89 @@ | ||
| // aux-build:arc_wake.rs | ||
| // edition:2018 | ||
| // run-pass | ||
|
|
||
| #![allow(unused_variables)] | ||
| #![feature(async_await, await_macro, futures_api)] | ||
|
|
||
| extern crate arc_wake; | ||
|
|
||
| use arc_wake::ArcWake; | ||
| use std::cell::RefCell; | ||
| use std::future::Future; | ||
| use std::sync::Arc; | ||
| use std::task::Context; | ||
|
|
||
| struct EmptyWaker; | ||
|
|
||
| impl ArcWake for EmptyWaker { | ||
| fn wake(self: Arc<Self>) {} | ||
| } | ||
|
|
||
| #[derive(Debug, Eq, PartialEq)] | ||
| enum DropOrder { | ||
| Function, | ||
| Val(&'static str), | ||
| } | ||
|
|
||
| struct D(&'static str, Arc<RefCell<Vec<DropOrder>>>); | ||
|
|
||
| impl Drop for D { | ||
| fn drop(&mut self) { | ||
| self.1.borrow_mut().push(DropOrder::Val(self.0)); | ||
| } | ||
| } | ||
|
|
||
| async fn foo(x: D, _y: D) { | ||
| x.1.borrow_mut().push(DropOrder::Function); | ||
| } | ||
|
|
||
| async fn bar(x: D, _: D) { | ||
| x.1.borrow_mut().push(DropOrder::Function); | ||
| } | ||
|
|
||
| async fn baz((x, _): (D, D)) { | ||
| x.1.borrow_mut().push(DropOrder::Function); | ||
| } | ||
|
|
||
| async fn foobar(x: D, (a, _, _c): (D, D, D), _: D, _y: D) { | ||
| x.1.borrow_mut().push(DropOrder::Function); | ||
| } | ||
|
|
||
| fn main() { | ||
| let empty = Arc::new(EmptyWaker); | ||
| let waker = ArcWake::into_waker(empty); | ||
| let mut cx = Context::from_waker(&waker); | ||
|
|
||
| use DropOrder::*; | ||
|
|
||
| // Currently, the `bar` and `foobar` tests do not output the same order as the equivalent | ||
| // non-async functions. This is because the drop order of captured variables doesn't match the | ||
| // drop order of arguments in a function. | ||
|
|
||
| let af = Arc::new(RefCell::new(Vec::new())); | ||
| let mut fut = Box::pin(foo(D("x", af.clone()), D("_y", af.clone()))); | ||
| let _ = fut.as_mut().poll(&mut cx); | ||
| assert_eq!(*af.borrow(), &[Function, Val("_y"), Val("x")]); | ||
|
|
||
| let af = Arc::new(RefCell::new(Vec::new())); | ||
davidtwco marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let mut fut = Box::pin(bar(D("x", af.clone()), D("_", af.clone()))); | ||
| let _ = fut.as_mut().poll(&mut cx); | ||
| assert_eq!(*af.borrow(), &[Function, Val("x"), Val("_")]); | ||
|
|
||
| let af = Arc::new(RefCell::new(Vec::new())); | ||
| let mut fut = Box::pin(baz((D("x", af.clone()), D("_", af.clone())))); | ||
| let _ = fut.as_mut().poll(&mut cx); | ||
| assert_eq!(*af.borrow(), &[Function, Val("x"), Val("_")]); | ||
|
|
||
| let af = Arc::new(RefCell::new(Vec::new())); | ||
| let mut fut = Box::pin(foobar( | ||
| D("x", af.clone()), | ||
| (D("a", af.clone()), D("_", af.clone()), D("_c", af.clone())), | ||
| D("_", af.clone()), | ||
| D("_y", af.clone()), | ||
| )); | ||
| let _ = fut.as_mut().poll(&mut cx); | ||
| assert_eq!(*af.borrow(), &[ | ||
| Function, Val("_y"), Val("_c"), Val("a"), Val("x"), Val("_"), Val("_"), | ||
| ]); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.