Rewrite the error-code docs for coverage attributes [E0788]

This commit is contained in:
Zalathar 2024-12-25 15:18:01 +11:00
parent 3996209398
commit db02b1d3e9

View File

@ -1,26 +1,24 @@
A `#[coverage]` attribute was applied to something which does not show up A `#[coverage(off|on)]` attribute was found in a position where it is not
in code coverage, or is too granular to be excluded from the coverage report. allowed.
For now, this attribute can only be applied to function, method, and closure Coverage attributes can be applied to:
definitions. In the future, it may be added to statements, blocks, and - Function and method declarations that have a body, including trait methods
expressions, and for the time being, using this attribute in those places that have a default implementation.
will just emit an `unused_attributes` lint instead of this error. - Closure expressions, in situations where attributes can be applied to
expressions.
- `impl` blocks (inherent or trait), and modules.
Example of erroneous code: Example of erroneous code:
```compile_fail,E0788 ```compile_fail,E0788
#[coverage(off)] unsafe extern "C" {
struct Foo; #[coverage(off)]
fn foreign_fn();
#[coverage(on)] }
const FOO: Foo = Foo;
``` ```
`#[coverage(off)]` tells the compiler to not generate coverage instrumentation When using the `-C instrument-coverage` flag, coverage attributes act as a
for a piece of code when the `-C instrument-coverage` flag is passed. Things hint to the compiler that it should instrument or not instrument the
like structs and consts are not coverable code, and thus cannot do anything corresponding function or enclosed functions. The precise effect of applying
with this attribute. a coverage attribute is not guaranteed and may change in future compiler
versions.
If you wish to apply this attribute to all methods in an impl or module,
manually annotate each method; it is not possible to annotate the entire impl
with a `#[coverage]` attribute.