about summary refs log tree commit diff
path: root/tests/coverage/attr
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-08 13:24:50 +0000
committerbors <bors@rust-lang.org>2024-07-08 13:24:50 +0000
commitcfd7cf5a0e497c238dcf9947e2eeec01837beeb4 (patch)
tree776950273fb7d4fd210f508377149c477800cb66 /tests/coverage/attr
parent59a4f02f836f74c4cf08f47d76c9f6069a2f8276 (diff)
parent63c04f05e60ce27311fc1b874907188616beb558 (diff)
downloadrust-cfd7cf5a0e497c238dcf9947e2eeec01837beeb4.tar.gz
rust-cfd7cf5a0e497c238dcf9947e2eeec01837beeb4.zip
Auto merge of #127199 - Zalathar:hir-holes, r=oli-obk
coverage: Extract hole spans from HIR instead of MIR

This makes it possible to treat more kinds of nested item/code as holes, instead of being restricted to closures.

(It also potentially opens up the possibility of using HIR holes to modify branch or MC/DC spans, though we currently don't actually do this.)

Thus, this new implementation treats the following as holes:
- Closures (as before, including `async` and coroutines)
- All nested items
- Inline `const` (because why not)

This gives more accurate coverage reports, because lines occupied by holes don't show the execution count from the enclosing function.

Fixes #126626.
Diffstat (limited to 'tests/coverage/attr')
-rw-r--r--tests/coverage/attr/nested.cov-map8
-rw-r--r--tests/coverage/attr/nested.coverage5
-rw-r--r--tests/coverage/attr/nested.rs5
-rw-r--r--tests/coverage/attr/off-on-sandwich.cov-map21
-rw-r--r--tests/coverage/attr/off-on-sandwich.coverage21
-rw-r--r--tests/coverage/attr/off-on-sandwich.rs5
6 files changed, 24 insertions, 41 deletions
diff --git a/tests/coverage/attr/nested.cov-map b/tests/coverage/attr/nested.cov-map
index 0f2d5542f75..466aec8956e 100644
--- a/tests/coverage/attr/nested.cov-map
+++ b/tests/coverage/attr/nested.cov-map
@@ -1,18 +1,18 @@
 Function name: nested::closure_expr
-Raw bytes (14): 0x[01, 01, 00, 02, 01, 44, 01, 01, 0f, 01, 0b, 05, 01, 02]
+Raw bytes (14): 0x[01, 01, 00, 02, 01, 3f, 01, 01, 0f, 01, 0b, 05, 01, 02]
 Number of files: 1
 - file 0 => global file 1
 Number of expressions: 0
 Number of file 0 mappings: 2
-- Code(Counter(0)) at (prev + 68, 1) to (start + 1, 15)
+- Code(Counter(0)) at (prev + 63, 1) to (start + 1, 15)
 - Code(Counter(0)) at (prev + 11, 5) to (start + 1, 2)
 
 Function name: nested::closure_tail
-Raw bytes (14): 0x[01, 01, 00, 02, 01, 53, 01, 01, 0f, 01, 11, 05, 01, 02]
+Raw bytes (14): 0x[01, 01, 00, 02, 01, 4e, 01, 01, 0f, 01, 11, 05, 01, 02]
 Number of files: 1
 - file 0 => global file 1
 Number of expressions: 0
 Number of file 0 mappings: 2
-- Code(Counter(0)) at (prev + 83, 1) to (start + 1, 15)
+- Code(Counter(0)) at (prev + 78, 1) to (start + 1, 15)
 - Code(Counter(0)) at (prev + 17, 5) to (start + 1, 2)
 
diff --git a/tests/coverage/attr/nested.coverage b/tests/coverage/attr/nested.coverage
index bdd117b7dfa..2d64fe698ea 100644
--- a/tests/coverage/attr/nested.coverage
+++ b/tests/coverage/attr/nested.coverage
@@ -4,11 +4,6 @@
    LL|       |// Demonstrates the interaction between #[coverage(off)] and various kinds of
    LL|       |// nested function.
    LL|       |
-   LL|       |// FIXME(#126625): Coverage attributes should apply recursively to nested functions.
-   LL|       |// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`,
-   LL|       |// its lines can still be marked with misleading execution counts from its enclosing
-   LL|       |// function.
-   LL|       |
    LL|       |#[coverage(off)]
    LL|       |fn do_stuff() {}
    LL|       |
diff --git a/tests/coverage/attr/nested.rs b/tests/coverage/attr/nested.rs
index c7ff835f44f..8213e29b6fc 100644
--- a/tests/coverage/attr/nested.rs
+++ b/tests/coverage/attr/nested.rs
@@ -4,11 +4,6 @@
 // Demonstrates the interaction between #[coverage(off)] and various kinds of
 // nested function.
 
-// FIXME(#126625): Coverage attributes should apply recursively to nested functions.
-// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`,
-// its lines can still be marked with misleading execution counts from its enclosing
-// function.
-
 #[coverage(off)]
 fn do_stuff() {}
 
diff --git a/tests/coverage/attr/off-on-sandwich.cov-map b/tests/coverage/attr/off-on-sandwich.cov-map
index ed77d7d17e6..d5fbac6ebf7 100644
--- a/tests/coverage/attr/off-on-sandwich.cov-map
+++ b/tests/coverage/attr/off-on-sandwich.cov-map
@@ -1,24 +1,27 @@
 Function name: off_on_sandwich::dense_a::dense_b
-Raw bytes (9): 0x[01, 01, 00, 01, 01, 14, 05, 07, 06]
+Raw bytes (14): 0x[01, 01, 00, 02, 01, 0f, 05, 02, 12, 01, 07, 05, 00, 06]
 Number of files: 1
 - file 0 => global file 1
 Number of expressions: 0
-Number of file 0 mappings: 1
-- Code(Counter(0)) at (prev + 20, 5) to (start + 7, 6)
+Number of file 0 mappings: 2
+- Code(Counter(0)) at (prev + 15, 5) to (start + 2, 18)
+- Code(Counter(0)) at (prev + 7, 5) to (start + 0, 6)
 
 Function name: off_on_sandwich::sparse_a::sparse_b::sparse_c
-Raw bytes (9): 0x[01, 01, 00, 01, 01, 26, 09, 0b, 0a]
+Raw bytes (14): 0x[01, 01, 00, 02, 01, 21, 09, 02, 17, 01, 0b, 09, 00, 0a]
 Number of files: 1
 - file 0 => global file 1
 Number of expressions: 0
-Number of file 0 mappings: 1
-- Code(Counter(0)) at (prev + 38, 9) to (start + 11, 10)
+Number of file 0 mappings: 2
+- Code(Counter(0)) at (prev + 33, 9) to (start + 2, 23)
+- Code(Counter(0)) at (prev + 11, 9) to (start + 0, 10)
 
 Function name: off_on_sandwich::sparse_a::sparse_b::sparse_c::sparse_d
-Raw bytes (9): 0x[01, 01, 00, 01, 01, 29, 0d, 07, 0e]
+Raw bytes (14): 0x[01, 01, 00, 02, 01, 24, 0d, 02, 1b, 01, 07, 0d, 00, 0e]
 Number of files: 1
 - file 0 => global file 1
 Number of expressions: 0
-Number of file 0 mappings: 1
-- Code(Counter(0)) at (prev + 41, 13) to (start + 7, 14)
+Number of file 0 mappings: 2
+- Code(Counter(0)) at (prev + 36, 13) to (start + 2, 27)
+- Code(Counter(0)) at (prev + 7, 13) to (start + 0, 14)
 
diff --git a/tests/coverage/attr/off-on-sandwich.coverage b/tests/coverage/attr/off-on-sandwich.coverage
index 58c128b8342..675697906ee 100644
--- a/tests/coverage/attr/off-on-sandwich.coverage
+++ b/tests/coverage/attr/off-on-sandwich.coverage
@@ -4,11 +4,6 @@
    LL|       |// Demonstrates the interaction of `#[coverage(off)]` and `#[coverage(on)]`
    LL|       |// in nested functions.
    LL|       |
-   LL|       |// FIXME(#126625): Coverage attributes should apply recursively to nested functions.
-   LL|       |// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`,
-   LL|       |// its lines can still be marked with misleading execution counts from its enclosing
-   LL|       |// function.
-   LL|       |
    LL|       |#[coverage(off)]
    LL|       |fn do_stuff() {}
    LL|       |
@@ -20,10 +15,10 @@
    LL|      2|    fn dense_b() {
    LL|      2|        dense_c();
    LL|      2|        dense_c();
-   LL|      2|        #[coverage(off)]
-   LL|      2|        fn dense_c() {
-   LL|      2|            do_stuff();
-   LL|      2|        }
+   LL|       |        #[coverage(off)]
+   LL|       |        fn dense_c() {
+   LL|       |            do_stuff();
+   LL|       |        }
    LL|      2|    }
    LL|       |}
    LL|       |
@@ -41,10 +36,10 @@
    LL|      8|            fn sparse_d() {
    LL|      8|                sparse_e();
    LL|      8|                sparse_e();
-   LL|      8|                #[coverage(off)]
-   LL|      8|                fn sparse_e() {
-   LL|      8|                    do_stuff();
-   LL|      8|                }
+   LL|       |                #[coverage(off)]
+   LL|       |                fn sparse_e() {
+   LL|       |                    do_stuff();
+   LL|       |                }
    LL|      8|            }
    LL|      4|        }
    LL|       |    }
diff --git a/tests/coverage/attr/off-on-sandwich.rs b/tests/coverage/attr/off-on-sandwich.rs
index 6b21b180223..261634e0029 100644
--- a/tests/coverage/attr/off-on-sandwich.rs
+++ b/tests/coverage/attr/off-on-sandwich.rs
@@ -4,11 +4,6 @@
 // Demonstrates the interaction of `#[coverage(off)]` and `#[coverage(on)]`
 // in nested functions.
 
-// FIXME(#126625): Coverage attributes should apply recursively to nested functions.
-// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`,
-// its lines can still be marked with misleading execution counts from its enclosing
-// function.
-
 #[coverage(off)]
 fn do_stuff() {}