]> git.lizzy.rs Git - rust.git/commitdiff
Add generator, async tests with uninhabited saved local
authorTyler Mandry <tmandry@gmail.com>
Wed, 7 Aug 2019 23:39:54 +0000 (16:39 -0700)
committerTyler Mandry <tmandry@gmail.com>
Wed, 7 Aug 2019 23:56:35 +0000 (16:56 -0700)
tests/run-pass/async-fn.rs
tests/run-pass/generator.rs

index 5c916473b580493b2040dc408b84881d2a2b699b..25b9b9ac5ba4b0642f8f0a9c4a1e7ca68aa50cc8 100644 (file)
@@ -14,6 +14,32 @@ pub async fn foo(x: &u32, y: u32) -> u32 {
     *x + y + *a
 }
 
+async fn add(x: u32, y: u32) -> u32 {
+    async { x + y }.await
+}
+
+async fn build_aggregate(a: u32, b: u32, c: u32, d: u32) -> u32 {
+    let x = (add(a, b).await, add(c, d).await);
+    x.0 + x.1
+}
+
+enum Never {}
+fn never() -> Never {
+    panic!()
+}
+
+async fn includes_never(crash: bool, x: u32) -> u32 {
+    let mut result = async { x * x }.await;
+    if !crash {
+        return result;
+    }
+    #[allow(unused)]
+    let bad = never();
+    result *= async { x + x }.await;
+    drop(bad);
+    result
+}
+
 fn raw_waker_clone(_this: *const ()) -> RawWaker {
     panic!("unimplemented");
 }
@@ -38,4 +64,14 @@ fn main() {
     let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
     let mut context = Context::from_waker(&waker);
     assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(31));
+
+    let mut fut = build_aggregate(1, 2, 3, 4);
+    let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
+    let mut context = Context::from_waker(&waker);
+    assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(10));
+
+    let mut fut = includes_never(false, 4);
+    let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
+    let mut context = Context::from_waker(&waker);
+    assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(16));
 }
index 477f548a7b0658ed942ef68809ee1703a9109f92..5064d8daf0f3c793bf73bb45ddfe2845a5759c45 100644 (file)
@@ -17,7 +17,11 @@ fn finish<T>(mut amt: usize, mut t: T) -> T::Return
             }
         }
     }
+}
 
+enum Never {}
+fn never() -> Never {
+    panic!()
 }
 
 fn main() {
@@ -67,4 +71,13 @@ fn main() {
         }),
         10
     );
+    let b = true;
+    finish(1, || {
+        yield 1;
+        if b { return; }
+        #[allow(unused)]
+        let x = never();
+        yield 2;
+        drop(x);
+    });
 }