Skip to content

Commit 6510527

Browse files
committed
auto merge of #14510 : kballard/rust/rename_strallocating_into_owned, r=alexcrichton
We already have into_string(), but it was implemented in terms of into_owned(). Flip it around and deprecate into_owned(). Remove a few spurious calls to .into_owned() that existed in libregex and librustdoc.
2 parents 81c0223 + eb98c9e commit 6510527

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

src/libregex/re.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,13 @@ impl<'t> Replacer for NoExpand<'t> {
573573

574574
impl<'t> Replacer for &'t str {
575575
fn reg_replace<'a>(&'a mut self, caps: &Captures) -> MaybeOwned<'a> {
576-
Owned(caps.expand(*self).into_owned())
576+
Owned(caps.expand(*self))
577577
}
578578
}
579579

580580
impl<'a> Replacer for |&Captures|: 'a -> String {
581581
fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
582-
Owned((*self)(caps).into_owned())
582+
Owned((*self)(caps))
583583
}
584584
}
585585

src/librustdoc/html/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl fmt::Show for clean::Type {
356356
}
357357
}
358358
}
359-
ret.into_owned()
359+
ret
360360
})
361361
}
362362
clean::Proc(ref decl) => {

src/libstd/str.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use mem;
7979
use option::{None, Option, Some};
8080
use result::Result;
8181
use slice::Vector;
82-
use slice::{ImmutableVector, MutableVector, CloneableVector};
82+
use slice::{ImmutableVector, MutableVector};
8383
use string::String;
8484
use vec::Vec;
8585

@@ -503,7 +503,7 @@ pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
503503
res.push_bytes(v.slice(subseqidx, total))
504504
};
505505
}
506-
Owned(res.into_owned())
506+
Owned(res.into_string())
507507
}
508508

509509
/*
@@ -608,7 +608,7 @@ impl<'a> Str for MaybeOwned<'a> {
608608

609609
impl<'a> StrAllocating for MaybeOwned<'a> {
610610
#[inline]
611-
fn into_owned(self) -> String {
611+
fn into_string(self) -> String {
612612
match self {
613613
Slice(s) => s.to_string(),
614614
Owned(s) => s
@@ -723,18 +723,18 @@ Section: Trait implementations
723723
/// Any string that can be represented as a slice
724724
pub trait StrAllocating: Str {
725725
/// Convert `self` into a `String`, not making a copy if possible.
726-
fn into_owned(self) -> String;
726+
fn into_string(self) -> String;
727727

728728
/// Convert `self` into a `String`.
729729
#[inline]
730730
fn to_string(&self) -> String {
731731
String::from_str(self.as_slice())
732732
}
733733

734-
/// Convert `self` into a `String`, not making a copy if possible.
735-
#[inline]
736-
fn into_string(self) -> String {
737-
self.into_owned()
734+
#[allow(missing_doc)]
735+
#[deprecated = "replaced by .into_string()"]
736+
fn into_owned(self) -> String {
737+
self.into_string()
738738
}
739739

740740
/// Escape each char in `s` with `char::escape_default`.
@@ -889,7 +889,7 @@ pub trait StrAllocating: Str {
889889

890890
impl<'a> StrAllocating for &'a str {
891891
#[inline]
892-
fn into_owned(self) -> String {
892+
fn into_string(self) -> String {
893893
self.to_string()
894894
}
895895
}
@@ -1045,7 +1045,7 @@ mod tests {
10451045
#[test]
10461046
fn test_concat() {
10471047
fn t(v: &[String], s: &str) {
1048-
assert_eq!(v.concat(), s.to_str().into_owned());
1048+
assert_eq!(v.concat(), s.to_str().into_string());
10491049
}
10501050
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
10511051
"no".to_string(), "good".to_string()], "youknowI'mnogood");
@@ -1057,7 +1057,7 @@ mod tests {
10571057
#[test]
10581058
fn test_connect() {
10591059
fn t(v: &[String], sep: &str, s: &str) {
1060-
assert_eq!(v.connect(sep), s.to_str().into_owned());
1060+
assert_eq!(v.connect(sep), s.to_str().into_string());
10611061
}
10621062
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
10631063
"no".to_string(), "good".to_string()],
@@ -1070,7 +1070,7 @@ mod tests {
10701070
#[test]
10711071
fn test_concat_slices() {
10721072
fn t(v: &[&str], s: &str) {
1073-
assert_eq!(v.concat(), s.to_str().into_owned());
1073+
assert_eq!(v.concat(), s.to_str().into_string());
10741074
}
10751075
t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
10761076
let v: &[&str] = [];
@@ -1081,7 +1081,7 @@ mod tests {
10811081
#[test]
10821082
fn test_connect_slices() {
10831083
fn t(v: &[&str], sep: &str, s: &str) {
1084-
assert_eq!(v.connect(sep), s.to_str().into_owned());
1084+
assert_eq!(v.connect(sep), s.to_str().into_string());
10851085
}
10861086
t(["you", "know", "I'm", "no", "good"],
10871087
" ", "you know I'm no good");
@@ -2162,9 +2162,9 @@ mod tests {
21622162
}
21632163

21642164
#[test]
2165-
fn test_maybe_owned_into_owned() {
2166-
assert_eq!(Slice("abcde").into_owned(), "abcde".to_string());
2167-
assert_eq!(Owned("abcde".to_string()).into_owned(), "abcde".to_string());
2165+
fn test_maybe_owned_into_string() {
2166+
assert_eq!(Slice("abcde").into_string(), "abcde".to_string());
2167+
assert_eq!(Owned("abcde".to_string()).into_string(), "abcde".to_string());
21682168
}
21692169

21702170
#[test]

src/libstd/string.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,6 @@ impl Str for String {
322322
}
323323

324324
impl StrAllocating for String {
325-
#[inline]
326-
fn into_owned(self) -> String {
327-
self
328-
}
329-
330325
#[inline]
331326
fn into_string(self) -> String {
332327
self

0 commit comments

Comments
 (0)