Skip to content

Coverage only applies to spans in a contiguous span of source code (not both macro and caller) #85000

Open
@richkadel

Description

@richkadel

Explore adding coverage spans for all sources that emit some coverable spans, including macros and the source that invokes the macros.

The current implementation of -Zinstrument-coverage requires choosing a span in which to report coverage. Typically this is the function's or closure's body_span, so functions that invoke macros will have coverage but code within the expanded macro will not have coverage. Or, if the macro starts the body span (if the macro emits the left curly brace), the macro will have coverage, and any code in the calling source (if passed as an argument to the macro) will not get coverage.

This latter effect was a problem for closures that don't include enclosing braces, until PR #84897 .

PR #84897 is better, but limited: The PR removed coverage from a macro that included most of the function logic (on_error!() defined in closure_macro.rs and closure_macro_async.rs coverage tests.)

Instead of the change in PR #84897, if we can actually add spans to all sources that emit some part of the actual covered, expanded function body syntax, I think this will give coverage results everywhere they apply (except perhaps for macros that generate code that splits a statement or terminator implementation across multiple source spans).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions