about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-07 05:11:51 +0200
committerGitHub <noreply@github.com>2019-07-07 05:11:51 +0200
commit719eeb260b5c870fd6bee24e5e04fcf2203e8a0e (patch)
treeaf1cf9569a8488ab1f2c8e03d6053439eb6cee4e /src
parentb0bd5f236d9bea38b8c9048f379fec179b09984c (diff)
parentee05fc8104e5e2fecf8f67fc3d4259d5d576a20f (diff)
downloadrust-719eeb260b5c870fd6bee24e5e04fcf2203e8a0e.tar.gz
rust-719eeb260b5c870fd6bee24e5e04fcf2203e8a0e.zip
Rollup merge of #61990 - llogiq:questionmark-test, r=QuietMisdreavus
First question mark in doctest

We have had `?` for `Result`s in doctests for some time, but so far haven't used them in doctests. With this PR, I want to start the de-`unwrap`ping of doctests – and the discussion on where to do so.

There is one downside, which is that the code can no longer be copied into a plain `main()` method, on the other hand, there should be a workable error if one does this.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/macros.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index 33ffd84e521..58ea0207c56 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -335,11 +335,14 @@ macro_rules! r#try {
 /// ```
 /// use std::io::Write;
 ///
-/// let mut w = Vec::new();
-/// write!(&mut w, "test").unwrap();
-/// write!(&mut w, "formatted {}", "arguments").unwrap();
+/// fn main() -> std::io::Result<()> {
+///     let mut w = Vec::new();
+///     write!(&mut w, "test")?;
+///     write!(&mut w, "formatted {}", "arguments")?;
 ///
-/// assert_eq!(w, b"testformatted arguments");
+///     assert_eq!(w, b"testformatted arguments");
+///     Ok(())
+/// }
 /// ```
 ///
 /// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects