Skip to content

Commit

Permalink
std: Remove String's to_owned
Browse files Browse the repository at this point in the history
  • Loading branch information
richo committed May 27, 2014
1 parent c7fe4ff commit 4348e23
Show file tree
Hide file tree
Showing 113 changed files with 442 additions and 438 deletions.
6 changes: 3 additions & 3 deletions src/compiletest/compiletest.rs
Expand Up @@ -314,10 +314,10 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
match config.mode {
Pretty => vec!(".rs".to_owned()),
_ => vec!(".rc".to_owned(), ".rs".to_owned())
Pretty => vec!(".rs".to_string()),
_ => vec!(".rc".to_string(), ".rs".to_string())
};
let invalid_prefixes = vec!(".".to_owned(), "#".to_owned(), "~".to_owned());
let invalid_prefixes = vec!(".".to_string(), "#".to_string(), "~".to_string());
let name = testfile.filename_str().unwrap();

let mut valid = false;
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Expand Up @@ -1034,7 +1034,7 @@ fn compose_and_run_compiler(

let aux_dir = aux_output_dir_name(config, testfile);
// FIXME (#9639): This needs to handle non-utf8 paths
let extra_link_args = vec!("-L".to_owned(), aux_dir.as_str().unwrap().to_owned());
let extra_link_args = vec!("-L".to_string(), aux_dir.as_str().unwrap().to_owned());

for rel_ab in props.aux_builds.iter() {
let abs_ab = config.aux_base.join(rel_ab.as_slice());
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust.md
Expand Up @@ -3538,7 +3538,7 @@ allocated on the heap (unlike closures). An example of creating and calling a
procedure:

```rust
let string = "Hello".to_owned();
let string = "Hello".to_string();

// Creates a new procedure, passing it to the `spawn` function.
spawn(proc() {
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/bitv.rs
Expand Up @@ -988,10 +988,10 @@ mod tests {
#[test]
fn test_to_str() {
let zerolen = Bitv::new(0u, false);
assert_eq!(zerolen.to_str(), "".to_owned());
assert_eq!(zerolen.to_str(), "".to_string());

let eightbits = Bitv::new(8u, false);
assert_eq!(eightbits.to_str(), "00000000".to_owned());
assert_eq!(eightbits.to_str(), "00000000".to_string());
}

#[test]
Expand All @@ -1014,7 +1014,7 @@ mod tests {
let mut b = bitv::Bitv::new(2, false);
b.set(0, true);
b.set(1, false);
assert_eq!(b.to_str(), "10".to_owned());
assert_eq!(b.to_str(), "10".to_string());
}

#[test]
Expand Down Expand Up @@ -1343,7 +1343,7 @@ mod tests {
#[test]
fn test_from_bools() {
assert!(from_bools([true, false, true, true]).to_str() ==
"1011".to_owned());
"1011".to_string());
}

#[test]
Expand Down
86 changes: 43 additions & 43 deletions src/libcollections/btree.rs
Expand Up @@ -778,81 +778,81 @@ mod test_btree {
//Tests the functionality of the insert methods (which are unfinished).
#[test]
fn insert_test_one() {
let b = BTree::new(1, "abc".to_owned(), 2);
let is_insert = b.insert(2, "xyz".to_owned());
let b = BTree::new(1, "abc".to_string(), 2);
let is_insert = b.insert(2, "xyz".to_string());
//println!("{}", is_insert.clone().to_str());
assert!(is_insert.root.is_leaf());
}

#[test]
fn insert_test_two() {
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
let leaf_elt_3 = LeafElt::new(3, "ccc".to_owned());
let leaf_elt_1 = LeafElt::new(1, "aaa".to_string());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_string());
let leaf_elt_3 = LeafElt::new(3, "ccc".to_string());
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3));
let b = BTree::new_with_node_len(n, 3, 2);
//println!("{}", b.clone().insert(4, "ddd".to_owned()).to_str());
assert!(b.insert(4, "ddd".to_owned()).root.is_leaf());
//println!("{}", b.clone().insert(4, "ddd".to_string()).to_str());
assert!(b.insert(4, "ddd".to_string()).root.is_leaf());
}

#[test]
fn insert_test_three() {
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
let leaf_elt_3 = LeafElt::new(3, "ccc".to_owned());
let leaf_elt_4 = LeafElt::new(4, "ddd".to_owned());
let leaf_elt_1 = LeafElt::new(1, "aaa".to_string());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_string());
let leaf_elt_3 = LeafElt::new(3, "ccc".to_string());
let leaf_elt_4 = LeafElt::new(4, "ddd".to_string());
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
let b = BTree::new_with_node_len(n, 3, 2);
//println!("{}", b.clone().insert(5, "eee".to_owned()).to_str());
assert!(!b.insert(5, "eee".to_owned()).root.is_leaf());
//println!("{}", b.clone().insert(5, "eee".to_string()).to_str());
assert!(!b.insert(5, "eee".to_string()).root.is_leaf());
}

#[test]
fn insert_test_four() {
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
let leaf_elt_3 = LeafElt::new(3, "ccc".to_owned());
let leaf_elt_4 = LeafElt::new(4, "ddd".to_owned());
let leaf_elt_1 = LeafElt::new(1, "aaa".to_string());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_string());
let leaf_elt_3 = LeafElt::new(3, "ccc".to_string());
let leaf_elt_4 = LeafElt::new(4, "ddd".to_string());
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
let mut b = BTree::new_with_node_len(n, 3, 2);
b = b.clone().insert(5, "eee".to_owned());
b = b.clone().insert(6, "fff".to_owned());
b = b.clone().insert(7, "ggg".to_owned());
b = b.clone().insert(8, "hhh".to_owned());
b = b.clone().insert(0, "omg".to_owned());
b = b.clone().insert(5, "eee".to_string());
b = b.clone().insert(6, "fff".to_string());
b = b.clone().insert(7, "ggg".to_string());
b = b.clone().insert(8, "hhh".to_string());
b = b.clone().insert(0, "omg".to_string());
//println!("{}", b.clone().to_str());
assert!(!b.root.is_leaf());
}

#[test]
fn bsearch_test_one() {
let b = BTree::new(1, "abc".to_owned(), 2);
let b = BTree::new(1, "abc".to_string(), 2);
assert_eq!(Some(1), b.root.bsearch_node(2));
}

#[test]
fn bsearch_test_two() {
let b = BTree::new(1, "abc".to_owned(), 2);
let b = BTree::new(1, "abc".to_string(), 2);
assert_eq!(Some(0), b.root.bsearch_node(0));
}

#[test]
fn bsearch_test_three() {
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
let leaf_elt_3 = LeafElt::new(4, "ccc".to_owned());
let leaf_elt_4 = LeafElt::new(5, "ddd".to_owned());
let leaf_elt_1 = LeafElt::new(1, "aaa".to_string());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_string());
let leaf_elt_3 = LeafElt::new(4, "ccc".to_string());
let leaf_elt_4 = LeafElt::new(5, "ddd".to_string());
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
let b = BTree::new_with_node_len(n, 3, 2);
assert_eq!(Some(2), b.root.bsearch_node(3));
}

#[test]
fn bsearch_test_four() {
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
let leaf_elt_3 = LeafElt::new(4, "ccc".to_owned());
let leaf_elt_4 = LeafElt::new(5, "ddd".to_owned());
let leaf_elt_1 = LeafElt::new(1, "aaa".to_string());
let leaf_elt_2 = LeafElt::new(2, "bbb".to_string());
let leaf_elt_3 = LeafElt::new(4, "ccc".to_string());
let leaf_elt_4 = LeafElt::new(5, "ddd".to_string());
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
let b = BTree::new_with_node_len(n, 3, 2);
assert_eq!(Some(4), b.root.bsearch_node(800));
Expand All @@ -861,48 +861,48 @@ mod test_btree {
//Tests the functionality of the get method.
#[test]
fn get_test() {
let b = BTree::new(1, "abc".to_owned(), 2);
let b = BTree::new(1, "abc".to_string(), 2);
let val = b.get(1);
assert_eq!(val, Some("abc".to_owned()));
assert_eq!(val, Some("abc".to_string()));
}

//Tests the BTree's clone() method.
#[test]
fn btree_clone_test() {
let b = BTree::new(1, "abc".to_owned(), 2);
let b = BTree::new(1, "abc".to_string(), 2);
let b2 = b.clone();
assert!(b.root == b2.root)
}

//Tests the BTree's cmp() method when one node is "less than" another.
#[test]
fn btree_cmp_test_less() {
let b = BTree::new(1, "abc".to_owned(), 2);
let b2 = BTree::new(2, "bcd".to_owned(), 2);
let b = BTree::new(1, "abc".to_string(), 2);
let b2 = BTree::new(2, "bcd".to_string(), 2);
assert!(&b.cmp(&b2) == &Less)
}

//Tests the BTree's cmp() method when two nodes are equal.
#[test]
fn btree_cmp_test_eq() {
let b = BTree::new(1, "abc".to_owned(), 2);
let b2 = BTree::new(1, "bcd".to_owned(), 2);
let b = BTree::new(1, "abc".to_string(), 2);
let b2 = BTree::new(1, "bcd".to_string(), 2);
assert!(&b.cmp(&b2) == &Equal)
}

//Tests the BTree's cmp() method when one node is "greater than" another.
#[test]
fn btree_cmp_test_greater() {
let b = BTree::new(1, "abc".to_owned(), 2);
let b2 = BTree::new(2, "bcd".to_owned(), 2);
let b = BTree::new(1, "abc".to_string(), 2);
let b2 = BTree::new(2, "bcd".to_string(), 2);
assert!(&b2.cmp(&b) == &Greater)
}

//Tests the BTree's to_str() method.
#[test]
fn btree_tostr_test() {
let b = BTree::new(1, "abc".to_owned(), 2);
assert_eq!(b.to_str(), "Key: 1, value: abc;".to_owned())
let b = BTree::new(1, "abc".to_string(), 2);
assert_eq!(b.to_str(), "Key: 1, value: abc;".to_string())
}

}
10 changes: 5 additions & 5 deletions src/libcollections/hashmap.rs
Expand Up @@ -2026,9 +2026,9 @@ mod test_map {
let mut m = HashMap::new();

let (foo, bar, baz) = (1,2,3);
m.insert("foo".to_owned(), foo);
m.insert("bar".to_owned(), bar);
m.insert("baz".to_owned(), baz);
m.insert("foo".to_string(), foo);
m.insert("bar".to_string(), bar);
m.insert("baz".to_string(), baz);


assert_eq!(m.find_equiv(&("foo")), Some(&foo));
Expand Down Expand Up @@ -2313,8 +2313,8 @@ mod test_set {

let set_str = format!("{}", set);

assert!(set_str == "{1, 2}".to_owned() || set_str == "{2, 1}".to_owned());
assert_eq!(format!("{}", empty), "{}".to_owned());
assert!(set_str == "{1, 2}".to_string() || set_str == "{2, 1}".to_string());
assert_eq!(format!("{}", empty), "{}".to_string());
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/lru_cache.rs
Expand Up @@ -319,15 +319,15 @@ mod tests {
cache.put(1, 10);
cache.put(2, 20);
cache.put(3, 30);
assert_eq!(cache.to_str(), "{3: 30, 2: 20, 1: 10}".to_owned());
assert_eq!(cache.to_str(), "{3: 30, 2: 20, 1: 10}".to_string());
cache.put(2, 22);
assert_eq!(cache.to_str(), "{2: 22, 3: 30, 1: 10}".to_owned());
assert_eq!(cache.to_str(), "{2: 22, 3: 30, 1: 10}".to_string());
cache.put(6, 60);
assert_eq!(cache.to_str(), "{6: 60, 2: 22, 3: 30}".to_owned());
assert_eq!(cache.to_str(), "{6: 60, 2: 22, 3: 30}".to_string());
cache.get(&3);
assert_eq!(cache.to_str(), "{3: 30, 6: 60, 2: 22}".to_owned());
assert_eq!(cache.to_str(), "{3: 30, 6: 60, 2: 22}".to_string());
cache.change_capacity(2);
assert_eq!(cache.to_str(), "{3: 30, 6: 60}".to_owned());
assert_eq!(cache.to_str(), "{3: 30, 6: 60}".to_string());
}

#[test]
Expand All @@ -338,6 +338,6 @@ mod tests {
cache.clear();
assert!(cache.get(&1).is_none());
assert!(cache.get(&2).is_none());
assert_eq!(cache.to_str(), "{}".to_owned());
assert_eq!(cache.to_str(), "{}".to_string());
}
}
2 changes: 1 addition & 1 deletion src/libcore/fmt/num.rs
Expand Up @@ -140,7 +140,7 @@ pub struct RadixFmt<T, R>(T, R);
///
/// ~~~
/// use std::fmt::radix;
/// assert_eq!(format!("{}", radix(55, 36)), "1j".to_owned());
/// assert_eq!(format!("{}", radix(55, 36)), "1j".to_string());
/// ~~~
pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
RadixFmt(x, Radix::new(base))
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/mem.rs
Expand Up @@ -552,7 +552,7 @@ mod tests {

#[test]
fn test_replace() {
let mut x = Some("test".to_owned());
let mut x = Some("test".to_string());
let y = replace(&mut x, None);
assert!(x.is_none());
assert!(y.is_some());
Expand All @@ -576,7 +576,7 @@ mod tests {
}

unsafe {
assert!(Vec::from_slice([76u8]) == transmute("L".to_owned()));
assert!(Vec::from_slice([76u8]) == transmute("L".to_string()));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/slice.rs
Expand Up @@ -925,15 +925,15 @@ pub trait MutableVector<'a, T> {
/// # Example
///
/// ```rust
/// let mut v = ~["foo".to_owned(), "bar".to_owned(), "baz".to_owned()];
/// let mut v = ~["foo".to_string(), "bar".to_string(), "baz".to_string()];
///
/// unsafe {
/// // `"baz".to_owned()` is deallocated.
/// v.unsafe_set(2, "qux".to_owned());
/// // `"baz".to_string()` is deallocated.
/// v.unsafe_set(2, "qux".to_string());
///
/// // Out of bounds: could cause a crash, or overwriting
/// // other data, or something else.
/// // v.unsafe_set(10, "oops".to_owned());
/// // v.unsafe_set(10, "oops".to_string());
/// }
/// ```
unsafe fn unsafe_set(self, index: uint, val: T);
Expand All @@ -945,10 +945,10 @@ pub trait MutableVector<'a, T> {
/// # Example
///
/// ```rust
/// let mut v = ["foo".to_owned(), "bar".to_owned()];
/// let mut v = ["foo".to_string(), "bar".to_string()];
///
/// // memory leak! `"bar".to_owned()` is not deallocated.
/// unsafe { v.init_elem(1, "baz".to_owned()); }
/// // memory leak! `"bar".to_string()` is not deallocated.
/// unsafe { v.init_elem(1, "baz".to_string()); }
/// ```
unsafe fn init_elem(self, i: uint, val: T);

Expand Down
2 changes: 1 addition & 1 deletion src/libgetopts/lib.rs
Expand Up @@ -728,7 +728,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
each_split_within(desc_normalized_whitespace.as_slice(),
54,
|substr| {
desc_rows.push(substr.to_owned());
desc_rows.push(substr.to_string());
true
});

Expand Down
10 changes: 5 additions & 5 deletions src/libnative/io/process.rs
Expand Up @@ -1103,24 +1103,24 @@ mod tests {

assert_eq!(
test_wrapper("prog", ["aaa", "bbb", "ccc"]),
"prog aaa bbb ccc".to_owned()
"prog aaa bbb ccc".to_string()
);

assert_eq!(
test_wrapper("C:\\Program Files\\blah\\blah.exe", ["aaa"]),
"\"C:\\Program Files\\blah\\blah.exe\" aaa".to_owned()
"\"C:\\Program Files\\blah\\blah.exe\" aaa".to_string()
);
assert_eq!(
test_wrapper("C:\\Program Files\\test", ["aa\"bb"]),
"\"C:\\Program Files\\test\" aa\\\"bb".to_owned()
"\"C:\\Program Files\\test\" aa\\\"bb".to_string()
);
assert_eq!(
test_wrapper("echo", ["a b c"]),
"echo \"a b c\"".to_owned()
"echo \"a b c\"".to_string()
);
assert_eq!(
test_wrapper("\u03c0\u042f\u97f3\u00e6\u221e", []),
"\u03c0\u042f\u97f3\u00e6\u221e".to_owned()
"\u03c0\u042f\u97f3\u00e6\u221e".to_string()
);
}
}
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Expand Up @@ -703,7 +703,7 @@ pub fn exported_name(path: PathElems, hash: &str, vers: &str) -> String {
let vers = if vers.len() > 0 && !char::is_XID_start(vers.char_at(0)) {
format!("v{}", vers)
} else {
vers.to_owned()
vers.to_string()
};

mangle(path, Some(hash), Some(vers.as_slice()))
Expand Down

0 comments on commit 4348e23

Please sign in to comment.