]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #14510 : kballard/rust/rename_strallocating_into_owned, r=alexcrichton
authorbors <bors@rust-lang.org>
Fri, 30 May 2014 02:31:42 +0000 (19:31 -0700)
committerbors <bors@rust-lang.org>
Fri, 30 May 2014 02:31:42 +0000 (19:31 -0700)
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.

1  2 
src/libregex/re.rs
src/librustdoc/html/format.rs
src/libstd/str.rs

diff --combined src/libregex/re.rs
index 83c1cb37158a910fc46b6628b909271890dcac76,190e37c6436391bd639ff273fd00d170d7e68e32..61cf1604cd52c725aaf05afa1054725f372bb224
@@@ -425,7 -425,7 +425,7 @@@ impl Regex 
      /// # use regex::Captures; fn main() {
      /// let re = regex!(r"([^,\s]+),\s+(\S+)");
      /// let result = re.replace("Springsteen, Bruce", |caps: &Captures| {
 -    ///     format_strbuf!("{} {}", caps.at(2), caps.at(1))
 +    ///     format!("{} {}", caps.at(2), caps.at(1))
      /// });
      /// assert_eq!(result.as_slice(), "Bruce Springsteen");
      /// # }
@@@ -573,13 -573,13 +573,13 @@@ impl<'t> Replacer for NoExpand<'t> 
  
  impl<'t> Replacer for &'t str {
      fn reg_replace<'a>(&'a mut self, caps: &Captures) -> MaybeOwned<'a> {
-         Owned(caps.expand(*self).into_owned())
+         Owned(caps.expand(*self))
      }
  }
  
  impl<'a> Replacer for |&Captures|: 'a -> String {
      fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
-         Owned((*self)(caps).into_owned())
+         Owned((*self)(caps))
      }
  }
  
@@@ -761,8 -761,9 +761,8 @@@ impl<'t> Captures<'t> 
          let re = Regex::new(r"(^|[^$]|\b)\$(\w+)").unwrap();
          let text = re.replace_all(text, |refs: &Captures| -> String {
              let (pre, name) = (refs.at(1), refs.at(2));
 -            format_strbuf!("{}{}",
 -                           pre,
 -                           match from_str::<uint>(name.as_slice()) {
 +            format!("{}{}", pre,
 +                    match from_str::<uint>(name.as_slice()) {
                  None => self.name(name).to_string(),
                  Some(i) => self.at(i).to_string(),
              })
index 7af1eb21aead0afd80c636da552d73b1b755ccae,8b8ed92e72a3e84d14d4398423139c789b4a7924..3b3f4378d67ad3589ffb42e982b99176965b2f46
@@@ -356,7 -356,7 +356,7 @@@ impl fmt::Show for clean::Type 
                                      }
                                  }
                             }
-                            ret.into_owned()
+                            ret
                         })
              }
              clean::Proc(ref decl) => {
                         lifetimes = if decl.lifetimes.len() == 0 {
                             "".to_string()
                         } else {
 -                           format_strbuf!("&lt;{:#}&gt;", decl.lifetimes)
 +                           format!("&lt;{:#}&gt;", decl.lifetimes)
                         },
                         args = decl.decl.inputs,
                         bounds = if decl.bounds.len() == 0 {
                             let mut m = decl.bounds
                                             .iter()
                                             .map(|s| s.to_str().to_string());
 -                           format_strbuf!(
 +                           format!(
                                 ": {}",
                                 m.collect::<Vec<String>>().connect(" + "))
                         },
                         match decl.abi.as_slice() {
                             "" => " extern ".to_string(),
                             "\"Rust\"" => "".to_string(),
 -                           s => format_strbuf!(" extern {} ", s)
 +                           s => format!(" extern {} ", s)
                         },
                         decl.generics,
                         decl.decl)
diff --combined src/libstd/str.rs
index 274a1b068634da01bae2c52c1a277b2b49a907bf,9a6e3a9dca2b2a134fb44ac4db4ef653de29dc11..6538809c8f12d27894fd5e22819de7742c342628
@@@ -79,7 -79,7 +79,7 @@@ use mem
  use option::{None, Option, Some};
  use result::Result;
  use slice::Vector;
- use slice::{ImmutableVector, MutableVector, CloneableVector};
+ use slice::{ImmutableVector, MutableVector};
  use string::String;
  use vec::Vec;
  
@@@ -503,7 -503,7 +503,7 @@@ pub fn from_utf8_lossy<'a>(v: &'a [u8]
              res.push_bytes(v.slice(subseqidx, total))
          };
      }
-     Owned(res.into_owned())
+     Owned(res.into_string())
  }
  
  /*
@@@ -608,7 -608,7 +608,7 @@@ impl<'a> Str for MaybeOwned<'a> 
  
  impl<'a> StrAllocating for MaybeOwned<'a> {
      #[inline]
-     fn into_owned(self) -> String {
+     fn into_string(self) -> String {
          match self {
              Slice(s) => s.to_string(),
              Owned(s) => s
@@@ -723,7 -723,7 +723,7 @@@ Section: Trait implementation
  /// Any string that can be represented as a slice
  pub trait StrAllocating: Str {
      /// Convert `self` into a `String`, not making a copy if possible.
-     fn into_owned(self) -> String;
+     fn into_string(self) -> String;
  
      /// Convert `self` into a `String`.
      #[inline]
          String::from_str(self.as_slice())
      }
  
-     /// Convert `self` into a `String`, not making a copy if possible.
-     #[inline]
-     fn into_string(self) -> String {
-         self.into_owned()
+     #[allow(missing_doc)]
+     #[deprecated = "replaced by .into_string()"]
+     fn into_owned(self) -> String {
+         self.into_string()
      }
  
      /// Escape each char in `s` with `char::escape_default`.
  
  impl<'a> StrAllocating for &'a str {
      #[inline]
-     fn into_owned(self) -> String {
+     fn into_string(self) -> String {
          self.to_string()
      }
  }
@@@ -1045,7 -1045,7 +1045,7 @@@ mod tests 
      #[test]
      fn test_concat() {
          fn t(v: &[String], s: &str) {
-             assert_eq!(v.concat(), s.to_str().into_owned());
+             assert_eq!(v.concat(), s.to_str().into_string());
          }
          t(["you".to_string(), "know".to_string(), "I'm".to_string(),
            "no".to_string(), "good".to_string()], "youknowI'mnogood");
      #[test]
      fn test_connect() {
          fn t(v: &[String], sep: &str, s: &str) {
-             assert_eq!(v.connect(sep), s.to_str().into_owned());
+             assert_eq!(v.connect(sep), s.to_str().into_string());
          }
          t(["you".to_string(), "know".to_string(), "I'm".to_string(),
             "no".to_string(), "good".to_string()],
      #[test]
      fn test_concat_slices() {
          fn t(v: &[&str], s: &str) {
-             assert_eq!(v.concat(), s.to_str().into_owned());
+             assert_eq!(v.concat(), s.to_str().into_string());
          }
          t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
          let v: &[&str] = [];
      #[test]
      fn test_connect_slices() {
          fn t(v: &[&str], sep: &str, s: &str) {
-             assert_eq!(v.connect(sep), s.to_str().into_owned());
+             assert_eq!(v.connect(sep), s.to_str().into_string());
          }
          t(["you", "know", "I'm", "no", "good"],
            " ", "you know I'm no good");
          assert_eq!(s.len(), 5);
          assert_eq!(s.as_slice(), "abcde");
          assert_eq!(s.to_str(), "abcde".to_string());
 -        assert_eq!(format_strbuf!("{}", s), "abcde".to_string());
 +        assert_eq!(format!("{}", s), "abcde".to_string());
          assert!(s.lt(&Owned("bcdef".to_string())));
          assert_eq!(Slice(""), Default::default());
  
          assert_eq!(o.len(), 5);
          assert_eq!(o.as_slice(), "abcde");
          assert_eq!(o.to_str(), "abcde".to_string());
 -        assert_eq!(format_strbuf!("{}", o), "abcde".to_string());
 +        assert_eq!(format!("{}", o), "abcde".to_string());
          assert!(o.lt(&Slice("bcdef")));
          assert_eq!(Owned("".to_string()), Default::default());
  
      }
  
      #[test]
-     fn test_maybe_owned_into_owned() {
-         assert_eq!(Slice("abcde").into_owned(), "abcde".to_string());
-         assert_eq!(Owned("abcde".to_string()).into_owned(), "abcde".to_string());
+     fn test_maybe_owned_into_string() {
+         assert_eq!(Slice("abcde").into_string(), "abcde".to_string());
+         assert_eq!(Owned("abcde".to_string()).into_string(), "abcde".to_string());
      }
  
      #[test]