-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the error-code docs for coverage attributes [E0788]
- Loading branch information
Showing
1 changed file
with
16 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
A `#[coverage]` attribute was applied to something which does not show up | ||
in code coverage, or is too granular to be excluded from the coverage report. | ||
A `#[coverage(off|on)]` attribute was applied in a position where it is not | ||
allowed. | ||
|
||
For now, this attribute can only be applied to function, method, and closure | ||
definitions. In the future, it may be added to statements, blocks, and | ||
expressions, and for the time being, using this attribute in those places | ||
will just emit an `unused_attributes` lint instead of this error. | ||
The coverage attribute can be applied to: | ||
- Function and method declarations that have a body, including trait methods | ||
that have a default implementation. | ||
- Closure expressions, in situations where attributes can be applied to | ||
expressions. | ||
- `impl` blocks (inherent or trait), and modules. | ||
|
||
Example of erroneous code: | ||
|
||
```compile_fail,E0788 | ||
#[coverage(off)] | ||
struct Foo; | ||
#[coverage(on)] | ||
const FOO: Foo = Foo; | ||
unsafe extern "C" { | ||
#[coverage(off)] | ||
fn foreign_fn(); | ||
} | ||
``` | ||
|
||
`#[coverage(off)]` tells the compiler to not generate coverage instrumentation | ||
for a piece of code when the `-C instrument-coverage` flag is passed. Things | ||
like structs and consts are not coverable code, and thus cannot do anything | ||
with this attribute. | ||
|
||
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. | ||
The coverage attribute is a hint to the `-C instrument-coverage` flag to | ||
instrument or not instrument the corresponding function or enclosed functions. | ||
The precise effect of applying a coverage attribute is not guaranteed and may | ||
change in future compiler versions. |