Skip to content

Commit 4c98134

Browse files
committed
coverage: Add a test showing the inconsistent handling of function signatures
1 parent c7f3948 commit 4c98134

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Function name: fn_sig_into_try::a
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0a, 01, 04, 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 + 10, 1) to (start + 4, 2)
8+
9+
Function name: fn_sig_into_try::b
10+
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 12, 05, 00, 0f, 00, 00, 0f, 00, 10, 02, 01, 05, 00, 0c, 07, 01, 01, 00, 02]
11+
Number of files: 1
12+
- file 0 => global file 1
13+
Number of expressions: 2
14+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
15+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
16+
Number of file 0 mappings: 4
17+
- Code(Counter(0)) at (prev + 18, 5) to (start + 0, 15)
18+
- Code(Zero) at (prev + 0, 15) to (start + 0, 16)
19+
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 12)
20+
= (c0 - c1)
21+
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
22+
= (c1 + (c0 - c1))
23+
24+
Function name: fn_sig_into_try::c
25+
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 18, 0d, 00, 17, 00, 00, 17, 00, 18, 02, 01, 05, 00, 0c, 07, 01, 01, 00, 02]
26+
Number of files: 1
27+
- file 0 => global file 1
28+
Number of expressions: 2
29+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
30+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
31+
Number of file 0 mappings: 4
32+
- Code(Counter(0)) at (prev + 24, 13) to (start + 0, 23)
33+
- Code(Zero) at (prev + 0, 23) to (start + 0, 24)
34+
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 12)
35+
= (c0 - c1)
36+
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
37+
= (c1 + (c0 - c1))
38+
39+
Function name: fn_sig_into_try::d
40+
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 1c, 01, 03, 0f, 00, 03, 0f, 00, 10, 02, 01, 05, 00, 0c, 07, 01, 01, 00, 02]
41+
Number of files: 1
42+
- file 0 => global file 1
43+
Number of expressions: 2
44+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
45+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
46+
Number of file 0 mappings: 4
47+
- Code(Counter(0)) at (prev + 28, 1) to (start + 3, 15)
48+
- Code(Zero) at (prev + 3, 15) to (start + 0, 16)
49+
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 12)
50+
= (c0 - c1)
51+
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
52+
= (c1 + (c0 - c1))
53+

tests/coverage-map/fn_sig_into_try.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![feature(coverage_attribute)]
2+
// compile-flags: --edition=2021
3+
4+
// Regression test for inconsistent handling of function signature spans that
5+
// are followed by code using the `?` operator.
6+
//
7+
// For each of these similar functions, the line containing the function
8+
// signature should be handled in the same way.
9+
10+
fn a() -> Option<i32>
11+
{
12+
Some(7i32);
13+
Some(0)
14+
}
15+
16+
fn b() -> Option<i32>
17+
{
18+
Some(7i32)?;
19+
Some(0)
20+
}
21+
22+
fn c() -> Option<i32>
23+
{
24+
let _ = Some(7i32)?;
25+
Some(0)
26+
}
27+
28+
fn d() -> Option<i32>
29+
{
30+
let _: () = ();
31+
Some(7i32)?;
32+
Some(0)
33+
}
34+
35+
#[coverage(off)]
36+
fn main() {
37+
a();
38+
b();
39+
c();
40+
d();
41+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |// compile-flags: --edition=2021
3+
LL| |
4+
LL| |// Regression test for inconsistent handling of function signature spans that
5+
LL| |// are followed by code using the `?` operator.
6+
LL| |//
7+
LL| |// For each of these similar functions, the line containing the function
8+
LL| |// signature should be handled in the same way.
9+
LL| |
10+
LL| 1|fn a() -> Option<i32>
11+
LL| 1|{
12+
LL| 1| Some(7i32);
13+
LL| 1| Some(0)
14+
LL| 1|}
15+
LL| |
16+
LL| |fn b() -> Option<i32>
17+
LL| |{
18+
LL| 1| Some(7i32)?;
19+
^0
20+
LL| 1| Some(0)
21+
LL| 1|}
22+
LL| |
23+
LL| |fn c() -> Option<i32>
24+
LL| |{
25+
LL| 1| let _ = Some(7i32)?;
26+
^0
27+
LL| 1| Some(0)
28+
LL| 1|}
29+
LL| |
30+
LL| 1|fn d() -> Option<i32>
31+
LL| 1|{
32+
LL| 1| let _: () = ();
33+
LL| 1| Some(7i32)?;
34+
^0
35+
LL| 1| Some(0)
36+
LL| 1|}
37+
LL| |
38+
LL| |#[coverage(off)]
39+
LL| |fn main() {
40+
LL| | a();
41+
LL| | b();
42+
LL| | c();
43+
LL| | d();
44+
LL| |}
45+

tests/run-coverage/fn_sig_into_try.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![feature(coverage_attribute)]
2+
// compile-flags: --edition=2021
3+
4+
// Regression test for inconsistent handling of function signature spans that
5+
// are followed by code using the `?` operator.
6+
//
7+
// For each of these similar functions, the line containing the function
8+
// signature should be handled in the same way.
9+
10+
fn a() -> Option<i32>
11+
{
12+
Some(7i32);
13+
Some(0)
14+
}
15+
16+
fn b() -> Option<i32>
17+
{
18+
Some(7i32)?;
19+
Some(0)
20+
}
21+
22+
fn c() -> Option<i32>
23+
{
24+
let _ = Some(7i32)?;
25+
Some(0)
26+
}
27+
28+
fn d() -> Option<i32>
29+
{
30+
let _: () = ();
31+
Some(7i32)?;
32+
Some(0)
33+
}
34+
35+
#[coverage(off)]
36+
fn main() {
37+
a();
38+
b();
39+
c();
40+
d();
41+
}

0 commit comments

Comments
 (0)