1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
LL| |#![feature(coverage_attribute)]
LL| |#![feature(custom_inner_attributes)] // for #![rustfmt::skip]
LL| |#![allow(unused_assignments, dead_code)]
LL| |#![rustfmt::skip]
LL| |//@ edition: 2018
LL| |//@ compile-flags: -Copt-level=1
LL| |
LL| |//@ aux-build: executor.rs
LL| |extern crate executor;
LL| |
LL| 1|async fn c(x: u8) -> u8 {
LL| 1| if x == 8 {
LL| 1| 1
LL| | } else {
LL| 0| 0
LL| | }
LL| 1|}
LL| |
LL| 0|async fn d() -> u8 { 1 }
LL| |
LL| 0|async fn e() -> u8 { 1 } // unused function; executor does not block on `g()`
LL| |
LL| 1|async fn f() -> u8 { 1 }
LL| |
LL| 0|async fn foo() -> [bool; 10] { [false; 10] } // unused function; executor does not block on `h()`
LL| |
LL| 1|pub async fn g(x: u8) {
LL| 0| match x {
LL| 0| y if e().await == y => (),
LL| 0| y if f().await == y => (),
LL| 0| _ => (),
LL| | }
LL| 0|}
LL| |
LL| 1|async fn h(x: usize) { // The function signature is counted when called, but the body is not
LL| 0| // executed (not awaited) so the open brace has a `0` count (at least when
LL| 0| // displayed with `llvm-cov show` in color-mode).
LL| 0| match x {
LL| 0| y if foo().await[y] => (),
LL| 0| _ => (),
LL| | }
LL| 0|}
LL| |
LL| 1|async fn i(x: u8) { // line coverage is 1, but there are 2 regions:
LL| 1| // (a) the function signature, counted when the function is called; and
LL| 1| // (b) the open brace for the function body, counted once when the body is
LL| 1| // executed asynchronously.
LL| 1| match x {
LL| 1| y if c(x).await == y + 1 => { d().await; }
^0 ^0
LL| 1| y if f().await == y + 1 => (),
^0 ^0
LL| 1| _ => (),
LL| | }
LL| 1|}
LL| |
LL| 1|fn j(x: u8) {
LL| | // non-async versions of `c()`, `d()`, and `f()` to make it similar to async `i()`.
LL| 1| fn c(x: u8) -> u8 {
LL| 1| if x == 8 {
LL| 0| 1
LL| | } else {
LL| 1| 0
LL| | }
LL| 1| }
LL| 0| fn d() -> u8 { 1 } // inner function is defined in-line, but the function is not executed
LL| 1| fn f() -> u8 { 1 }
LL| 1| match x {
LL| 1| y if c(x) == y + 1 => { d(); }
^0 ^0
LL| 1| y if f() == y + 1 => (),
^0 ^0
LL| 1| _ => (),
LL| | }
LL| 1|}
LL| |
LL| 0|fn k(x: u8) { // unused function
LL| 0| match x {
LL| 0| 1 => (),
LL| 0| 2 => (),
LL| 0| _ => (),
LL| | }
LL| 0|}
LL| |
LL| 1|fn l(x: u8) {
LL| 1| match x {
LL| 0| 1 => (),
LL| 0| 2 => (),
LL| 1| _ => (),
LL| | }
LL| 1|}
LL| |
LL| 1|async fn m(x: u8) -> u8 { x - 1 }
^0
LL| |
LL| 1|fn main() {
LL| 1| let _ = g(10);
LL| 1| let _ = h(9);
LL| 1| let mut future = Box::pin(i(8));
LL| 1| j(7);
LL| 1| l(6);
LL| 1| let _ = m(5);
LL| 1| executor::block_on(future.as_mut());
LL| 1|}
|