Rollup merge of #62663 - llogiq:more-questionmark-docs, r=GuillaumeGomez

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
This commit is contained in:
Mazdak Farrokhzad 2019-08-02 12:14:14 +02:00 committed by GitHub
commit 6b951c2950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -353,11 +353,15 @@ macro_rules! r#try {
/// use std::fmt::Write as FmtWrite;
/// use std::io::Write as IoWrite;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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
///
/// 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.
@ -399,14 +403,17 @@ macro_rules! write {
/// # Examples
///
/// ```
/// use std::io::Write;
/// use std::io::{Write, Result};
///
/// fn main() -> Result<()> {
/// let mut w = Vec::new();
/// writeln!(&mut w).unwrap();
/// writeln!(&mut w, "test").unwrap();
/// writeln!(&mut w, "formatted {}", "arguments").unwrap();
/// writeln!(&mut w)?;
/// writeln!(&mut w, "test")?;
/// writeln!(&mut w, "formatted {}", "arguments")?;
///
/// 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
@ -417,11 +424,15 @@ macro_rules! write {
/// use std::fmt::Write as FmtWrite;
/// use std::io::Write as IoWrite;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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
///
/// 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")]