@@ -16,8 +16,8 @@ The basic idea is this:
1616The triple backticks start and end code blocks. If this were in a file named ` foo.rs ` ,
1717running ` rustdoc --test foo.rs ` will extract this example, and then run it as a test.
1818
19- Please note that by default, if no language is set for the block code, ` rustdoc `
20- assumes it is ` Rust ` code. So the following:
19+ Please note that by default, if no language is set for the block code, rustdoc
20+ assumes it is Rust code. So the following:
2121
2222`````` markdown
2323```rust
@@ -44,7 +44,6 @@ the `assert!` family of macros works the same as other Rust code:
4444
4545``` rust
4646let foo = " foo" ;
47-
4847assert_eq! (foo , " foo" );
4948```
5049
@@ -55,8 +54,9 @@ the code panics and the doctest fails.
5554
5655In the example above, you'll note something strange: there's no ` main `
5756function! Forcing you to write ` main ` for every example, no matter how small,
58- adds friction. So ` rustdoc ` processes your examples slightly before
59- running them. Here's the full algorithm rustdoc uses to preprocess examples:
57+ adds friction and clutters the output. So ` rustdoc ` processes your examples
58+ slightly before running them. Here's the full algorithm ` rustdoc ` uses to
59+ preprocess examples:
6060
61611 . Some common ` allow ` attributes are inserted, including
6262 ` unused_variables ` , ` unused_assignments ` , ` unused_mut ` ,
@@ -78,10 +78,12 @@ Sometimes, you need some setup code, or other things that would distract
7878from your example, but are important to make the tests work. Consider
7979an example block that looks like this:
8080
81- ``` text
81+ ``` ignore
82+ /// ```
8283/// /// Some documentation.
8384/// # fn foo() {} // this function will be hidden
8485/// println!("Hello, World!");
86+ /// ```
8587```
8688
8789It will render like this:
@@ -251,7 +253,7 @@ disambiguate the error type:
251253This is an unfortunate consequence of the ` ? ` operator adding an implicit
252254conversion, so type inference fails because the type is not unique. Please note
253255that you must write the ` (()) ` in one sequence without intermediate whitespace
254- so that rustdoc understands you want an implicit ` Result ` -returning function.
256+ so that ` rustdoc ` understands you want an implicit ` Result ` -returning function.
255257
256258## Documenting macros
257259
@@ -359,7 +361,7 @@ the code with the 2015 edition.
359361## Syntax reference
360362
361363The * exact* syntax for code blocks, including the edge cases, can be found
362- in the [ Fenced Code Blocks] ( https://spec.commonmark.org/0.28 /#fenced-code-blocks )
364+ in the [ Fenced Code Blocks] ( https://spec.commonmark.org/0.29 /#fenced-code-blocks )
363365section of the CommonMark specification.
364366
365367Rustdoc also accepts * indented* code blocks as an alternative to fenced
@@ -372,7 +374,7 @@ can indent each line by four or more spaces.
372374``````
373375
374376These, too, are documented in the CommonMark specification, in the
375- [ Indented Code Blocks] ( https://spec.commonmark.org/0.28 /#indented-code-blocks )
377+ [ Indented Code Blocks] ( https://spec.commonmark.org/0.29 /#indented-code-blocks )
376378section.
377379
378380However, it's preferable to use fenced code blocks over indented code blocks.
@@ -388,7 +390,7 @@ documentation. To this end, Rustdoc allows you to have certain items only appear
388390collecting doctests, so you can utilize doctest functionality without forcing the test to appear in
389391docs, or to find an arbitrary private item to include it on.
390392
391- When compiling a crate for use in doctests (with ` --test ` option), rustdoc will set ` cfg(doctest) ` .
393+ When compiling a crate for use in doctests (with ` --test ` option), ` rustdoc ` will set ` #[ cfg(doctest)] ` .
392394Note that they will still link against only the public items of your crate; if you need to test
393395private items, you need to write a unit test.
394396
@@ -407,18 +409,18 @@ pub struct MyStructOnlyTakesUsize;
407409```
408410
409411Note that the struct ` MyStructOnlyTakesUsize ` here isn't actually part of your public crate
410- API. The use of ` #[cfg(doctest)] ` makes sure that this struct only exists while rustdoc is
412+ API. The use of ` #[cfg(doctest)] ` makes sure that this struct only exists while ` rustdoc ` is
411413collecting doctests. This means that its doctest is executed when ` --test ` is passed to rustdoc,
412414but is hidden from the public documentation.
413415
414- Another possible use of ` cfg(doctest) ` is to test doctests that are included in your README file
416+ Another possible use of ` #[ cfg(doctest)] ` is to test doctests that are included in your README file
415417without including it in your main documentation. For example, you could write this into your
416418` lib.rs ` to test your README as part of your doctests:
417419
418420``` rust,ignore
419421#![feature(external_doc)]
420422
421- #[doc(include= "../README.md")]
423+ #[doc(include = "../README.md")]
422424#[cfg(doctest)]
423425pub struct ReadmeDoctests;
424426```
0 commit comments