fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1 LL| |// compile-flags: --edition=2018 2 LL| |#![feature(coverage_attribute)] 3 LL| | 4 LL| |macro_rules! bail { 5 LL| | ($msg:literal $(,)?) => { 6 LL| | if $msg.len() > 0 { 7 LL| | println!("no msg"); 8 LL| | } else { 9 LL| | println!($msg); 10 LL| | } 11 LL| | return Err(String::from($msg)); 12 LL| | }; 13 LL| |} 14 LL| | 15 LL| |macro_rules! on_error { 16 LL| | ($value:expr, $error_message:expr) => { 17 LL| | $value.or_else(|e| { // FIXME(85000): no coverage in closure macros 18 LL| | let message = format!($error_message, e); 19 LL| | if message.len() > 0 { 20 LL| | println!("{}", message); 21 LL| | Ok(String::from("ok")) 22 LL| | } else { 23 LL| | bail!("error"); 24 LL| | } 25 LL| | }) 26 LL| | }; 27 LL| |} 28 LL| | 29 LL| 1|fn load_configuration_files() -> Result<String, String> { 30 LL| 1| Ok(String::from("config")) 31 LL| 1|} 32 LL| | 33 LL| 1|pub async fn test() -> Result<(), String> { 34 LL| 1| println!("Starting service"); 35 LL| 1| let config = on_error!(load_configuration_files(), "Error loading configs: {}")?; 36 ^0 37 LL| | 38 LL| 1| let startup_delay_duration = String::from("arg"); 39 LL| 1| let _ = (config, startup_delay_duration); 40 LL| 1| Ok(()) 41 LL| 1|} 42 LL| | 43 LL| |#[coverage(off)] 44 LL| |fn main() { 45 LL| | executor::block_on(test()).unwrap(); 46 LL| |} 47 LL| | 48 LL| |mod executor { 49 LL| | use core::{ 50 LL| | future::Future, 51 LL| | pin::Pin, 52 LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, 53 LL| | }; 54 LL| | 55 LL| | #[coverage(off)] 56 LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output { 57 LL| | let mut future = unsafe { Pin::new_unchecked(&mut future) }; 58 LL| | use std::hint::unreachable_unchecked; 59 LL| | static VTABLE: RawWakerVTable = RawWakerVTable::new( 60 LL| | #[coverage(off)] 61 LL| | |_| unsafe { unreachable_unchecked() }, // clone 62 LL| | #[coverage(off)] 63 LL| | |_| unsafe { unreachable_unchecked() }, // wake 64 LL| | #[coverage(off)] 65 LL| | |_| unsafe { unreachable_unchecked() }, // wake_by_ref 66 LL| | #[coverage(off)] 67 LL| | |_| (), 68 LL| | ); 69 LL| | let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; 70 LL| | let mut context = Context::from_waker(&waker); 71 LL| | 72 LL| | loop { 73 LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) { 74 LL| | break val; 75 LL| | } 76 LL| | } 77 LL| | } 78 LL| |} 79