Skip to content

Commit fe420dc

Browse files
committed
coverage: Test for closure body that is a single bang-macro
1 parent 268dbbb commit fe420dc

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Function name: macro_in_closure::NO_BLOCK::{closure#0}
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 1c, 00, 2d]
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 + 7, 28) to (start + 0, 45)
8+
9+
Function name: macro_in_closure::WITH_BLOCK::{closure#0}
10+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 09, 1e, 02, 02]
11+
Number of files: 1
12+
- file 0 => global file 1
13+
Number of expressions: 0
14+
Number of file 0 mappings: 1
15+
- Code(Counter(0)) at (prev + 9, 30) to (start + 2, 2)
16+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |// edition: 2021
3+
LL| |
4+
LL| |// If a closure body consists entirely of a single bang-macro invocation, the
5+
LL| |// body span ends up inside the macro-expansion, so we need to un-expand it
6+
LL| |// back to the declaration site.
7+
LL| 1|static NO_BLOCK: fn() = || println!("hello");
8+
LL| |
9+
LL| 1|static WITH_BLOCK: fn() = || {
10+
LL| 1| println!("hello");
11+
LL| 1|};
12+
LL| |
13+
LL| |#[coverage(off)]
14+
LL| |fn main() {
15+
LL| | NO_BLOCK();
16+
LL| | WITH_BLOCK();
17+
LL| |}
18+

tests/coverage/macro_in_closure.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(coverage_attribute)]
2+
// edition: 2021
3+
4+
// If a closure body consists entirely of a single bang-macro invocation, the
5+
// body span ends up inside the macro-expansion, so we need to un-expand it
6+
// back to the declaration site.
7+
static NO_BLOCK: fn() = || println!("hello");
8+
9+
static WITH_BLOCK: fn() = || {
10+
println!("hello");
11+
};
12+
13+
#[coverage(off)]
14+
fn main() {
15+
NO_BLOCK();
16+
WITH_BLOCK();
17+
}

0 commit comments

Comments
 (0)