about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcore/fmt/mod.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index fdebf785b31..d16f8b5ac9a 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -436,12 +436,17 @@ impl<'a> Arguments<'a> {
     /// #![feature(fmt_as_str)]
     ///
     /// assert_eq!(format_args!("hello").as_str(), Some("hello"));
+    /// assert_eq!(format_args!("").as_str(), Some(""));
     /// assert_eq!(format_args!("{}", 1).as_str(), None);
     /// ```
     #[unstable(feature = "fmt_as_str", issue = "none")]
     #[inline]
     pub fn as_str(&self) -> Option<&'a str> {
-        if self.args.is_empty() && self.pieces.len() == 1 { Some(self.pieces[0]) } else { None }
+        match (self.pieces, self.args) {
+            ([], []) => Some(""),
+            ([s], []) => Some(s),
+            _ => None,
+        }
     }
 }