Skip to content

Commit 514e324

Browse files
committed
coverage: Regression test for #117788
Without the workaround applied, this test will produce malformed mappings that cause `llvm-cov` to fail. (And if it does emit well-formed mappings, they should be obviously incorrect.)
1 parent ed8298b commit 514e324

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// edition: 2021
2+
3+
#[macro_export]
4+
macro_rules! macro_that_defines_a_function {
5+
(fn $name:ident () $body:tt) => {
6+
fn $name () -> () $body
7+
}
8+
}
9+
10+
// Non-executable comment.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Function name: macro_name_span::affected_function
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 06, 1b, 00, 20]
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 + 6, 27) to (start + 0, 32)
8+
9+
Function name: macro_name_span::main
10+
Raw bytes (9): 0x[01, 02, 00, 01, 01, 0b, 01, 02, 02]
11+
Number of files: 1
12+
- file 0 => global file 2
13+
Number of expressions: 0
14+
Number of file 0 mappings: 1
15+
- Code(Counter(0)) at (prev + 11, 1) to (start + 2, 2)
16+
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
$DIR/auxiliary/macro_name_span_helper.rs:
2+
LL| |// edition: 2021
3+
LL| |
4+
LL| |#[macro_export]
5+
LL| |macro_rules! macro_that_defines_a_function {
6+
LL| | (fn $name:ident () $body:tt) => {
7+
LL| 1| fn $name () -> () $body
8+
LL| | }
9+
LL| |}
10+
LL| |
11+
LL| |// Non-executable comment.
12+
13+
$DIR/macro_name_span.rs:
14+
LL| |// edition: 2021
15+
LL| |
16+
LL| |// Regression test for <https://github.com/rust-lang/rust/issues/117788>.
17+
LL| |// Under some circumstances, the heuristics that detect macro name spans can
18+
LL| |// get confused and produce incorrect spans beyond the bounds of the span
19+
LL| |// being processed.
20+
LL| |
21+
LL| |// aux-build: macro_name_span_helper.rs
22+
LL| |extern crate macro_name_span_helper;
23+
LL| |
24+
LL| 1|fn main() {
25+
LL| 1| affected_function();
26+
LL| 1|}
27+
LL| |
28+
LL| |macro_rules! macro_with_an_unreasonably_and_egregiously_long_name {
29+
LL| | () => {
30+
LL| | println!("hello");
31+
LL| | };
32+
LL| |}
33+
LL| |
34+
LL| |macro_name_span_helper::macro_that_defines_a_function! {
35+
LL| | fn affected_function() {
36+
LL| | macro_with_an_unreasonably_and_egregiously_long_name!();
37+
LL| | }
38+
LL| |}
39+

tests/coverage/macro_name_span.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// edition: 2021
2+
3+
// Regression test for <https://github.com/rust-lang/rust/issues/117788>.
4+
// Under some circumstances, the heuristics that detect macro name spans can
5+
// get confused and produce incorrect spans beyond the bounds of the span
6+
// being processed.
7+
8+
// aux-build: macro_name_span_helper.rs
9+
extern crate macro_name_span_helper;
10+
11+
fn main() {
12+
affected_function();
13+
}
14+
15+
macro_rules! macro_with_an_unreasonably_and_egregiously_long_name {
16+
() => {
17+
println!("hello");
18+
};
19+
}
20+
21+
macro_name_span_helper::macro_that_defines_a_function! {
22+
fn affected_function() {
23+
macro_with_an_unreasonably_and_egregiously_long_name!();
24+
}
25+
}

0 commit comments

Comments
 (0)