-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
Automatic Rustup
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
b17491c8f6d555386104dfd82004c01bfef09c95 | ||
d26b41711282042c4ea0c5733e7332b07cfa4933 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![feature(async_closure, noop_waker, async_fn_traits)] | ||
Check failure on line 1 in tests/pass/async-closure.rs GitHub Actions / build (ubuntu-latest, x86_64-unknown-linux-gnu)pass test got exit status: 1
Check failure on line 1 in tests/pass/async-closure.rs GitHub Actions / build (ubuntu-latest, x86_64-unknown-linux-gnu)test generated output
Check failure on line 1 in tests/pass/async-closure.rs GitHub Actions / build (macos-latest, x86_64-apple-darwin)pass test got exit status: 1
Check failure on line 1 in tests/pass/async-closure.rs GitHub Actions / build (macos-latest, x86_64-apple-darwin)test generated output
Check failure on line 1 in tests/pass/async-closure.rs GitHub Actions / build (windows-latest, i686-pc-windows-msvc)pass test got exit code: 1
|
||
|
||
use std::future::Future; | ||
use std::pin::pin; | ||
use std::task::*; | ||
|
||
pub fn block_on<T>(fut: impl Future<Output = T>) -> T { | ||
let mut fut = pin!(fut); | ||
let ctx = &mut Context::from_waker(Waker::noop()); | ||
|
||
loop { | ||
match fut.as_mut().poll(ctx) { | ||
Poll::Pending => {} | ||
Poll::Ready(t) => break t, | ||
} | ||
} | ||
} | ||
|
||
async fn call_once(f: impl FnOnce(DropMe)) { | ||
f(DropMe("world")).await; | ||
Check failure on line 20 in tests/pass/async-closure.rs GitHub Actions / build (ubuntu-latest, x86_64-unknown-linux-gnu)Unmatched diagnostics
Check failure on line 20 in tests/pass/async-closure.rs GitHub Actions / build (macos-latest, x86_64-apple-darwin)Unmatched diagnostics
|
||
} | ||
|
||
#[derive(Debug)] | ||
struct DropMe(&'static str); | ||
|
||
impl Drop for DropMe { | ||
fn drop(&mut self) { | ||
println!("{}", self.0); | ||
} | ||
} | ||
|
||
pub fn main() { | ||
block_on(async { | ||
let b = DropMe("hello"); | ||
let async_closure = async move |a: DropMe| { | ||
println!("{a:?} {b:?}"); | ||
}; | ||
call_once(async_closure).await; | ||
Check failure on line 38 in tests/pass/async-closure.rs GitHub Actions / build (ubuntu-latest, x86_64-unknown-linux-gnu)Unmatched diagnostics
Check failure on line 38 in tests/pass/async-closure.rs GitHub Actions / build (macos-latest, x86_64-apple-darwin)Unmatched diagnostics
Check failure on line 38 in tests/pass/async-closure.rs GitHub Actions / build (windows-latest, i686-pc-windows-msvc)Unmatched diagnostics
|
||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DropMe("world") DropMe("hello") | ||
world | ||
Check failure on line 2 in tests/pass/async-closure.stdout GitHub Actions / build (ubuntu-latest, x86_64-unknown-linux-gnu)extraneous lines in output
Check failure on line 2 in tests/pass/async-closure.stdout GitHub Actions / build (macos-latest, x86_64-apple-darwin)extraneous lines in output
|
||
hello |