@@ -315,7 +315,7 @@ Markdown file, the URL given to `--markdown-playground-url` will take precedence
315
315
` --playground-url ` and ` #![doc(html_playground_url = "url")] ` are present when rendering crate docs,
316
316
the attribute will take precedence.
317
317
318
- ### ` --sort-modules-by-appearance ` : control how items on module pages are sorted
318
+ ## ` --sort-modules-by-appearance ` : control how items on module pages are sorted
319
319
320
320
Using this flag looks like this:
321
321
@@ -328,7 +328,7 @@ some consideration for their stability, and names that end in a number). Giving
328
328
` rustdoc ` will disable this sorting and instead make it print the items in the order they appear in
329
329
the source.
330
330
331
- ### ` --show-type-layout ` : add a section to each type's docs describing its memory layout
331
+ ## ` --show-type-layout ` : add a section to each type's docs describing its memory layout
332
332
333
333
* Tracking issue: [ #113248 ] ( https://github.com/rust-lang/rust/issues/113248 )
334
334
@@ -346,7 +346,7 @@ of that type will take in memory.
346
346
Note that most layout information is ** completely unstable** and may even differ
347
347
between compilations.
348
348
349
- ### ` --resource-suffix ` : modifying the name of CSS/JavaScript in crate docs
349
+ ## ` --resource-suffix ` : modifying the name of CSS/JavaScript in crate docs
350
350
351
351
* Tracking issue: [ #54765 ] ( https://github.com/rust-lang/rust/issues/54765 )
352
352
@@ -361,7 +361,7 @@ all these files are linked from every page, changing where they are can be cumbe
361
361
specially cache them. This flag will rename all these files in the output to include the suffix in
362
362
the filename. For example, ` light.css ` would become ` light-suf.css ` with the above command.
363
363
364
- ### ` --extern-html-root-url ` : control how rustdoc links to non-local crates
364
+ ## ` --extern-html-root-url ` : control how rustdoc links to non-local crates
365
365
366
366
Using this flag looks like this:
367
367
@@ -376,7 +376,7 @@ flags to control that behavior. When the `--extern-html-root-url` flag is given
376
376
one of your dependencies, rustdoc use that URL for those docs. Keep in mind that if those docs exist
377
377
in the output directory, those local docs will still override this flag.
378
378
379
- ### ` -Z force-unstable-if-unmarked `
379
+ ## ` -Z force-unstable-if-unmarked `
380
380
381
381
Using this flag looks like this:
382
382
@@ -389,7 +389,7 @@ This is an internal flag intended for the standard library and compiler that app
389
389
allows ` rustdoc ` to be able to generate documentation for the compiler crates and the standard
390
390
library, as an equivalent command-line argument is provided to ` rustc ` when building those crates.
391
391
392
- ### ` --index-page ` : provide a top-level landing page for docs
392
+ ## ` --index-page ` : provide a top-level landing page for docs
393
393
394
394
This feature allows you to generate an index-page with a given markdown file. A good example of it
395
395
is the [ rust documentation index] ( https://doc.rust-lang.org/nightly/index.html ) .
@@ -398,18 +398,18 @@ With this, you'll have a page which you can customize as much as you want at the
398
398
399
399
Using ` index-page ` option enables ` enable-index-page ` option as well.
400
400
401
- ### ` --enable-index-page ` : generate a default index page for docs
401
+ ## ` --enable-index-page ` : generate a default index page for docs
402
402
403
403
This feature allows the generation of a default index-page which lists the generated crates.
404
404
405
- ### ` --nocapture ` : disable output capture for test
405
+ ## ` --nocapture ` : disable output capture for test
406
406
407
407
When this flag is used with ` --test ` , the output (stdout and stderr) of your tests won't be
408
408
captured by rustdoc. Instead, the output will be directed to your terminal,
409
409
as if you had run the test executable manually. This is especially useful
410
410
for debugging your tests!
411
411
412
- ### ` --check ` : only checks the documentation
412
+ ## ` --check ` : only checks the documentation
413
413
414
414
When this flag is supplied, rustdoc will type check and lint your code, but will not generate any
415
415
documentation or run your doctests.
@@ -420,7 +420,7 @@ Using this flag looks like:
420
420
rustdoc -Z unstable-options --check src/lib.rs
421
421
```
422
422
423
- ### ` --static-root-path ` : control how static files are loaded in HTML output
423
+ ## ` --static-root-path ` : control how static files are loaded in HTML output
424
424
425
425
Using this flag looks like this:
426
426
@@ -435,7 +435,7 @@ JavaScript, and font files in a single location, rather than duplicating it once
435
435
files like the search index will still load from the documentation root, but anything that gets
436
436
renamed with ` --resource-suffix ` will load from the given path.
437
437
438
- ### ` --persist-doctests ` : persist doctest executables after running
438
+ ## ` --persist-doctests ` : persist doctest executables after running
439
439
440
440
* Tracking issue: [ #56925 ] ( https://github.com/rust-lang/rust/issues/56925 )
441
441
@@ -449,7 +449,7 @@ This flag allows you to keep doctest executables around after they're compiled o
449
449
Usually, rustdoc will immediately discard a compiled doctest after it's been tested, but
450
450
with this option, you can keep those binaries around for farther testing.
451
451
452
- ### ` --show-coverage ` : calculate the percentage of items with documentation
452
+ ## ` --show-coverage ` : calculate the percentage of items with documentation
453
453
454
454
* Tracking issue: [ #58154 ] ( https://github.com/rust-lang/rust/issues/58154 )
455
455
@@ -500,7 +500,7 @@ Calculating code examples follows these rules:
500
500
* typedef
501
501
2 . If one of the previously listed items has a code example, then it'll be counted.
502
502
503
- #### JSON output
503
+ ### JSON output
504
504
505
505
When using ` --output-format json ` with this option, it will display the coverage information in
506
506
JSON format. For example, here is the JSON for a file with one documented item and one
@@ -522,7 +522,7 @@ Note that the third item is the crate root, which in this case is undocumented.
522
522
If you want the JSON output to be displayed on ` stdout ` instead of having a file generated, you can
523
523
use ` -o - ` .
524
524
525
- ### ` -w ` /` --output-format ` : output format
525
+ ## ` -w ` /` --output-format ` : output format
526
526
527
527
` --output-format json ` emits documentation in the experimental
528
528
[ JSON format] ( https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types/ ) . ` --output-format html ` has no effect,
@@ -542,7 +542,7 @@ It can also be used with `--show-coverage`. Take a look at its
542
542
[ documentation] ( #--show-coverage-calculate-the-percentage-of-items-with-documentation ) for more
543
543
information.
544
544
545
- ### ` --enable-per-target-ignores ` : allow ` ignore-foo ` style filters for doctests
545
+ ## ` --enable-per-target-ignores ` : allow ` ignore-foo ` style filters for doctests
546
546
547
547
* Tracking issue: [ #64245 ] ( https://github.com/rust-lang/rust/issues/64245 )
548
548
@@ -577,7 +577,7 @@ struct Foo;
577
577
In older versions, this will be ignored on all targets, but on newer versions ` ignore-gnu ` will
578
578
override ` ignore ` .
579
579
580
- ### ` --runtool ` , ` --runtool-arg ` : program to run tests with; args to pass to it
580
+ ## ` --runtool ` , ` --runtool-arg ` : program to run tests with; args to pass to it
581
581
582
582
* Tracking issue: [ #64245 ] ( https://github.com/rust-lang/rust/issues/64245 )
583
583
@@ -596,7 +596,7 @@ $ rustdoc src/lib.rs -Z unstable-options --runtool valgrind
596
596
597
597
Another use case would be to run a test inside an emulator, or through a Virtual Machine.
598
598
599
- ### ` --with-examples ` : include examples of uses of items as documentation
599
+ ## ` --with-examples ` : include examples of uses of items as documentation
600
600
601
601
* Tracking issue: [ #88791 ] ( https://github.com/rust-lang/rust/issues/88791 )
602
602
@@ -625,7 +625,7 @@ crate being documented (`foobar`) and a path to output the calls
625
625
To scrape examples from test code, e.g. functions marked ` #[test] ` , then
626
626
add the ` --scrape-tests ` flag.
627
627
628
- ### ` --generate-link-to-definition ` : Generate links on types in source code
628
+ ## ` --generate-link-to-definition ` : Generate links on types in source code
629
629
630
630
* Tracking issue: [ #89095 ] ( https://github.com/rust-lang/rust/issues/89095 )
631
631
@@ -664,3 +664,80 @@ Similar to cargo `build.rustc-wrapper` option, this flag takes a `rustc` wrapper
664
664
The first argument to the program will be the test builder program.
665
665
666
666
This flag can be passed multiple times to nest wrappers.
667
+
668
+ ## Passing arguments to rustc when compiling doctests
669
+
670
+ You can use the ` --doctest-compilation-args ` flag if you want to add options when compiling the
671
+ doctest. For example if you have:
672
+
673
+ ``` rust,no_run
674
+ /// ```
675
+ /// #![deny(warnings)]
676
+ /// #![feature(async_await)]
677
+ ///
678
+ /// let x = 12;
679
+ /// ```
680
+ pub struct Bar;
681
+ ```
682
+
683
+ And you run ` rustdoc --test ` on it, you will get:
684
+
685
+ ``` console
686
+ running 1 test
687
+ test foo.rs - Bar (line 1) ... FAILED
688
+
689
+ failures:
690
+
691
+ ---- foo.rs - Bar (line 1) stdout ----
692
+ error: the feature `async_await` has been stable since 1.39.0 and no longer requires an attribute to enable
693
+ --> foo.rs:2:12
694
+ |
695
+ 3 | #![feature(async_await)]
696
+ | ^^^^^^^^^^^
697
+ |
698
+ note: the lint level is defined here
699
+ --> foo.rs:1:9
700
+ |
701
+ 2 | #![deny(warnings)]
702
+ | ^^^^^^^^
703
+ = note: `#[deny(stable_features)]` implied by `#[deny(warnings)]`
704
+
705
+ error: aborting due to 1 previous error
706
+
707
+ Couldn't compile the test.
708
+
709
+ failures:
710
+ foo.rs - Bar (line 1)
711
+
712
+ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s
713
+ ```
714
+
715
+ But if you can limit the lint level to warning by using ` --doctest_compilation_args=--cap-lints=warn ` :
716
+
717
+ ``` console
718
+ $ rustdoc --test --doctest_compilation_args=--cap-lints=warn file.rs
719
+
720
+ running 1 test
721
+ test tests/rustdoc-ui/doctest/rustflags.rs - Bar (line 5) ... ok
722
+
723
+ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s
724
+ ```
725
+
726
+ The parsing of arguments works as follows: if it encounters a ` " ` or a ` ' ` , it will continue
727
+ until it finds the character unescaped (without a prepending ` \ ` ). If not inside a string, a
728
+ whitespace character will also split arguments. Example:
729
+
730
+ ``` text
731
+ "hello 'a'\" ok" how are 'you today?'
732
+ ```
733
+
734
+ will be split as follows:
735
+
736
+ ``` text
737
+ [
738
+ "hello 'a'\" ok",
739
+ "how",
740
+ "are",
741
+ "you today?",
742
+ ]
743
+ ```
0 commit comments