Skip to content

Commit 69be798

Browse files
committed
coverage: Regression test for markers in a function with no spans
1 parent d69a329 commit 69be798

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Function name: no_spans_if_not::main
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 01, 02, 02]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 11, 1) to (start + 2, 2)
8+
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
LL| |// edition: 2021
2+
LL| |
3+
LL| |// If the span extractor can't find any relevant spans for a function,
4+
LL| |// but the function contains coverage span-marker statements (e.g. inserted
5+
LL| |// for `if !`, coverage codegen may think that it is instrumented and
6+
LL| |// consequently complain that it has no spans.
7+
LL| |//
8+
LL| |// Regression test for #118850,
9+
LL| |// "A used function should have had coverage mapping data but did not".
10+
LL| |
11+
LL| 1|fn main() {
12+
LL| 1| affected_function();
13+
LL| 1|}
14+
LL| |
15+
LL| |macro_rules! macro_that_defines_a_function {
16+
LL| | (fn $name:ident () $body:tt) => {
17+
LL| | fn $name () $body
18+
LL| | }
19+
LL| |}
20+
LL| |
21+
LL| |macro_that_defines_a_function! {
22+
LL| | fn affected_function() {
23+
LL| | if !false {
24+
LL| | ()
25+
LL| | } else {
26+
LL| | ()
27+
LL| | }
28+
LL| | }
29+
LL| |}
30+

tests/coverage/no_spans_if_not.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// edition: 2021
2+
3+
// If the span extractor can't find any relevant spans for a function,
4+
// but the function contains coverage span-marker statements (e.g. inserted
5+
// for `if !`, coverage codegen may think that it is instrumented and
6+
// consequently complain that it has no spans.
7+
//
8+
// Regression test for #118850,
9+
// "A used function should have had coverage mapping data but did not".
10+
11+
fn main() {
12+
affected_function();
13+
}
14+
15+
macro_rules! macro_that_defines_a_function {
16+
(fn $name:ident () $body:tt) => {
17+
fn $name () $body
18+
}
19+
}
20+
21+
macro_that_defines_a_function! {
22+
fn affected_function() {
23+
if !false {
24+
()
25+
} else {
26+
()
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)