Skip to content

Commit

Permalink
Rollup merge of #61990 - llogiq:questionmark-test, r=QuietMisdreavus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Centril authored Jul 7, 2019
2 parents b0bd5f2 + ee05fc8 commit 719eeb2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 719eeb2

Please sign in to comment.