diff options
| author | Andre Bogus <bogusandre@gmail.com> | 2018-12-03 18:16:20 +0100 |
|---|---|---|
| committer | Andre Bogus <bogusandre@gmail.com> | 2019-02-17 16:42:49 +0100 |
| commit | dad211ef9fdcef5328813a1907d323303f09fc6c (patch) | |
| tree | ccb9785522c11eb483b9bf6c5addeacdb1ec8c31 /src/doc/rustdoc | |
| parent | 007115746c6d0234742719dd67efba054abe97ce (diff) | |
| download | rust-dad211ef9fdcef5328813a1907d323303f09fc6c.tar.gz rust-dad211ef9fdcef5328813a1907d323303f09fc6c.zip | |
Modify doctest's auto-`fn main()` to allow `Result`s
This lets the default `fn main()` unwrap any `Result`s, which allows the use of `?` in most tests without adding it manually.
Diffstat (limited to 'src/doc/rustdoc')
| -rw-r--r-- | src/doc/rustdoc/src/documentation-tests.md | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index dd8dcb7ff9b..020ffe4e1df 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -236,6 +236,23 @@ appears to the reader as the initial idea but works with doc tests: /// ``` ``` +As of version 1.34.0, one can also omit the `fn main()`, but you will have to +disambiguate the error type: + +```ignore +/// ``` +/// use std::io; +/// let mut input = String::new(); +/// io::stdin().read_line(&mut input)?; +/// # Ok::<(), io:Error>(()) +/// ``` +``` + +This is an unfortunate consequence of the `?` operator adding an implicit +conversion, so type inference fails because the type is not unique. Please note +that you must write the `(())` in one sequence without intermediate whitespace +so that rustdoc understands you want an implicit `Result`-returning function. + ## Documenting macros Here’s an example of documenting a macro: |
