summary refs log tree commit diff
path: root/src/libcollections/string.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-06 15:22:24 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-06 15:22:24 -0800
commit5c3ddcb15dc8b40fa780a38fd7494b9b5b991d09 (patch)
tree9ad6d0c242e45a785dae4b22f1e4ddd9d4f9c55a /src/libcollections/string.rs
parent5f27b500800fc2720c5caa4a0cd5dcc46c0b911f (diff)
parent44440e5c18a1dbcc9685866ffffe00c508929079 (diff)
downloadrust-5c3ddcb15dc8b40fa780a38fd7494b9b5b991d09.tar.gz
rust-5c3ddcb15dc8b40fa780a38fd7494b9b5b991d09.zip
rollup merge of #20481: seanmonstar/fmt-show-string
Conflicts:
	src/compiletest/runtest.rs
	src/libcore/fmt/mod.rs
	src/libfmt_macros/lib.rs
	src/libregex/parse.rs
	src/librustc/middle/cfg/construct.rs
	src/librustc/middle/dataflow.rs
	src/librustc/middle/infer/higher_ranked/mod.rs
	src/librustc/middle/ty.rs
	src/librustc_back/archive.rs
	src/librustc_borrowck/borrowck/fragments.rs
	src/librustc_borrowck/borrowck/gather_loans/mod.rs
	src/librustc_resolve/lib.rs
	src/librustc_trans/back/link.rs
	src/librustc_trans/save/mod.rs
	src/librustc_trans/trans/base.rs
	src/librustc_trans/trans/callee.rs
	src/librustc_trans/trans/common.rs
	src/librustc_trans/trans/consts.rs
	src/librustc_trans/trans/controlflow.rs
	src/librustc_trans/trans/debuginfo.rs
	src/librustc_trans/trans/expr.rs
	src/librustc_trans/trans/monomorphize.rs
	src/librustc_typeck/astconv.rs
	src/librustc_typeck/check/method/mod.rs
	src/librustc_typeck/check/mod.rs
	src/librustc_typeck/check/regionck.rs
	src/librustc_typeck/collect.rs
	src/libsyntax/ext/format.rs
	src/libsyntax/ext/source_util.rs
	src/libsyntax/ext/tt/transcribe.rs
	src/libsyntax/parse/mod.rs
	src/libsyntax/parse/token.rs
	src/test/run-pass/issue-8898.rs
Diffstat (limited to 'src/libcollections/string.rs')
-rw-r--r--src/libcollections/string.rs40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index 20bc08416dc..938ee73455f 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -677,13 +677,25 @@ impl FromUtf8Error {
 
 impl fmt::Show for FromUtf8Error {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        self.error.fmt(f)
+        fmt::String::fmt(self, f)
+    }
+}
+
+impl fmt::String for FromUtf8Error {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt(&self.error, f)
     }
 }
 
 impl fmt::Show for FromUtf16Error {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        "invalid utf-16: lone surrogate found".fmt(f)
+        fmt::String::fmt(self, f)
+    }
+}
+
+impl fmt::String for FromUtf16Error {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt("invalid utf-16: lone surrogate found", f)
     }
 }
 
@@ -793,10 +805,17 @@ impl Default for String {
     }
 }
 
-#[experimental = "waiting on Show stabilization"]
+#[experimental = "waiting on fmt stabilization"]
+impl fmt::String for String {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt(&**self, f)
+    }
+}
+
+#[experimental = "waiting on fmt stabilization"]
 impl fmt::Show for String {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        (**self).fmt(f)
+        fmt::Show::fmt(&**self, f)
     }
 }
 
@@ -902,6 +921,8 @@ pub trait ToString {
     fn to_string(&self) -> String;
 }
 
+#[cfg(stage0)]
+//NOTE(stage0): remove after stage0 snapshot
 impl<T: fmt::Show> ToString for T {
     fn to_string(&self) -> String {
         use core::fmt::Writer;
@@ -912,6 +933,17 @@ impl<T: fmt::Show> ToString for T {
     }
 }
 
+#[cfg(not(stage0))]
+impl<T: fmt::String> ToString for T {
+    fn to_string(&self) -> String {
+        use core::fmt::Writer;
+        let mut buf = String::new();
+        let _ = buf.write_fmt(format_args!("{}", self));
+        buf.shrink_to_fit();
+        buf
+    }
+}
+
 impl IntoCow<'static, String, str> for String {
     fn into_cow(self) -> CowString<'static> {
         Cow::Owned(self)