Skip to content

Commit 3ff8b84

Browse files
clarfontheyehuss
authored andcommitted
Mention coverage attribute
1 parent 3436fc7 commit 3ff8b84

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- [Limits](attributes/limits.md)
4646
- [Type System](attributes/type_system.md)
4747
- [Debugger](attributes/debugger.md)
48+
- [Coverage instrumentation](attributes/coverage-instrumentation.md)
4849

4950
- [Statements and expressions](statements-and-expressions.md)
5051
- [Statements](statements.md)

src/attributes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ The following is an index of all built-in attributes.
328328
- Debugger
329329
- [`debugger_visualizer`] --- Embeds a file that specifies debugger output for a type.
330330
- [`collapse_debuginfo`] --- Controls how macro invocations are encoded in debuginfo.
331+
- Coverage Instrumentation
332+
- [`coverage`] --- Controls how code coverage is instrumented
331333

332334
[Doc comments]: comments.md#doc-comments
333335
[ECMA-334]: https://www.ecma-international.org/publications-and-standards/standards/ecma-334/
@@ -347,6 +349,7 @@ The following is an index of all built-in attributes.
347349
[`cfg`]: conditional-compilation.md#the-cfg-attribute
348350
[`cold`]: attributes/codegen.md#the-cold-attribute
349351
[`collapse_debuginfo`]: attributes/debugger.md#the-collapse_debuginfo-attribute
352+
[`coverage`]: attributes/coverage-instrumentation.md#the-coverage-attribute
350353
[`crate_name`]: crates-and-source-files.md#the-crate_name-attribute
351354
[`crate_type`]: linkage.md
352355
[`debugger_visualizer`]: attributes/debugger.md#the-debugger_visualizer-attribute
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Coverage instrumentation attributes
2+
3+
The following [attributes] are used for controlling coverage instrumentation,
4+
which can be enabled with the `-C instrument-coverage` compiler flag.
5+
6+
### The `coverage` attribute
7+
8+
The *`coverage` [attribute]* indicates whether a function should instrument code
9+
coverage at all and show up in code coverage reports. It can only be controlled
10+
at the function level, but it can be applied to modules, `impl` blocks, or
11+
anything that can contain functions.
12+
13+
There are two ways to use the coverage attribute:
14+
15+
* `#[coverage(off)]` indicates that all functions within an item, recursively,
16+
should not be instrumented, unless specified by another attribute.
17+
* `#[coverage(on)]` (the default) indicates that all functions within an item,
18+
recursively, *should* be instrumented, unless specified by another attribute.
19+
20+
More-specific attributes always take priority over less-specific ones, e.g.
21+
if a crate is marked `#![coverage(off)]`, then functions inside that crate
22+
marked `#[coverage(on)]` will still have coverage.
23+
24+
[attribute]: ../attributes.md
25+
[attributes]: ../attributes.md

0 commit comments

Comments
 (0)