@@ -311,7 +311,7 @@ Markdown file, the URL given to `--markdown-playground-url` will take precedence
311311` --playground-url ` and ` #![doc(html_playground_url = "url")] ` are present when rendering crate docs,
312312the attribute will take precedence.
313313
314- ### ` --sort-modules-by-appearance ` : control how items on module pages are sorted
314+ ## ` --sort-modules-by-appearance ` : control how items on module pages are sorted
315315
316316Using this flag looks like this:
317317
@@ -324,7 +324,7 @@ some consideration for their stability, and names that end in a number). Giving
324324` rustdoc ` will disable this sorting and instead make it print the items in the order they appear in
325325the source.
326326
327- ### ` --show-type-layout ` : add a section to each type's docs describing its memory layout
327+ ## ` --show-type-layout ` : add a section to each type's docs describing its memory layout
328328
329329* Tracking issue: [ #113248 ] ( https://github.com/rust-lang/rust/issues/113248 )
330330
@@ -342,7 +342,7 @@ of that type will take in memory.
342342Note that most layout information is ** completely unstable** and may even differ
343343between compilations.
344344
345- ### ` --resource-suffix ` : modifying the name of CSS/JavaScript in crate docs
345+ ## ` --resource-suffix ` : modifying the name of CSS/JavaScript in crate docs
346346
347347 * Tracking issue: [ #54765 ] ( https://github.com/rust-lang/rust/issues/54765 )
348348
@@ -357,7 +357,7 @@ all these files are linked from every page, changing where they are can be cumbe
357357specially cache them. This flag will rename all these files in the output to include the suffix in
358358the filename. For example, ` light.css ` would become ` light-suf.css ` with the above command.
359359
360- ### ` --extern-html-root-url ` : control how rustdoc links to non-local crates
360+ ## ` --extern-html-root-url ` : control how rustdoc links to non-local crates
361361
362362Using this flag looks like this:
363363
@@ -372,7 +372,7 @@ flags to control that behavior. When the `--extern-html-root-url` flag is given
372372one of your dependencies, rustdoc use that URL for those docs. Keep in mind that if those docs exist
373373in the output directory, those local docs will still override this flag.
374374
375- ### ` -Z force-unstable-if-unmarked `
375+ ## ` -Z force-unstable-if-unmarked `
376376
377377Using this flag looks like this:
378378
@@ -385,7 +385,7 @@ This is an internal flag intended for the standard library and compiler that app
385385allows ` rustdoc ` to be able to generate documentation for the compiler crates and the standard
386386library, as an equivalent command-line argument is provided to ` rustc ` when building those crates.
387387
388- ### ` --index-page ` : provide a top-level landing page for docs
388+ ## ` --index-page ` : provide a top-level landing page for docs
389389
390390This feature allows you to generate an index-page with a given markdown file. A good example of it
391391is the [ rust documentation index] ( https://doc.rust-lang.org/nightly/index.html ) .
@@ -394,18 +394,18 @@ With this, you'll have a page which you can customize as much as you want at the
394394
395395Using ` index-page ` option enables ` enable-index-page ` option as well.
396396
397- ### ` --enable-index-page ` : generate a default index page for docs
397+ ## ` --enable-index-page ` : generate a default index page for docs
398398
399399This feature allows the generation of a default index-page which lists the generated crates.
400400
401- ### ` --nocapture ` : disable output capture for test
401+ ## ` --nocapture ` : disable output capture for test
402402
403403When this flag is used with ` --test ` , the output (stdout and stderr) of your tests won't be
404404captured by rustdoc. Instead, the output will be directed to your terminal,
405405as if you had run the test executable manually. This is especially useful
406406for debugging your tests!
407407
408- ### ` --check ` : only checks the documentation
408+ ## ` --check ` : only checks the documentation
409409
410410When this flag is supplied, rustdoc will type check and lint your code, but will not generate any
411411documentation or run your doctests.
@@ -416,7 +416,7 @@ Using this flag looks like:
416416rustdoc -Z unstable-options --check src/lib.rs
417417```
418418
419- ### ` --static-root-path ` : control how static files are loaded in HTML output
419+ ## ` --static-root-path ` : control how static files are loaded in HTML output
420420
421421Using this flag looks like this:
422422
@@ -431,7 +431,7 @@ JavaScript, and font files in a single location, rather than duplicating it once
431431files like the search index will still load from the documentation root, but anything that gets
432432renamed with ` --resource-suffix ` will load from the given path.
433433
434- ### ` --persist-doctests ` : persist doctest executables after running
434+ ## ` --persist-doctests ` : persist doctest executables after running
435435
436436 * Tracking issue: [ #56925 ] ( https://github.com/rust-lang/rust/issues/56925 )
437437
@@ -445,7 +445,7 @@ This flag allows you to keep doctest executables around after they're compiled o
445445Usually, rustdoc will immediately discard a compiled doctest after it's been tested, but
446446with this option, you can keep those binaries around for farther testing.
447447
448- ### ` --show-coverage ` : calculate the percentage of items with documentation
448+ ## ` --show-coverage ` : calculate the percentage of items with documentation
449449
450450 * Tracking issue: [ #58154 ] ( https://github.com/rust-lang/rust/issues/58154 )
451451
@@ -496,7 +496,7 @@ Calculating code examples follows these rules:
496496 * typedef
4974972 . If one of the previously listed items has a code example, then it'll be counted.
498498
499- #### JSON output
499+ ### JSON output
500500
501501When using ` --output-format json ` with this option, it will display the coverage information in
502502JSON format. For example, here is the JSON for a file with one documented item and one
@@ -518,7 +518,7 @@ Note that the third item is the crate root, which in this case is undocumented.
518518If you want the JSON output to be displayed on ` stdout ` instead of having a file generated, you can
519519use ` -o - ` .
520520
521- ### ` -w ` /` --output-format ` : output format
521+ ## ` -w ` /` --output-format ` : output format
522522
523523` --output-format json ` emits documentation in the experimental
524524[ JSON format] ( https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types/ ) . ` --output-format html ` has no effect,
@@ -538,7 +538,7 @@ It can also be used with `--show-coverage`. Take a look at its
538538[ documentation] ( #--show-coverage-calculate-the-percentage-of-items-with-documentation ) for more
539539information.
540540
541- ### ` --enable-per-target-ignores ` : allow ` ignore-foo ` style filters for doctests
541+ ## ` --enable-per-target-ignores ` : allow ` ignore-foo ` style filters for doctests
542542
543543 * Tracking issue: [ #64245 ] ( https://github.com/rust-lang/rust/issues/64245 )
544544
@@ -573,7 +573,7 @@ struct Foo;
573573In older versions, this will be ignored on all targets, but on newer versions ` ignore-gnu ` will
574574override ` ignore ` .
575575
576- ### ` --runtool ` , ` --runtool-arg ` : program to run tests with; args to pass to it
576+ ## ` --runtool ` , ` --runtool-arg ` : program to run tests with; args to pass to it
577577
578578 * Tracking issue: [ #64245 ] ( https://github.com/rust-lang/rust/issues/64245 )
579579
@@ -592,7 +592,7 @@ $ rustdoc src/lib.rs -Z unstable-options --runtool valgrind
592592
593593Another use case would be to run a test inside an emulator, or through a Virtual Machine.
594594
595- ### ` --with-examples ` : include examples of uses of items as documentation
595+ ## ` --with-examples ` : include examples of uses of items as documentation
596596
597597 * Tracking issue: [ #88791 ] ( https://github.com/rust-lang/rust/issues/88791 )
598598
@@ -621,9 +621,67 @@ crate being documented (`foobar`) and a path to output the calls
621621To scrape examples from test code, e.g. functions marked ` #[test] ` , then
622622add the ` --scrape-tests ` flag.
623623
624- ### ` --generate-link-to-definition ` : Generate links on types in source code
624+ ## ` --generate-link-to-definition ` : Generate links on types in source code
625625
626626 * Tracking issue: [ #89095 ] ( https://github.com/rust-lang/rust/issues/89095 )
627627
628628This flag enables the generation of links in the source code pages which allow the reader
629629to jump to a type definition.
630+
631+ ## Passing arguments to rustc when compiling doctests
632+
633+ You can use the ` --doctest-compilation-args ` option if you want to add options when compiling the
634+ doctest. For example if you have:
635+
636+ ``` rust,no_run
637+ /// ```
638+ /// #![deny(warnings)]
639+ /// #![feature(async_await)]
640+ ///
641+ /// let x = 12;
642+ /// ```
643+ pub struct Bar;
644+ ```
645+
646+ And you run ` rustdoc --test ` on it, you will get:
647+
648+ ``` console
649+ running 1 test
650+ test foo.rs - Bar (line 1) ... FAILED
651+
652+ failures:
653+
654+ ---- foo.rs - Bar (line 1) stdout ----
655+ error: the feature `async_await` has been stable since 1.39.0 and no longer requires an attribute to enable
656+ --> foo.rs:2:12
657+ |
658+ 3 | #![feature(async_await)]
659+ | ^^^^^^^^^^^
660+ |
661+ note: the lint level is defined here
662+ --> foo.rs:1:9
663+ |
664+ 2 | #![deny(warnings)]
665+ | ^^^^^^^^
666+ = note: `#[deny(stable_features)]` implied by `#[deny(warnings)]`
667+
668+ error: aborting due to 1 previous error
669+
670+ Couldn't compile the test.
671+
672+ failures:
673+ foo.rs - Bar (line 1)
674+
675+ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s
676+ ```
677+
678+ But if you can limit the lint level to warning by using ` --doctest_compilation_args=--cap-lints=warn ` :
679+
680+ ``` console
681+ $ rustdoc --test --doctest_compilation_args=--cap-lints=warn file.rs
682+
683+ running 1 test
684+ test tests/rustdoc-ui/doctest/rustflags.rs - Bar (line 5) ... ok
685+
686+ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s
687+ ```
0 commit comments