Skip to content

Commit db02b1d

Browse files
committed
Rewrite the error-code docs for coverage attributes [E0788]
1 parent 3996209 commit db02b1d

File tree

1 file changed

+17
-19
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+17
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
A `#[coverage]` attribute was applied to something which does not show up
2-
in code coverage, or is too granular to be excluded from the coverage report.
1+
A `#[coverage(off|on)]` attribute was found in a position where it is not
2+
allowed.
33

4-
For now, this attribute can only be applied to function, method, and closure
5-
definitions. In the future, it may be added to statements, blocks, and
6-
expressions, and for the time being, using this attribute in those places
7-
will just emit an `unused_attributes` lint instead of this error.
4+
Coverage attributes can be applied to:
5+
- Function and method declarations that have a body, including trait methods
6+
that have a default implementation.
7+
- Closure expressions, in situations where attributes can be applied to
8+
expressions.
9+
- `impl` blocks (inherent or trait), and modules.
810

911
Example of erroneous code:
1012

1113
```compile_fail,E0788
12-
#[coverage(off)]
13-
struct Foo;
14-
15-
#[coverage(on)]
16-
const FOO: Foo = Foo;
14+
unsafe extern "C" {
15+
#[coverage(off)]
16+
fn foreign_fn();
17+
}
1718
```
1819

19-
`#[coverage(off)]` tells the compiler to not generate coverage instrumentation
20-
for a piece of code when the `-C instrument-coverage` flag is passed. Things
21-
like structs and consts are not coverable code, and thus cannot do anything
22-
with this attribute.
23-
24-
If you wish to apply this attribute to all methods in an impl or module,
25-
manually annotate each method; it is not possible to annotate the entire impl
26-
with a `#[coverage]` attribute.
20+
When using the `-C instrument-coverage` flag, coverage attributes act as a
21+
hint to the compiler that it should instrument or not instrument the
22+
corresponding function or enclosed functions. The precise effect of applying
23+
a coverage attribute is not guaranteed and may change in future compiler
24+
versions.

0 commit comments

Comments
 (0)