Skip to content

Commit 41ed32f

Browse files
committed
coverage: Test how #[automatically_derived] affects instrumentation
1 parent f8e355c commit 41ed32f

7 files changed

+370
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn
2+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 1a, 09, 00, 16, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 1e, 01, 01, 09, 00, 0a]
3+
Number of files: 1
4+
- file 0 => $DIR/auto-derived.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 4
7+
- Code(Counter(0)) at (prev + 26, 9) to (start + 0, 22)
8+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
9+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 30)
10+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
11+
Highest counter ID seen: c0
12+
13+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn_on
14+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 1f, 09, 00, 19, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 23, 01, 01, 09, 00, 0a]
15+
Number of files: 1
16+
- file 0 => $DIR/auto-derived.rs
17+
Number of expressions: 0
18+
Number of file 0 mappings: 4
19+
- Code(Counter(0)) at (prev + 31, 9) to (start + 0, 25)
20+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
21+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 35)
22+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
23+
Highest counter ID seen: c0
24+
25+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::{closure#0}
26+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 23, 1a, 00, 1b, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 1d, 01, 01, 09, 00, 0a]
27+
Number of files: 1
28+
- file 0 => $DIR/auto-derived.rs
29+
Number of expressions: 0
30+
Number of file 0 mappings: 4
31+
- Code(Counter(0)) at (prev + 35, 26) to (start + 0, 27)
32+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
33+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 29)
34+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
35+
Highest counter ID seen: c0
36+
37+
Function name: auto_derived::main
38+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 33, 01, 00, 0a, 01, 01, 05, 00, 1a, 01, 01, 01, 00, 02]
39+
Number of files: 1
40+
- file 0 => $DIR/auto-derived.rs
41+
Number of expressions: 0
42+
Number of file 0 mappings: 3
43+
- Code(Counter(0)) at (prev + 51, 1) to (start + 0, 10)
44+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 26)
45+
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
46+
Highest counter ID seen: c0
47+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |//@ revisions: base auto on
4+
LL| |
5+
LL| |// Tests for how `#[automatically_derived]` affects coverage instrumentation.
6+
LL| |//
7+
LL| |// The actual behaviour is an implementation detail, so this test mostly exists
8+
LL| |// to show when that behaviour has been accidentally or deliberately changed.
9+
LL| |//
10+
LL| |// Revision guide:
11+
LL| |// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
12+
LL| |// - auto: Test how `#[automatically_derived]` affects instrumentation
13+
LL| |// - on: Test interaction between auto-derived and `#[coverage(on)]`
14+
LL| |
15+
LL| |struct MyStruct;
16+
LL| |
17+
LL| |trait MyTrait {
18+
LL| | fn my_assoc_fn();
19+
LL| |}
20+
LL| |
21+
LL| |#[cfg_attr(auto, automatically_derived)]
22+
LL| |#[cfg_attr(on, automatically_derived)]
23+
LL| |#[cfg_attr(on, coverage(on))]
24+
LL| |impl MyTrait for MyStruct {
25+
LL| | fn my_assoc_fn() {
26+
LL| 1| fn inner_fn() {
27+
LL| 1| say("in inner fn");
28+
LL| 1| }
29+
LL| |
30+
LL| | #[coverage(on)]
31+
LL| 1| fn inner_fn_on() {
32+
LL| 1| say("in inner fn (on)");
33+
LL| 1| }
34+
LL| |
35+
LL| 1| let closure = || {
36+
LL| 1| say("in closure");
37+
LL| 1| };
38+
LL| |
39+
LL| | closure();
40+
LL| | inner_fn();
41+
LL| | inner_fn_on();
42+
LL| | }
43+
LL| |}
44+
LL| |
45+
LL| |#[coverage(off)]
46+
LL| |#[inline(never)]
47+
LL| |fn say(s: &str) {
48+
LL| | println!("{s}");
49+
LL| |}
50+
LL| |
51+
LL| 1|fn main() {
52+
LL| 1| MyStruct::my_assoc_fn();
53+
LL| 1|}
54+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn
2+
Raw bytes (34): 0x[01, 01, 00, 06, 01, 19, 05, 00, 15, 01, 0a, 0d, 00, 14, 01, 04, 09, 00, 12, 01, 01, 09, 00, 11, 01, 01, 09, 00, 14, 01, 01, 05, 00, 06]
3+
Number of files: 1
4+
- file 0 => $DIR/auto-derived.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 6
7+
- Code(Counter(0)) at (prev + 25, 5) to (start + 0, 21)
8+
- Code(Counter(0)) at (prev + 10, 13) to (start + 0, 20)
9+
- Code(Counter(0)) at (prev + 4, 9) to (start + 0, 18)
10+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17)
11+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 20)
12+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6)
13+
Highest counter ID seen: c0
14+
15+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn
16+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 1a, 09, 00, 16, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 1e, 01, 01, 09, 00, 0a]
17+
Number of files: 1
18+
- file 0 => $DIR/auto-derived.rs
19+
Number of expressions: 0
20+
Number of file 0 mappings: 4
21+
- Code(Counter(0)) at (prev + 26, 9) to (start + 0, 22)
22+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
23+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 30)
24+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
25+
Highest counter ID seen: c0
26+
27+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn_on
28+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 1f, 09, 00, 19, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 23, 01, 01, 09, 00, 0a]
29+
Number of files: 1
30+
- file 0 => $DIR/auto-derived.rs
31+
Number of expressions: 0
32+
Number of file 0 mappings: 4
33+
- Code(Counter(0)) at (prev + 31, 9) to (start + 0, 25)
34+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
35+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 35)
36+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
37+
Highest counter ID seen: c0
38+
39+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::{closure#0}
40+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 23, 1a, 00, 1b, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 1d, 01, 01, 09, 00, 0a]
41+
Number of files: 1
42+
- file 0 => $DIR/auto-derived.rs
43+
Number of expressions: 0
44+
Number of file 0 mappings: 4
45+
- Code(Counter(0)) at (prev + 35, 26) to (start + 0, 27)
46+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
47+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 29)
48+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
49+
Highest counter ID seen: c0
50+
51+
Function name: auto_derived::main
52+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 33, 01, 00, 0a, 01, 01, 05, 00, 1a, 01, 01, 01, 00, 02]
53+
Number of files: 1
54+
- file 0 => $DIR/auto-derived.rs
55+
Number of expressions: 0
56+
Number of file 0 mappings: 3
57+
- Code(Counter(0)) at (prev + 51, 1) to (start + 0, 10)
58+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 26)
59+
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
60+
Highest counter ID seen: c0
61+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |//@ revisions: base auto on
4+
LL| |
5+
LL| |// Tests for how `#[automatically_derived]` affects coverage instrumentation.
6+
LL| |//
7+
LL| |// The actual behaviour is an implementation detail, so this test mostly exists
8+
LL| |// to show when that behaviour has been accidentally or deliberately changed.
9+
LL| |//
10+
LL| |// Revision guide:
11+
LL| |// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
12+
LL| |// - auto: Test how `#[automatically_derived]` affects instrumentation
13+
LL| |// - on: Test interaction between auto-derived and `#[coverage(on)]`
14+
LL| |
15+
LL| |struct MyStruct;
16+
LL| |
17+
LL| |trait MyTrait {
18+
LL| | fn my_assoc_fn();
19+
LL| |}
20+
LL| |
21+
LL| |#[cfg_attr(auto, automatically_derived)]
22+
LL| |#[cfg_attr(on, automatically_derived)]
23+
LL| |#[cfg_attr(on, coverage(on))]
24+
LL| |impl MyTrait for MyStruct {
25+
LL| 1| fn my_assoc_fn() {
26+
LL| 1| fn inner_fn() {
27+
LL| 1| say("in inner fn");
28+
LL| 1| }
29+
LL| |
30+
LL| | #[coverage(on)]
31+
LL| 1| fn inner_fn_on() {
32+
LL| 1| say("in inner fn (on)");
33+
LL| 1| }
34+
LL| |
35+
LL| 1| let closure = || {
36+
LL| 1| say("in closure");
37+
LL| 1| };
38+
LL| |
39+
LL| 1| closure();
40+
LL| 1| inner_fn();
41+
LL| 1| inner_fn_on();
42+
LL| 1| }
43+
LL| |}
44+
LL| |
45+
LL| |#[coverage(off)]
46+
LL| |#[inline(never)]
47+
LL| |fn say(s: &str) {
48+
LL| | println!("{s}");
49+
LL| |}
50+
LL| |
51+
LL| 1|fn main() {
52+
LL| 1| MyStruct::my_assoc_fn();
53+
LL| 1|}
54+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn
2+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 1a, 09, 00, 16, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 1e, 01, 01, 09, 00, 0a]
3+
Number of files: 1
4+
- file 0 => $DIR/auto-derived.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 4
7+
- Code(Counter(0)) at (prev + 26, 9) to (start + 0, 22)
8+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
9+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 30)
10+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
11+
Highest counter ID seen: c0
12+
13+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn_on
14+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 1f, 09, 00, 19, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 23, 01, 01, 09, 00, 0a]
15+
Number of files: 1
16+
- file 0 => $DIR/auto-derived.rs
17+
Number of expressions: 0
18+
Number of file 0 mappings: 4
19+
- Code(Counter(0)) at (prev + 31, 9) to (start + 0, 25)
20+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
21+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 35)
22+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
23+
Highest counter ID seen: c0
24+
25+
Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::{closure#0}
26+
Raw bytes (24): 0x[01, 01, 00, 04, 01, 23, 1a, 00, 1b, 01, 01, 0d, 00, 10, 01, 00, 11, 00, 1d, 01, 01, 09, 00, 0a]
27+
Number of files: 1
28+
- file 0 => $DIR/auto-derived.rs
29+
Number of expressions: 0
30+
Number of file 0 mappings: 4
31+
- Code(Counter(0)) at (prev + 35, 26) to (start + 0, 27)
32+
- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
33+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 29)
34+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
35+
Highest counter ID seen: c0
36+
37+
Function name: auto_derived::main
38+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 33, 01, 00, 0a, 01, 01, 05, 00, 1a, 01, 01, 01, 00, 02]
39+
Number of files: 1
40+
- file 0 => $DIR/auto-derived.rs
41+
Number of expressions: 0
42+
Number of file 0 mappings: 3
43+
- Code(Counter(0)) at (prev + 51, 1) to (start + 0, 10)
44+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 26)
45+
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
46+
Highest counter ID seen: c0
47+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |//@ revisions: base auto on
4+
LL| |
5+
LL| |// Tests for how `#[automatically_derived]` affects coverage instrumentation.
6+
LL| |//
7+
LL| |// The actual behaviour is an implementation detail, so this test mostly exists
8+
LL| |// to show when that behaviour has been accidentally or deliberately changed.
9+
LL| |//
10+
LL| |// Revision guide:
11+
LL| |// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
12+
LL| |// - auto: Test how `#[automatically_derived]` affects instrumentation
13+
LL| |// - on: Test interaction between auto-derived and `#[coverage(on)]`
14+
LL| |
15+
LL| |struct MyStruct;
16+
LL| |
17+
LL| |trait MyTrait {
18+
LL| | fn my_assoc_fn();
19+
LL| |}
20+
LL| |
21+
LL| |#[cfg_attr(auto, automatically_derived)]
22+
LL| |#[cfg_attr(on, automatically_derived)]
23+
LL| |#[cfg_attr(on, coverage(on))]
24+
LL| |impl MyTrait for MyStruct {
25+
LL| | fn my_assoc_fn() {
26+
LL| 1| fn inner_fn() {
27+
LL| 1| say("in inner fn");
28+
LL| 1| }
29+
LL| |
30+
LL| | #[coverage(on)]
31+
LL| 1| fn inner_fn_on() {
32+
LL| 1| say("in inner fn (on)");
33+
LL| 1| }
34+
LL| |
35+
LL| 1| let closure = || {
36+
LL| 1| say("in closure");
37+
LL| 1| };
38+
LL| |
39+
LL| | closure();
40+
LL| | inner_fn();
41+
LL| | inner_fn_on();
42+
LL| | }
43+
LL| |}
44+
LL| |
45+
LL| |#[coverage(off)]
46+
LL| |#[inline(never)]
47+
LL| |fn say(s: &str) {
48+
LL| | println!("{s}");
49+
LL| |}
50+
LL| |
51+
LL| 1|fn main() {
52+
LL| 1| MyStruct::my_assoc_fn();
53+
LL| 1|}
54+

tests/coverage/auto-derived.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2024
3+
//@ revisions: base auto on
4+
5+
// Tests for how `#[automatically_derived]` affects coverage instrumentation.
6+
//
7+
// The actual behaviour is an implementation detail, so this test mostly exists
8+
// to show when that behaviour has been accidentally or deliberately changed.
9+
//
10+
// Revision guide:
11+
// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
12+
// - auto: Test how `#[automatically_derived]` affects instrumentation
13+
// - on: Test interaction between auto-derived and `#[coverage(on)]`
14+
15+
struct MyStruct;
16+
17+
trait MyTrait {
18+
fn my_assoc_fn();
19+
}
20+
21+
#[cfg_attr(auto, automatically_derived)]
22+
#[cfg_attr(on, automatically_derived)]
23+
#[cfg_attr(on, coverage(on))]
24+
impl MyTrait for MyStruct {
25+
fn my_assoc_fn() {
26+
fn inner_fn() {
27+
say("in inner fn");
28+
}
29+
30+
#[coverage(on)]
31+
fn inner_fn_on() {
32+
say("in inner fn (on)");
33+
}
34+
35+
let closure = || {
36+
say("in closure");
37+
};
38+
39+
closure();
40+
inner_fn();
41+
inner_fn_on();
42+
}
43+
}
44+
45+
#[coverage(off)]
46+
#[inline(never)]
47+
fn say(s: &str) {
48+
println!("{s}");
49+
}
50+
51+
fn main() {
52+
MyStruct::my_assoc_fn();
53+
}

0 commit comments

Comments
 (0)