1 1| |#![allow(unused_assignments, dead_code)]
3 3| |// compile-flags: --edition=2018 -C opt-level=1
5 5| 1|async fn c(x: u8) -> u8 {
13 13| 0|async fn d() -> u8 { 1 }
15 15| 0|async fn e() -> u8 { 1 } // unused function; executor does not block on `g()`
17 17| 1|async fn f() -> u8 { 1 }
19 19| 0|async fn foo() -> [bool; 10] { [false; 10] } // unused function; executor does not block on `h()`
21 21| 1|pub async fn g(x: u8) {
23 23| 0| y if e().await == y => (),
24 24| 0| y if f().await == y => (),
29 29| 1|async fn h(x: usize) { // The function signature is counted when called, but the body is not
30 30| 0| // executed (not awaited) so the open brace has a `0` count (at least when
31 31| 0| // displayed with `llvm-cov show` in color-mode).
33 33| 0| y if foo().await[y] => (),
38 38| 1|async fn i(x: u8) { // line coverage is 1, but there are 2 regions:
39 39| 1| // (a) the function signature, counted when the function is called; and
40 40| 1| // (b) the open brace for the function body, counted once when the body is
41 41| 1| // executed asynchronously.
43 43| 1| y if c(x).await == y + 1 => { d().await; }
45 44| 1| y if f().await == y + 1 => (),
52 50| 1| // non-async versions of `c()`, `d()`, and `f()` to make it similar to async `i()`.
53 51| 1| fn c(x: u8) -> u8 {
55 53| 1| 1 // This line appears covered, but the 1-character expression span covering the `1`
57 54| 1| // is not executed. (`llvm-cov show` displays a `^0` below the `1` ). This is because
58 55| 1| // `fn j()` executes the open brace for the function body, followed by the function's
59 56| 1| // first executable statement, `match x`. Inner function declarations are not
60 57| 1| // "visible" to the MIR for `j()`, so the code region counts all lines between the
61 58| 1| // open brace and the first statement as executed, which is, in a sense, true.
62 59| 1| // `llvm-cov show` overcomes this kind of situation by showing the actual counts
63 60| 1| // of the enclosed coverages, (that is, the `1` expression was not executed, and
64 61| 1| // accurately displays a `0`).
69 66| 1| fn d() -> u8 { 1 } // inner function is defined in-line, but the function is not executed
71 67| 1| fn f() -> u8 { 1 }
73 69| 1| y if c(x) == y + 1 => { d(); }
75 70| 1| y if f() == y + 1 => (),
81 75| 0|fn k(x: u8) { // unused function
97 91| 1|async fn m(x: u8) -> u8 { x - 1 }
101 94| 1| let _ = g(10);
103 96| 1| let mut future = Box::pin(i(8));
107 100| 1| executor::block_on(future.as_mut());
112 105| | future::Future,
114 107| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
117 110| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
118 111| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
119 112| 1| use std::hint::unreachable_unchecked;
120 113| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
121 114| 1| |_| unsafe { unreachable_unchecked() }, // clone
123 115| 1| |_| unsafe { unreachable_unchecked() }, // wake
125 116| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
129 119| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
130 120| 1| let mut context = Context::from_waker(&waker);
133 123| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {