about summary refs log tree commit diff
path: root/tests/coverage
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2025-07-28 12:05:17 +1000
committerZalathar <Zalathar@users.noreply.github.com>2025-07-29 19:55:54 +1000
commit27610341768951b2d46071683bcb87ea7c690e98 (patch)
tree2cbc95fc99738e51707f54897812aaf0ccd57f49 /tests/coverage
parent552904134b564a74489db50aebe7070fdcce895c (diff)
downloadrust-27610341768951b2d46071683bcb87ea7c690e98.tar.gz
rust-27610341768951b2d46071683bcb87ea7c690e98.zip
coverage: Test how `#[automatically_derived]` affects instrumentation
Diffstat (limited to 'tests/coverage')
-rw-r--r--tests/coverage/auto-derived.auto.cov-map47
-rw-r--r--tests/coverage/auto-derived.auto.coverage54
-rw-r--r--tests/coverage/auto-derived.base.cov-map61
-rw-r--r--tests/coverage/auto-derived.base.coverage54
-rw-r--r--tests/coverage/auto-derived.on.cov-map47
-rw-r--r--tests/coverage/auto-derived.on.coverage54
-rw-r--r--tests/coverage/auto-derived.rs53
7 files changed, 370 insertions, 0 deletions
diff --git a/tests/coverage/auto-derived.auto.cov-map b/tests/coverage/auto-derived.auto.cov-map
new file mode 100644
index 00000000000..a0aa1206de4
--- /dev/null
+++ b/tests/coverage/auto-derived.auto.cov-map
@@ -0,0 +1,47 @@
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 26, 9) to (start + 0, 22)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 30)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn_on
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 31, 9) to (start + 0, 25)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 35)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::{closure#0}
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 35, 26) to (start + 0, 27)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 29)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: auto_derived::main
+Raw bytes (19): 0x[01, 01, 00, 03, 01, 33, 01, 00, 0a, 01, 01, 05, 00, 1a, 01, 01, 01, 00, 02]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 3
+- Code(Counter(0)) at (prev + 51, 1) to (start + 0, 10)
+- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 26)
+- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
+Highest counter ID seen: c0
+
diff --git a/tests/coverage/auto-derived.auto.coverage b/tests/coverage/auto-derived.auto.coverage
new file mode 100644
index 00000000000..960bd11ec3a
--- /dev/null
+++ b/tests/coverage/auto-derived.auto.coverage
@@ -0,0 +1,54 @@
+   LL|       |#![feature(coverage_attribute)]
+   LL|       |//@ edition: 2024
+   LL|       |//@ revisions: base auto on
+   LL|       |
+   LL|       |// Tests for how `#[automatically_derived]` affects coverage instrumentation.
+   LL|       |//
+   LL|       |// The actual behaviour is an implementation detail, so this test mostly exists
+   LL|       |// to show when that behaviour has been accidentally or deliberately changed.
+   LL|       |//
+   LL|       |// Revision guide:
+   LL|       |// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
+   LL|       |// - auto: Test how `#[automatically_derived]` affects instrumentation
+   LL|       |// - on:   Test interaction between auto-derived and `#[coverage(on)]`
+   LL|       |
+   LL|       |struct MyStruct;
+   LL|       |
+   LL|       |trait MyTrait {
+   LL|       |    fn my_assoc_fn();
+   LL|       |}
+   LL|       |
+   LL|       |#[cfg_attr(auto, automatically_derived)]
+   LL|       |#[cfg_attr(on, automatically_derived)]
+   LL|       |#[cfg_attr(on, coverage(on))]
+   LL|       |impl MyTrait for MyStruct {
+   LL|       |    fn my_assoc_fn() {
+   LL|      1|        fn inner_fn() {
+   LL|      1|            say("in inner fn");
+   LL|      1|        }
+   LL|       |
+   LL|       |        #[coverage(on)]
+   LL|      1|        fn inner_fn_on() {
+   LL|      1|            say("in inner fn (on)");
+   LL|      1|        }
+   LL|       |
+   LL|      1|        let closure = || {
+   LL|      1|            say("in closure");
+   LL|      1|        };
+   LL|       |
+   LL|       |        closure();
+   LL|       |        inner_fn();
+   LL|       |        inner_fn_on();
+   LL|       |    }
+   LL|       |}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |#[inline(never)]
+   LL|       |fn say(s: &str) {
+   LL|       |    println!("{s}");
+   LL|       |}
+   LL|       |
+   LL|      1|fn main() {
+   LL|      1|    MyStruct::my_assoc_fn();
+   LL|      1|}
+
diff --git a/tests/coverage/auto-derived.base.cov-map b/tests/coverage/auto-derived.base.cov-map
new file mode 100644
index 00000000000..2dcd616300d
--- /dev/null
+++ b/tests/coverage/auto-derived.base.cov-map
@@ -0,0 +1,61 @@
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 6
+- Code(Counter(0)) at (prev + 25, 5) to (start + 0, 21)
+- Code(Counter(0)) at (prev + 10, 13) to (start + 0, 20)
+- Code(Counter(0)) at (prev + 4, 9) to (start + 0, 18)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 20)
+- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6)
+Highest counter ID seen: c0
+
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 26, 9) to (start + 0, 22)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 30)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn_on
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 31, 9) to (start + 0, 25)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 35)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::{closure#0}
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 35, 26) to (start + 0, 27)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 29)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: auto_derived::main
+Raw bytes (19): 0x[01, 01, 00, 03, 01, 33, 01, 00, 0a, 01, 01, 05, 00, 1a, 01, 01, 01, 00, 02]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 3
+- Code(Counter(0)) at (prev + 51, 1) to (start + 0, 10)
+- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 26)
+- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
+Highest counter ID seen: c0
+
diff --git a/tests/coverage/auto-derived.base.coverage b/tests/coverage/auto-derived.base.coverage
new file mode 100644
index 00000000000..6ab6aa5c4df
--- /dev/null
+++ b/tests/coverage/auto-derived.base.coverage
@@ -0,0 +1,54 @@
+   LL|       |#![feature(coverage_attribute)]
+   LL|       |//@ edition: 2024
+   LL|       |//@ revisions: base auto on
+   LL|       |
+   LL|       |// Tests for how `#[automatically_derived]` affects coverage instrumentation.
+   LL|       |//
+   LL|       |// The actual behaviour is an implementation detail, so this test mostly exists
+   LL|       |// to show when that behaviour has been accidentally or deliberately changed.
+   LL|       |//
+   LL|       |// Revision guide:
+   LL|       |// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
+   LL|       |// - auto: Test how `#[automatically_derived]` affects instrumentation
+   LL|       |// - on:   Test interaction between auto-derived and `#[coverage(on)]`
+   LL|       |
+   LL|       |struct MyStruct;
+   LL|       |
+   LL|       |trait MyTrait {
+   LL|       |    fn my_assoc_fn();
+   LL|       |}
+   LL|       |
+   LL|       |#[cfg_attr(auto, automatically_derived)]
+   LL|       |#[cfg_attr(on, automatically_derived)]
+   LL|       |#[cfg_attr(on, coverage(on))]
+   LL|       |impl MyTrait for MyStruct {
+   LL|      1|    fn my_assoc_fn() {
+   LL|      1|        fn inner_fn() {
+   LL|      1|            say("in inner fn");
+   LL|      1|        }
+   LL|       |
+   LL|       |        #[coverage(on)]
+   LL|      1|        fn inner_fn_on() {
+   LL|      1|            say("in inner fn (on)");
+   LL|      1|        }
+   LL|       |
+   LL|      1|        let closure = || {
+   LL|      1|            say("in closure");
+   LL|      1|        };
+   LL|       |
+   LL|      1|        closure();
+   LL|      1|        inner_fn();
+   LL|      1|        inner_fn_on();
+   LL|      1|    }
+   LL|       |}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |#[inline(never)]
+   LL|       |fn say(s: &str) {
+   LL|       |    println!("{s}");
+   LL|       |}
+   LL|       |
+   LL|      1|fn main() {
+   LL|      1|    MyStruct::my_assoc_fn();
+   LL|      1|}
+
diff --git a/tests/coverage/auto-derived.on.cov-map b/tests/coverage/auto-derived.on.cov-map
new file mode 100644
index 00000000000..a0aa1206de4
--- /dev/null
+++ b/tests/coverage/auto-derived.on.cov-map
@@ -0,0 +1,47 @@
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 26, 9) to (start + 0, 22)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 30)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::inner_fn_on
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 31, 9) to (start + 0, 25)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 35)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: <auto_derived::MyStruct as auto_derived::MyTrait>::my_assoc_fn::{closure#0}
+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]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 4
+- Code(Counter(0)) at (prev + 35, 26) to (start + 0, 27)
+- Code(Counter(0)) at (prev + 1, 13) to (start + 0, 16)
+- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 29)
+- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
+Highest counter ID seen: c0
+
+Function name: auto_derived::main
+Raw bytes (19): 0x[01, 01, 00, 03, 01, 33, 01, 00, 0a, 01, 01, 05, 00, 1a, 01, 01, 01, 00, 02]
+Number of files: 1
+- file 0 => $DIR/auto-derived.rs
+Number of expressions: 0
+Number of file 0 mappings: 3
+- Code(Counter(0)) at (prev + 51, 1) to (start + 0, 10)
+- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 26)
+- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
+Highest counter ID seen: c0
+
diff --git a/tests/coverage/auto-derived.on.coverage b/tests/coverage/auto-derived.on.coverage
new file mode 100644
index 00000000000..960bd11ec3a
--- /dev/null
+++ b/tests/coverage/auto-derived.on.coverage
@@ -0,0 +1,54 @@
+   LL|       |#![feature(coverage_attribute)]
+   LL|       |//@ edition: 2024
+   LL|       |//@ revisions: base auto on
+   LL|       |
+   LL|       |// Tests for how `#[automatically_derived]` affects coverage instrumentation.
+   LL|       |//
+   LL|       |// The actual behaviour is an implementation detail, so this test mostly exists
+   LL|       |// to show when that behaviour has been accidentally or deliberately changed.
+   LL|       |//
+   LL|       |// Revision guide:
+   LL|       |// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
+   LL|       |// - auto: Test how `#[automatically_derived]` affects instrumentation
+   LL|       |// - on:   Test interaction between auto-derived and `#[coverage(on)]`
+   LL|       |
+   LL|       |struct MyStruct;
+   LL|       |
+   LL|       |trait MyTrait {
+   LL|       |    fn my_assoc_fn();
+   LL|       |}
+   LL|       |
+   LL|       |#[cfg_attr(auto, automatically_derived)]
+   LL|       |#[cfg_attr(on, automatically_derived)]
+   LL|       |#[cfg_attr(on, coverage(on))]
+   LL|       |impl MyTrait for MyStruct {
+   LL|       |    fn my_assoc_fn() {
+   LL|      1|        fn inner_fn() {
+   LL|      1|            say("in inner fn");
+   LL|      1|        }
+   LL|       |
+   LL|       |        #[coverage(on)]
+   LL|      1|        fn inner_fn_on() {
+   LL|      1|            say("in inner fn (on)");
+   LL|      1|        }
+   LL|       |
+   LL|      1|        let closure = || {
+   LL|      1|            say("in closure");
+   LL|      1|        };
+   LL|       |
+   LL|       |        closure();
+   LL|       |        inner_fn();
+   LL|       |        inner_fn_on();
+   LL|       |    }
+   LL|       |}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |#[inline(never)]
+   LL|       |fn say(s: &str) {
+   LL|       |    println!("{s}");
+   LL|       |}
+   LL|       |
+   LL|      1|fn main() {
+   LL|      1|    MyStruct::my_assoc_fn();
+   LL|      1|}
+
diff --git a/tests/coverage/auto-derived.rs b/tests/coverage/auto-derived.rs
new file mode 100644
index 00000000000..cbf8279918a
--- /dev/null
+++ b/tests/coverage/auto-derived.rs
@@ -0,0 +1,53 @@
+#![feature(coverage_attribute)]
+//@ edition: 2024
+//@ revisions: base auto on
+
+// Tests for how `#[automatically_derived]` affects coverage instrumentation.
+//
+// The actual behaviour is an implementation detail, so this test mostly exists
+// to show when that behaviour has been accidentally or deliberately changed.
+//
+// Revision guide:
+// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
+// - auto: Test how `#[automatically_derived]` affects instrumentation
+// - on:   Test interaction between auto-derived and `#[coverage(on)]`
+
+struct MyStruct;
+
+trait MyTrait {
+    fn my_assoc_fn();
+}
+
+#[cfg_attr(auto, automatically_derived)]
+#[cfg_attr(on, automatically_derived)]
+#[cfg_attr(on, coverage(on))]
+impl MyTrait for MyStruct {
+    fn my_assoc_fn() {
+        fn inner_fn() {
+            say("in inner fn");
+        }
+
+        #[coverage(on)]
+        fn inner_fn_on() {
+            say("in inner fn (on)");
+        }
+
+        let closure = || {
+            say("in closure");
+        };
+
+        closure();
+        inner_fn();
+        inner_fn_on();
+    }
+}
+
+#[coverage(off)]
+#[inline(never)]
+fn say(s: &str) {
+    println!("{s}");
+}
+
+fn main() {
+    MyStruct::my_assoc_fn();
+}