Skip to content

Commit 1766d1b

Browse files
committed
Auto merge of #896 - tmandry:add-generator-uninhabited-test, r=RalfJung
Add generator, async tests with uninhabited saved local See discussion in rust-lang/rust#63035.
2 parents ecd3c9c + f544721 commit 1766d1b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/run-pass/async-fn.rs

+36
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ pub async fn foo(x: &u32, y: u32) -> u32 {
1414
*x + y + *a
1515
}
1616

17+
async fn add(x: u32, y: u32) -> u32 {
18+
async { x + y }.await
19+
}
20+
21+
async fn build_aggregate(a: u32, b: u32, c: u32, d: u32) -> u32 {
22+
let x = (add(a, b).await, add(c, d).await);
23+
x.0 + x.1
24+
}
25+
26+
enum Never {}
27+
fn never() -> Never {
28+
panic!()
29+
}
30+
31+
async fn includes_never(crash: bool, x: u32) -> u32 {
32+
let mut result = async { x * x }.await;
33+
if !crash {
34+
return result;
35+
}
36+
#[allow(unused)]
37+
let bad = never();
38+
result *= async { x + x }.await;
39+
drop(bad);
40+
result
41+
}
42+
1743
fn raw_waker_clone(_this: *const ()) -> RawWaker {
1844
panic!("unimplemented");
1945
}
@@ -38,4 +64,14 @@ fn main() {
3864
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
3965
let mut context = Context::from_waker(&waker);
4066
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(31));
67+
68+
let mut fut = build_aggregate(1, 2, 3, 4);
69+
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
70+
let mut context = Context::from_waker(&waker);
71+
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(10));
72+
73+
let mut fut = includes_never(false, 4);
74+
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
75+
let mut context = Context::from_waker(&waker);
76+
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(16));
4177
}

tests/run-pass/generator.rs

+13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ fn finish<T>(mut amt: usize, mut t: T) -> T::Return
1717
}
1818
}
1919
}
20+
}
2021

22+
enum Never {}
23+
fn never() -> Never {
24+
panic!()
2125
}
2226

2327
fn main() {
@@ -67,4 +71,13 @@ fn main() {
6771
}),
6872
10
6973
);
74+
let b = true;
75+
finish(1, || {
76+
yield 1;
77+
if b { return; }
78+
#[allow(unused)]
79+
let x = never();
80+
yield 2;
81+
drop(x);
82+
});
7083
}

0 commit comments

Comments
 (0)