Skip to content

Commit fc8cf9c

Browse files
committed
specialize ToString for str
1 parent c7bdfd4 commit fc8cf9c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/libcollections/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#![feature(placement_new_protocol)]
4949
#![feature(shared)]
5050
#![feature(slice_patterns)]
51+
#![feature(specialization)]
5152
#![feature(staged_api)]
5253
#![feature(step_by)]
5354
#![feature(str_char)]

src/libcollections/string.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ pub trait ToString {
17701770
#[stable(feature = "rust1", since = "1.0.0")]
17711771
impl<T: fmt::Display + ?Sized> ToString for T {
17721772
#[inline]
1773-
fn to_string(&self) -> String {
1773+
default fn to_string(&self) -> String {
17741774
use core::fmt::Write;
17751775
let mut buf = String::new();
17761776
let _ = buf.write_fmt(format_args!("{}", self));
@@ -1779,6 +1779,14 @@ impl<T: fmt::Display + ?Sized> ToString for T {
17791779
}
17801780
}
17811781

1782+
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
1783+
impl ToString for str {
1784+
#[inline]
1785+
fn to_string(&self) -> String {
1786+
String::from(self)
1787+
}
1788+
}
1789+
17821790
#[stable(feature = "rust1", since = "1.0.0")]
17831791
impl AsRef<str> for String {
17841792
#[inline]

0 commit comments

Comments
 (0)