Skip to content

Commit 19b5a10

Browse files
authored
Rollup merge of #61138 - varkor:async-await-tests, r=cramertj
Move async/await tests to their own folder This moves run-pass and ui async/await tests to their own folder `src/test/ui/async-await` and organises some into subfolders. (It does not move rustdoc tests for async/await.) I also did some drive-by cleaning up of issues/error code tests into their own folders (which already existed). These are in separate commits, so easy to separate out if that's more desirable. r? @cramertj
2 parents 92f1cfd + c91ab64 commit 19b5a10

File tree

112 files changed

+74
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+74
-2
lines changed

src/test/run-pass/async-await.rs src/test/ui/async-await/async-await.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-pass
2+
13
// edition:2018
24
// aux-build:arc_wake.rs
35

src/test/run-pass/await-macro.rs src/test/ui/async-await/await-macro.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-pass
2+
13
// edition:2018
24
// aux-build:arc_wake.rs
35

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// edition:2018
2+
3+
use std::sync::Arc;
4+
use std::task::{
5+
Waker, RawWaker, RawWakerVTable,
6+
};
7+
8+
macro_rules! waker_vtable {
9+
($ty:ident) => {
10+
&RawWakerVTable::new(
11+
clone_arc_raw::<$ty>,
12+
wake_arc_raw::<$ty>,
13+
wake_by_ref_arc_raw::<$ty>,
14+
drop_arc_raw::<$ty>,
15+
)
16+
};
17+
}
18+
19+
pub trait ArcWake {
20+
fn wake(self: Arc<Self>);
21+
22+
fn wake_by_ref(arc_self: &Arc<Self>) {
23+
arc_self.clone().wake()
24+
}
25+
26+
fn into_waker(wake: Arc<Self>) -> Waker where Self: Sized
27+
{
28+
let ptr = Arc::into_raw(wake) as *const ();
29+
30+
unsafe {
31+
Waker::from_raw(RawWaker::new(ptr, waker_vtable!(Self)))
32+
}
33+
}
34+
}
35+
36+
unsafe fn increase_refcount<T: ArcWake>(data: *const ()) {
37+
// Retain Arc by creating a copy
38+
let arc: Arc<T> = Arc::from_raw(data as *const T);
39+
let arc_clone = arc.clone();
40+
// Forget the Arcs again, so that the refcount isn't decrased
41+
let _ = Arc::into_raw(arc);
42+
let _ = Arc::into_raw(arc_clone);
43+
}
44+
45+
unsafe fn clone_arc_raw<T: ArcWake>(data: *const ()) -> RawWaker {
46+
increase_refcount::<T>(data);
47+
RawWaker::new(data, waker_vtable!(T))
48+
}
49+
50+
unsafe fn drop_arc_raw<T: ArcWake>(data: *const ()) {
51+
// Drop Arc
52+
let _: Arc<T> = Arc::from_raw(data as *const T);
53+
}
54+
55+
unsafe fn wake_arc_raw<T: ArcWake>(data: *const ()) {
56+
let arc: Arc<T> = Arc::from_raw(data as *const T);
57+
ArcWake::wake(arc);
58+
}
59+
60+
unsafe fn wake_by_ref_arc_raw<T: ArcWake>(data: *const ()) {
61+
let arc: Arc<T> = Arc::from_raw(data as *const T);
62+
ArcWake::wake_by_ref(&arc);
63+
let _ = Arc::into_raw(arc);
64+
}
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#![feature(async_await)]
2-
#![allow(unused_parens)]
1+
// run-pass
32

43
// edition:2018
54
// pp-exact
65

6+
#![feature(async_await)]
7+
#![allow(unused_parens)]
8+
79
fn main() { let _a = (async { }); }
File renamed without changes.

src/test/run-pass/generator/issue-59972.rs src/test/ui/async-await/issues/issue-59972.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-pass
2+
13
// compile-flags: --edition=2018
24

35
#![feature(async_await, await_macro)]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)