Coverage spans should not overlap nested items · Issue #126626 · rust-lang/rust (original) (raw)

Currently we have special-case code that detects closure expressions within a function, and truncates any coverage spans from the outer function that would overlap with the closure. This is needed to have execution counts from the outer function show up on lines associated with the closure, which would be confusion.

However, we don't have similar handling for other kinds of nested items, such as nested functions, nested data types, and nested macros.

This can result in confusing/silly execution counts for lines associated with the inner items, as seen in this contrived example:

   LL|       |#[coverage(off)]
   LL|       |fn dense_a() {
   LL|       |    dense_b();
   LL|       |    dense_b();
   LL|       |    #[coverage(on)]
   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|      2|    }
   LL|       |}

Notice that the lines associated with dense_c have an execution count of 2, even though this function is not instrumented for coverage, and the execution count of those lines is not actually 2.

@rustbot label +A-code-coverage