fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1 LL| |// compile-flags: --edition=2018 2 LL| | 3 LL| 1|fn non_async_func() { 4 LL| 1| println!("non_async_func was covered"); 5 LL| 1| let b = true; 6 LL| 1| if b { 7 LL| 1| println!("non_async_func println in block"); 8 LL| 1| } 9 ^0 10 LL| 1|} 11 LL| | 12 LL| 1|async fn async_func() { 13 LL| 1| println!("async_func was covered"); 14 LL| 1| let b = true; 15 LL| 1| if b { 16 LL| 1| println!("async_func println in block"); 17 LL| 1| } 18 ^0 19 LL| 1|} 20 LL| | 21 LL| 1|async fn async_func_just_println() { 22 LL| 1| println!("async_func_just_println was covered"); 23 LL| 1|} 24 LL| | 25 LL| 1|fn main() { 26 LL| 1| println!("codecovsample::main"); 27 LL| 1| 28 LL| 1| non_async_func(); 29 LL| 1| 30 LL| 1| executor::block_on(async_func()); 31 LL| 1| executor::block_on(async_func_just_println()); 32 LL| 1|} 33 LL| | 34 LL| |mod executor { 35 LL| | use core::{ 36 LL| | future::Future, 37 LL| | pin::Pin, 38 LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, 39 LL| | }; 40 LL| | 41 LL| 2| pub fn block_on<F: Future>(mut future: F) -> F::Output { 42 LL| 2| let mut future = unsafe { Pin::new_unchecked(&mut future) }; 43 LL| 2| use std::hint::unreachable_unchecked; 44 LL| 2| static VTABLE: RawWakerVTable = RawWakerVTable::new( 45 LL| 2| |_| unsafe { unreachable_unchecked() }, // clone 46 ^0 47 LL| 2| |_| unsafe { unreachable_unchecked() }, // wake 48 ^0 49 LL| 2| |_| unsafe { unreachable_unchecked() }, // wake_by_ref 50 ^0 51 LL| 2| |_| (), 52 LL| 2| ); 53 LL| 2| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; 54 LL| 2| let mut context = Context::from_waker(&waker); 55 LL| | 56 LL| | loop { 57 LL| 2| if let Poll::Ready(val) = future.as_mut().poll(&mut context) { 58 LL| 2| break val; 59 LL| 0| } 60 LL| | } 61 LL| 2| } 62 ------------------ 63 | async2::executor::block_on::<async2::async_func::{closure#0}>: 64 | LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output { 65 | LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) }; 66 | LL| 1| use std::hint::unreachable_unchecked; 67 | LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new( 68 | LL| 1| |_| unsafe { unreachable_unchecked() }, // clone 69 | LL| 1| |_| unsafe { unreachable_unchecked() }, // wake 70 | LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref 71 | LL| 1| |_| (), 72 | LL| 1| ); 73 | LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; 74 | LL| 1| let mut context = Context::from_waker(&waker); 75 | LL| | 76 | LL| | loop { 77 | LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) { 78 | LL| 1| break val; 79 | LL| 0| } 80 | LL| | } 81 | LL| 1| } 82 ------------------ 83 | async2::executor::block_on::<async2::async_func_just_println::{closure#0}>: 84 | LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output { 85 | LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) }; 86 | LL| 1| use std::hint::unreachable_unchecked; 87 | LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new( 88 | LL| 1| |_| unsafe { unreachable_unchecked() }, // clone 89 | LL| 1| |_| unsafe { unreachable_unchecked() }, // wake 90 | LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref 91 | LL| 1| |_| (), 92 | LL| 1| ); 93 | LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; 94 | LL| 1| let mut context = Context::from_waker(&waker); 95 | LL| | 96 | LL| | loop { 97 | LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) { 98 | LL| 1| break val; 99 | LL| 0| } 100 | LL| | } 101 | LL| 1| } 102 ------------------ 103 LL| |} 104