about summary refs log tree commit diff
path: root/src/libcollections/string.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-03-31 21:18:29 -0700
committerbors <bors@rust-lang.org>2016-03-31 21:18:29 -0700
commit3b342fae8e8a0704e2acbd8ecc3e7ad06ce5eec6 (patch)
treeb076c7decedf82b14fda09e8e45ee9f511b4b415 /src/libcollections/string.rs
parenta2f0cc6b0c63b85c9f550410178dbff4912a56bc (diff)
parentfc8cf9c5afd531e825b3ae9a57f618c149dd3893 (diff)
downloadrust-3b342fae8e8a0704e2acbd8ecc3e7ad06ce5eec6.tar.gz
rust-3b342fae8e8a0704e2acbd8ecc3e7ad06ce5eec6.zip
Auto merge of #32586 - seanmonstar:speialize-to-string, r=alexcrichton
specialize ToString for str

If there was some conditional compiling we could do, such that this impl only exists in nightly, and is turned off in beta/stable, I think that'd be an improvement here, as we could test specialization out without affecting stable builds.
Diffstat (limited to 'src/libcollections/string.rs')
-rw-r--r--src/libcollections/string.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index 6731b15fb2e..c84d84959db 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -1755,7 +1755,7 @@ pub trait ToString {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: fmt::Display + ?Sized> ToString for T {
     #[inline]
-    fn to_string(&self) -> String {
+    default fn to_string(&self) -> String {
         use core::fmt::Write;
         let mut buf = String::new();
         let _ = buf.write_fmt(format_args!("{}", self));
@@ -1764,6 +1764,14 @@ impl<T: fmt::Display + ?Sized> ToString for T {
     }
 }
 
+#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
+impl ToString for str {
+    #[inline]
+    fn to_string(&self) -> String {
+        String::from(self)
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl AsRef<str> for String {
     #[inline]