Skip to content

Commit

Permalink
Rollup merge of rust-lang#62663 - llogiq:more-questionmark-docs, r=Gu…
Browse files Browse the repository at this point in the history
…illaumeGomez

More questionmarks in doctests

This removes the other `unwrap`s in the macro doctests, replacing them with `?`. For now, we need to specify the main function including the return type, we can get rid of that once the return type suggestion for `fn main() { .. }` works correctly.

r? @QuietMisdreavus
  • Loading branch information
Centril authored Aug 2, 2019
2 parents 435236b + cbac781 commit 6b951c2
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,15 @@ macro_rules! r#try {
/// use std::fmt::Write as FmtWrite;
/// use std::io::Write as IoWrite;
///
/// let mut s = String::new();
/// let mut v = Vec::new();
/// write!(&mut s, "{} {}", "abc", 123).unwrap(); // uses fmt::Write::write_fmt
/// write!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt
/// assert_eq!(v, b"s = \"abc 123\"");
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let mut s = String::new();
/// let mut v = Vec::new();
///
/// write!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
/// write!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
/// assert_eq!(v, b"s = \"abc 123\"");
/// Ok(())
/// }
/// ```
///
/// Note: This macro can be used in `no_std` setups as well.
Expand Down Expand Up @@ -399,14 +403,17 @@ macro_rules! write {
/// # Examples
///
/// ```
/// use std::io::Write;
/// use std::io::{Write, Result};
///
/// let mut w = Vec::new();
/// writeln!(&mut w).unwrap();
/// writeln!(&mut w, "test").unwrap();
/// writeln!(&mut w, "formatted {}", "arguments").unwrap();
/// fn main() -> Result<()> {
/// let mut w = Vec::new();
/// writeln!(&mut w)?;
/// writeln!(&mut w, "test")?;
/// writeln!(&mut w, "formatted {}", "arguments")?;
///
/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
/// Ok(())
/// }
/// ```
///
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
Expand All @@ -417,11 +424,15 @@ macro_rules! write {
/// use std::fmt::Write as FmtWrite;
/// use std::io::Write as IoWrite;
///
/// let mut s = String::new();
/// let mut v = Vec::new();
/// writeln!(&mut s, "{} {}", "abc", 123).unwrap(); // uses fmt::Write::write_fmt
/// writeln!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt
/// assert_eq!(v, b"s = \"abc 123\\n\"\n");
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let mut s = String::new();
/// let mut v = Vec::new();
///
/// writeln!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
/// writeln!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
/// assert_eq!(v, b"s = \"abc 123\\n\"\n");
/// Ok(())
/// }
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit 6b951c2

Please sign in to comment.