Skip to content

Commit cbac781

Browse files
committed
More questionmarks in doctests
1 parent ec30876 commit cbac781

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/libcore/macros.rs

+27-16
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,15 @@ macro_rules! r#try {
353353
/// use std::fmt::Write as FmtWrite;
354354
/// use std::io::Write as IoWrite;
355355
///
356-
/// let mut s = String::new();
357-
/// let mut v = Vec::new();
358-
/// write!(&mut s, "{} {}", "abc", 123).unwrap(); // uses fmt::Write::write_fmt
359-
/// write!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt
360-
/// assert_eq!(v, b"s = \"abc 123\"");
356+
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
357+
/// let mut s = String::new();
358+
/// let mut v = Vec::new();
359+
///
360+
/// write!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
361+
/// write!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
362+
/// assert_eq!(v, b"s = \"abc 123\"");
363+
/// Ok(())
364+
/// }
361365
/// ```
362366
///
363367
/// Note: This macro can be used in `no_std` setups as well.
@@ -399,14 +403,17 @@ macro_rules! write {
399403
/// # Examples
400404
///
401405
/// ```
402-
/// use std::io::Write;
406+
/// use std::io::{Write, Result};
403407
///
404-
/// let mut w = Vec::new();
405-
/// writeln!(&mut w).unwrap();
406-
/// writeln!(&mut w, "test").unwrap();
407-
/// writeln!(&mut w, "formatted {}", "arguments").unwrap();
408+
/// fn main() -> Result<()> {
409+
/// let mut w = Vec::new();
410+
/// writeln!(&mut w)?;
411+
/// writeln!(&mut w, "test")?;
412+
/// writeln!(&mut w, "formatted {}", "arguments")?;
408413
///
409-
/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
414+
/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
415+
/// Ok(())
416+
/// }
410417
/// ```
411418
///
412419
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
@@ -417,11 +424,15 @@ macro_rules! write {
417424
/// use std::fmt::Write as FmtWrite;
418425
/// use std::io::Write as IoWrite;
419426
///
420-
/// let mut s = String::new();
421-
/// let mut v = Vec::new();
422-
/// writeln!(&mut s, "{} {}", "abc", 123).unwrap(); // uses fmt::Write::write_fmt
423-
/// writeln!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt
424-
/// assert_eq!(v, b"s = \"abc 123\\n\"\n");
427+
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
428+
/// let mut s = String::new();
429+
/// let mut v = Vec::new();
430+
///
431+
/// writeln!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
432+
/// writeln!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
433+
/// assert_eq!(v, b"s = \"abc 123\\n\"\n");
434+
/// Ok(())
435+
/// }
425436
/// ```
426437
#[macro_export]
427438
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)