Skip to content

Commit db6dd8e

Browse files
committed
Auto merge of #32182 - bluss:string-from-is-str-owned, r=alexcrichton
Call str::to_owned in String::from and uninline it Call str::to_owned in String::from and uninline it These methods were already effectively equal, but now one calls the other, and neither is marked inline. String::from does not need to be inlined, it can be without it just like str::to_owned and String::clone are. Fixes #32163
2 parents 06074ac + ec39a76 commit db6dd8e

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/libcollections/string.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use core::str::pattern::Pattern;
6666
use rustc_unicode::char::{decode_utf16, REPLACEMENT_CHARACTER};
6767
use rustc_unicode::str as unicode_str;
6868

69-
use borrow::Cow;
69+
use borrow::{Cow, ToOwned};
7070
use range::RangeArgument;
7171
use str::{self, FromStr, Utf8Error, Chars};
7272
use vec::Vec;
@@ -1797,20 +1797,8 @@ impl AsRef<[u8]> for String {
17971797

17981798
#[stable(feature = "rust1", since = "1.0.0")]
17991799
impl<'a> From<&'a str> for String {
1800-
#[cfg(not(test))]
1801-
#[inline]
18021800
fn from(s: &'a str) -> String {
1803-
String { vec: <[_]>::to_vec(s.as_bytes()) }
1804-
}
1805-
1806-
// HACK(japaric): with cfg(test) the inherent `[T]::to_vec` method, which is
1807-
// required for this method definition, is not available. Since we don't
1808-
// require this method for testing purposes, I'll just stub it
1809-
// NB see the slice::hack module in slice.rs for more information
1810-
#[inline]
1811-
#[cfg(test)]
1812-
fn from(_: &str) -> String {
1813-
panic!("not available with cfg(test)");
1801+
s.to_owned()
18141802
}
18151803
}
18161804

0 commit comments

Comments
 (0)