Skip to content

Commit 530eaa8

Browse files
Clean up mess for --show-coverage documentation
1 parent 41301c3 commit 530eaa8

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

src/doc/rustdoc/src/unstable-features.md

+33-40
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ Using this flag looks like this:
348348
$ rustdoc src/lib.rs -Z unstable-options --show-coverage
349349
```
350350

351+
It generates something like this:
352+
353+
```bash
354+
+-------------------------------------+------------+------------+------------+------------+
355+
| File | Documented | Percentage | Examples | Percentage |
356+
+-------------------------------------+------------+------------+------------+------------+
357+
| lib.rs | 4 | 100.0% | 1 | 25.0% |
358+
+-------------------------------------+------------+------------+------------+------------+
359+
| Total | 4 | 100.0% | 1 | 25.0% |
360+
+-------------------------------------+------------+------------+------------+------------+
361+
```
362+
351363
If you want to determine how many items in your crate are documented, pass this flag to rustdoc.
352364
When it receives this flag, it will count the public items in your crate that have documentation,
353365
and print out the counts and a percentage instead of generating docs.
@@ -367,17 +379,25 @@ Some methodology notes about what rustdoc counts in this metric:
367379
Public items that are not documented can be seen with the built-in `missing_docs` lint. Private
368380
items that are not documented can be seen with Clippy's `missing_docs_in_private_items` lint.
369381

370-
### `-w`/`--output-format`: output format
382+
Calculating code examples follows these rules:
371383

372-
When using
373-
[`--show-coverage`](https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#--show-coverage-get-statistics-about-code-documentation-coverage),
374-
passing `--output-format json` will display the coverage information in JSON format. For example,
375-
here is the JSON for a file with one documented item and one undocumented item:
384+
1. These items aren't accounted by default:
385+
* struct/union field
386+
* enum variant
387+
* constant
388+
* static
389+
* typedef
390+
2. If one of the previously listed items has a code example, then it'll be counted.
391+
392+
#### JSON output
393+
394+
When using `--output-format json` with this option, it will display the coverage information in
395+
JSON format. For example, here is the JSON for a file with one documented item and one
396+
undocumented item:
376397

377398
```rust
378399
/// This item has documentation
379400
pub fn foo() {}
380-
381401
pub fn no_documentation() {}
382402
```
383403

@@ -387,10 +407,16 @@ pub fn no_documentation() {}
387407

388408
Note that the third item is the crate root, which in this case is undocumented.
389409

390-
When not using `--show-coverage`, `--output-format json` emits documentation in the experimental
410+
### `-w`/`--output-format`: output format
411+
412+
`--output-format json` emits documentation in the experimental
391413
[JSON format](https://github.com/rust-lang/rfcs/pull/2963). `--output-format html` has no effect,
392414
and is also accepted on stable toolchains.
393415

416+
It can also be used with `--show-coverage`. Take a look at its
417+
[documentation](#--show-coverage-get-statistics-about-code-documentation-coverage) for more
418+
information.
419+
394420
### `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests
395421

396422
Using this flag looks like this:
@@ -441,39 +467,6 @@ $ rustdoc src/lib.rs -Z unstable-options --runtool valgrind
441467

442468
Another use case would be to run a test inside an emulator, or through a Virtual Machine.
443469

444-
### `--show-coverage`: get statistics about code documentation coverage
445-
446-
This option allows you to get a nice overview over your code documentation coverage, including both
447-
doc-comments and code examples in the doc-comments. Example:
448-
449-
```bash
450-
$ rustdoc src/lib.rs -Z unstable-options --show-coverage
451-
+-------------------------------------+------------+------------+------------+------------+
452-
| File | Documented | Percentage | Examples | Percentage |
453-
+-------------------------------------+------------+------------+------------+------------+
454-
| lib.rs | 4 | 100.0% | 1 | 25.0% |
455-
+-------------------------------------+------------+------------+------------+------------+
456-
| Total | 4 | 100.0% | 1 | 25.0% |
457-
+-------------------------------------+------------+------------+------------+------------+
458-
```
459-
460-
You can also use this option with the `--output-format` one:
461-
462-
```bash
463-
$ rustdoc src/lib.rs -Z unstable-options --show-coverage --output-format json
464-
{"lib.rs":{"total":4,"with_docs":4,"total_examples":4,"with_examples":1}}
465-
```
466-
467-
Calculating code examples follows these rules:
468-
469-
1. These items aren't accounted by default:
470-
* struct/union field
471-
* enum variant
472-
* constant
473-
* static
474-
* typedef
475-
2. If one of the previously listed items has a code example, then it'll be counted.
476-
477470
### `--with-examples`: include examples of uses of items as documentation
478471

479472
This option, combined with `--scrape-examples-target-crate` and

0 commit comments

Comments
 (0)