72 lines
2.2 KiB
Plaintext
72 lines
2.2 KiB
Plaintext
LL| |#![feature(coverage_attribute, let_chains)]
|
|
LL| |//@ edition: 2021
|
|
LL| |//@ compile-flags: -Zcoverage-options=branch
|
|
LL| |//@ llvm-cov-flags: --show-branches=count
|
|
LL| |
|
|
LL| |macro_rules! no_merge {
|
|
LL| | () => {
|
|
LL| | for _ in 0..1 {}
|
|
LL| | };
|
|
LL| |}
|
|
LL| |
|
|
LL| 3|fn if_let(input: Option<&str>) {
|
|
LL| 3| no_merge!();
|
|
LL| |
|
|
LL| 3| if let Some(x) = input {
|
|
^2
|
|
------------------
|
|
| Branch (LL:12): [True: 2, False: 1]
|
|
------------------
|
|
LL| 2| say(x);
|
|
LL| 2| } else {
|
|
LL| 1| say("none");
|
|
LL| 1| }
|
|
LL| 3| say("done");
|
|
LL| 3|}
|
|
LL| |
|
|
LL| 15|fn if_let_chain(a: Option<&str>, b: Option<&str>) {
|
|
LL| 15| if let Some(x) = a
|
|
^12
|
|
------------------
|
|
| Branch (LL:12): [True: 12, False: 3]
|
|
------------------
|
|
LL| 12| && let Some(y) = b
|
|
^8
|
|
------------------
|
|
| Branch (LL:16): [True: 8, False: 4]
|
|
------------------
|
|
LL| 8| {
|
|
LL| 8| say(x);
|
|
LL| 8| say(y);
|
|
LL| 8| } else {
|
|
LL| 7| say("not both");
|
|
LL| 7| }
|
|
LL| 15| say("done");
|
|
LL| 15|}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn say(message: &str) {
|
|
LL| | core::hint::black_box(message);
|
|
LL| |}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn main() {
|
|
LL| | if_let(Some("x"));
|
|
LL| | if_let(Some("x"));
|
|
LL| | if_let(None);
|
|
LL| |
|
|
LL| | for _ in 0..8 {
|
|
LL| | if_let_chain(Some("a"), Some("b"));
|
|
LL| | }
|
|
LL| | for _ in 0..4 {
|
|
LL| | if_let_chain(Some("a"), None);
|
|
LL| | }
|
|
LL| | for _ in 0..2 {
|
|
LL| | if_let_chain(None, Some("b"));
|
|
LL| | }
|
|
LL| | if_let_chain(None, None);
|
|
LL| |}
|
|
LL| |
|
|
LL| |// FIXME(#124118) Actually instrument if-let and let-chains for branch coverage.
|
|
|