Skip to content

Commit e01338a

Browse files
committed
coverage: Regression test for unwrapping prev when there are no spans
1 parent cec8142 commit e01338a

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

tests/coverage/no_spans.cov-map

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Function name: no_spans::affected_function::{closure#0}
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1b, 0c, 00, 0e]
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 + 27, 12) to (start + 0, 14)
8+

tests/coverage/no_spans.coverage

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |// edition: 2021
3+
LL| |
4+
LL| |// If the span extractor can't find any relevant spans for a function, the
5+
LL| |// refinement loop will terminate with nothing in its `prev` slot. If the
6+
LL| |// subsequent code tries to unwrap `prev`, it will panic.
7+
LL| |//
8+
LL| |// This scenario became more likely after #118525 started discarding spans that
9+
LL| |// can't be un-expanded back to within the function body.
10+
LL| |//
11+
LL| |// Regression test for "invalid attempt to unwrap a None some_prev", as seen
12+
LL| |// in issues such as #118643 and #118662.
13+
LL| |
14+
LL| |#[coverage(off)]
15+
LL| |fn main() {
16+
LL| | affected_function()();
17+
LL| |}
18+
LL| |
19+
LL| |macro_rules! macro_that_defines_a_function {
20+
LL| | (fn $name:ident () $body:tt) => {
21+
LL| | fn $name () -> impl Fn() $body
22+
LL| | }
23+
LL| |}
24+
LL| |
25+
LL| |macro_that_defines_a_function! {
26+
LL| | fn affected_function() {
27+
LL| 1| || ()
28+
LL| | }
29+
LL| |}
30+

tests/coverage/no_spans.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(coverage_attribute)]
2+
// edition: 2021
3+
4+
// If the span extractor can't find any relevant spans for a function, the
5+
// refinement loop will terminate with nothing in its `prev` slot. If the
6+
// subsequent code tries to unwrap `prev`, it will panic.
7+
//
8+
// This scenario became more likely after #118525 started discarding spans that
9+
// can't be un-expanded back to within the function body.
10+
//
11+
// Regression test for "invalid attempt to unwrap a None some_prev", as seen
12+
// in issues such as #118643 and #118662.
13+
14+
#[coverage(off)]
15+
fn main() {
16+
affected_function()();
17+
}
18+
19+
macro_rules! macro_that_defines_a_function {
20+
(fn $name:ident () $body:tt) => {
21+
fn $name () -> impl Fn() $body
22+
}
23+
}
24+
25+
macro_that_defines_a_function! {
26+
fn affected_function() {
27+
|| ()
28+
}
29+
}

0 commit comments

Comments
 (0)