]> git.proxmox.com Git - rustc.git/blame - src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.async.txt
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / run-make-fulldeps / coverage-reports / expected_show_coverage.async.txt
CommitLineData
fc512014
XL
1 1| |#![allow(unused_assignments, dead_code)]
2 2| |
6a06907d 3 3| |// compile-flags: --edition=2018
fc512014
XL
4 4| |
5 5| 1|async fn c(x: u8) -> u8 {
6 6| 1| if x == 8 {
7 7| 1| 1
8 8| | } else {
9 9| 0| 0
10 10| | }
11 11| 1|}
12 12| |
13 13| 0|async fn d() -> u8 { 1 }
14 14| |
15 15| 0|async fn e() -> u8 { 1 } // unused function; executor does not block on `g()`
16 16| |
17 17| 1|async fn f() -> u8 { 1 }
18 18| |
19 19| 0|async fn foo() -> [bool; 10] { [false; 10] } // unused function; executor does not block on `h()`
20 20| |
21 21| 1|pub async fn g(x: u8) {
22 22| 0| match x {
23 23| 0| y if e().await == y => (),
24 24| 0| y if f().await == y => (),
25 25| 0| _ => (),
26 26| | }
27 27| 0|}
28 28| |
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).
32 32| 0| match x {
33 33| 0| y if foo().await[y] => (),
34 34| 0| _ => (),
35 35| | }
36 36| 0|}
37 37| |
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.
42 42| 1| match x {
43 43| 1| y if c(x).await == y + 1 => { d().await; }
44 ^0 ^0
45 44| 1| y if f().await == y + 1 => (),
46 ^0 ^0
47 45| 1| _ => (),
48 46| | }
49 47| 1|}
50 48| |
51 49| 1|fn j(x: u8) {
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 {
54 52| 1| if x == 8 {
55 53| 1| 1 // This line appears covered, but the 1-character expression span covering the `1`
56 ^0
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 funciton 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`).
65 62| 1| } else {
66 63| 1| 0
67 64| 1| }
68 65| 1| }
69 66| 1| fn d() -> u8 { 1 }
70 67| 1| fn f() -> u8 { 1 }
71 68| 1| match x {
72 69| 1| y if c(x) == y + 1 => { d(); }
73 ^0 ^0
74 70| 1| y if f() == y + 1 => (),
75 ^0 ^0
76 71| 1| _ => (),
77 72| | }
78 73| 1|}
79 74| |
80 75| 0|fn k(x: u8) { // unused function
81 76| 0| match x {
82 77| 0| 1 => (),
83 78| 0| 2 => (),
84 79| 0| _ => (),
85 80| | }
86 81| 0|}
87 82| |
88 83| 1|fn l(x: u8) {
89 84| 1| match x {
90 85| 0| 1 => (),
91 86| 0| 2 => (),
92 87| 1| _ => (),
93 88| | }
94 89| 1|}
95 90| |
96 91| 1|async fn m(x: u8) -> u8 { x - 1 }
97 ^0
98 92| |
99 93| 1|fn main() {
100 94| 1| let _ = g(10);
101 95| 1| let _ = h(9);
102 96| 1| let mut future = Box::pin(i(8));
103 97| 1| j(7);
104 98| 1| l(6);
105 99| 1| let _ = m(5);
106 100| 1| executor::block_on(future.as_mut());
107 101| 1|}
108 102| |
109 103| |mod executor {
110 104| | use core::{
111 105| | future::Future,
112 106| | pin::Pin,
113 107| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
114 108| | };
115 109| |
116 110| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
117 111| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
118 112| 1|
119 113| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
120 114| 1| |_| unimplemented!("clone"),
121 115| 1| |_| unimplemented!("wake"),
122 116| 1| |_| unimplemented!("wake_by_ref"),
123 117| 1| |_| (),
124 118| 1| );
125 119| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
126 120| 1| let mut context = Context::from_waker(&waker);
127 121| |
128 122| | loop {
129 123| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
130 124| 1| break val;
131 125| 0| }
132 126| | }
133 127| 1| }
134 128| |}
135