Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use into_string() instead of to_string() on string literals #19708

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
//! // through a shared reference.
//! let gadget_owner : Rc<Owner> = Rc::new(
//! Owner {
//! name: "Gadget Man".to_string(),
//! name: "Gadget Man".into_string(),
//! gadgets: RefCell::new(Vec::new())
//! }
//! );
Expand Down
8 changes: 4 additions & 4 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ mod tests {
let arena = TypedArena::new();
for _ in range(0u, 100000) {
arena.alloc(Noncopy {
string: "hello world".to_string(),
string: "hello world".into_string(),
array: vec!( 1, 2, 3, 4, 5 ),
});
}
Expand All @@ -588,7 +588,7 @@ mod tests {
let arena = TypedArena::new();
b.iter(|| {
arena.alloc(Noncopy {
string: "hello world".to_string(),
string: "hello world".into_string(),
array: vec!( 1, 2, 3, 4, 5 ),
})
})
Expand All @@ -598,7 +598,7 @@ mod tests {
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
b.iter(|| {
box Noncopy {
string: "hello world".to_string(),
string: "hello world".into_string(),
array: vec!( 1, 2, 3, 4, 5 ),
}
})
Expand All @@ -609,7 +609,7 @@ mod tests {
let arena = Arena::new();
b.iter(|| {
arena.alloc(|| Noncopy {
string: "hello world".to_string(),
string: "hello world".into_string(),
array: vec!( 1, 2, 3, 4, 5 ),
})
})
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
//! phone: u64,
//! }
//!
//! let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
//! let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
//! let person1 = Person { id: 5, name: "Janet".into_string(), phone: 555_666_7777 };
//! let person2 = Person { id: 5, name: "Bob".into_string(), phone: 555_666_7777 };
//!
//! assert!(hash::hash(&person1) != hash::hash(&person2));
//! ```
Expand All @@ -53,8 +53,8 @@
//! }
//! }
//!
//! let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
//! let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
//! let person1 = Person { id: 5, name: "Janet".into_string(), phone: 555_666_7777 };
//! let person2 = Person { id: 5, name: "Bob".into_string(), phone: 555_666_7777 };
//!
//! assert!(hash::hash(&person1) == hash::hash(&person2));
//! ```
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ mod tests {
assert_eq!(it.next(), None);
}
{
let v = ["Hello".to_string()];
let v = ["Hello".into_string()];
let mut it = v.permutations();
let (min_size, max_opt) = it.size_hint();
assert_eq!(min_size, 1);
Expand Down
16 changes: 8 additions & 8 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ pub trait StrVector for Sized? {
/// # Examples
///
/// ```rust
/// let first = "Restaurant at the End of the".to_string();
/// let second = " Universe".to_string();
/// let first = "Restaurant at the End of the".into_string();
/// let second = " Universe".into_string();
/// let string_vec = vec![first, second];
/// assert_eq!(string_vec.concat(), "Restaurant at the End of the Universe".to_string());
/// assert_eq!(string_vec.concat(), "Restaurant at the End of the Universe".into_string());
/// ```
fn concat(&self) -> String;

Expand All @@ -108,10 +108,10 @@ pub trait StrVector for Sized? {
/// # Examples
///
/// ```rust
/// let first = "Roast".to_string();
/// let second = "Sirloin Steak".to_string();
/// let first = "Roast".into_string();
/// let second = "Sirloin Steak".into_string();
/// let string_vec = vec![first, second];
/// assert_eq!(string_vec.connect(", "), "Roast, Sirloin Steak".to_string());
/// assert_eq!(string_vec.connect(", "), "Roast, Sirloin Steak".into_string());
/// ```
fn connect(&self, sep: &str) -> String;
}
Expand Down Expand Up @@ -720,11 +720,11 @@ pub trait StrAllocating: Str {
///
/// ```rust
/// let s = "Do you know the muffin man,
/// The muffin man, the muffin man, ...".to_string();
/// The muffin man, the muffin man, ...".into_string();
///
/// assert_eq!(s.replace("muffin man", "little lamb"),
/// "Do you know the little lamb,
/// The little lamb, the little lamb, ...".to_string());
/// The little lamb, the little lamb, ...".into_string());
///
/// // not found, so no change.
/// assert_eq!(s.replace("cookie monster", "little lamb"), s);
Expand Down
30 changes: 15 additions & 15 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl String {
/// ```rust
/// let hello_vec = vec![104, 101, 108, 108, 111];
/// let s = String::from_utf8(hello_vec);
/// assert_eq!(s, Ok("hello".to_string()));
/// assert_eq!(s, Ok("hello".into_string()));
///
/// let invalid_vec = vec![240, 144, 128];
/// let s = String::from_utf8(invalid_vec);
Expand Down Expand Up @@ -246,7 +246,7 @@ impl String {
/// // 𝄞music
/// let mut v = &mut [0xD834, 0xDD1E, 0x006d, 0x0075,
/// 0x0073, 0x0069, 0x0063];
/// assert_eq!(String::from_utf16(v), Some("𝄞music".to_string()));
/// assert_eq!(String::from_utf16(v), Some("𝄞music".into_string()));
///
/// // 𝄞mu<invalid>ic
/// v[4] = 0xD800;
Expand Down Expand Up @@ -276,7 +276,7 @@ impl String {
/// 0xD834];
///
/// assert_eq!(String::from_utf16_lossy(v),
/// "𝄞mus\uFFFDic\uFFFD".to_string());
/// "𝄞mus\uFFFDic\uFFFD".into_string());
/// ```
#[stable]
pub fn from_utf16_lossy(v: &[u16]) -> String {
Expand Down Expand Up @@ -686,7 +686,7 @@ impl String {
/// # Examples
///
/// ```
/// let a = "foo".to_string();
/// let a = "foo".into_string();
/// assert_eq!(a.len(), 3);
/// ```
#[inline]
Expand All @@ -710,7 +710,7 @@ impl String {
/// # Examples
///
/// ```
/// let mut s = "foo".to_string();
/// let mut s = "foo".into_string();
/// s.clear();
/// assert!(s.is_empty());
/// ```
Expand Down Expand Up @@ -911,7 +911,7 @@ impl<'a> Deref<String> for DerefString<'a> {
/// use std::string::as_string;
///
/// fn string_consumer(s: String) {
/// assert_eq!(s, "foo".to_string());
/// assert_eq!(s, "foo".into_string());
/// }
///
/// let string = as_string("foo").clone();
Expand Down Expand Up @@ -1015,7 +1015,7 @@ mod tests {
use test::Bencher;

use slice::CloneSliceAllocPrelude;
use str::{Str, StrPrelude};
use str::{Str, StrAllocating, StrPrelude};
use str;
use super::{as_string, String, ToString};
use vec::Vec;
Expand Down Expand Up @@ -1286,7 +1286,7 @@ mod tests {

#[test]
fn remove() {
let mut s = "ศไทย中华Việt Nam; foobar".to_string();;
let mut s = "ศไทย中华Việt Nam; foobar".into_string();;
assert_eq!(s.remove(0), Some('ศ'));
assert_eq!(s.len(), 33);
assert_eq!(s, "ไทย中华Việt Nam; foobar");
Expand All @@ -1298,24 +1298,24 @@ mod tests {

#[test] #[should_fail]
fn remove_bad() {
"ศ".to_string().remove(1);
"ศ".into_string().remove(1);
}

#[test]
fn insert() {
let mut s = "foobar".to_string();
let mut s = "foobar".into_string();
s.insert(0, 'ệ');
assert_eq!(s, "ệfoobar");
s.insert(6, 'ย');
assert_eq!(s, "ệfooยbar");
}

#[test] #[should_fail] fn insert_bad1() { "".to_string().insert(1, 't'); }
#[test] #[should_fail] fn insert_bad2() { "ệ".to_string().insert(1, 't'); }
#[test] #[should_fail] fn insert_bad1() { "".into_string().insert(1, 't'); }
#[test] #[should_fail] fn insert_bad2() { "ệ".into_string().insert(1, 't'); }

#[test]
fn test_slicing() {
let s = "foobar".to_string();
let s = "foobar".into_string();
assert_eq!("foobar", s[]);
assert_eq!("foo", s[..3]);
assert_eq!("bar", s[3..]);
Expand All @@ -1331,7 +1331,7 @@ mod tests {
assert_eq!(true.to_string(), "true");
assert_eq!(false.to_string(), "false");
assert_eq!(().to_string(), "()");
assert_eq!(("hi".to_string()).to_string(), "hi");
assert_eq!(("hi".into_string()).to_string(), "hi");
}

#[test]
Expand All @@ -1346,7 +1346,7 @@ mod tests {

#[test]
fn test_from_iterator() {
let s = "ศไทย中华Việt Nam".to_string();
let s = "ศไทย中华Việt Nam".into_string();
let t = "ศไทย中华";
let u = "Việt Nam";

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/tree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ impl<K, V> TreeMap<K, V> {
///
/// fn get_headers() -> TreeMap<String, String> {
/// let mut result = TreeMap::new();
/// result.insert("Content-Type".to_string(), "application/xml".to_string());
/// result.insert("User-Agent".to_string(), "Curl-Rust/0.1".to_string());
/// result.insert("Content-Type".into_string(), "application/xml".into_string());
/// result.insert("User-Agent".into_string(), "Curl-Rust/0.1".into_string());
/// result
/// }
///
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ impl<T> Vec<T> {
/// # Examples
///
/// ```
/// let v = vec!["a".to_string(), "b".to_string()];
/// let v = vec!["a".into_string(), "b".into_string()];
/// for s in v.into_iter() {
/// // s has type String, not &String
/// println!("{}", s);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
//! }
//!
//! fn main() {
//! let my_string = "Hello World".to_string();
//! let my_string = "Hello World".into_string();
//! do_work(&my_string);
//!
//! let my_i8: i8 = 100;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<T,R> Copy for RadixFmt<T,R> where T: Copy, R: Copy {}
///
/// ```
/// use std::fmt::radix;
/// assert_eq!(format!("{}", radix(55i, 36)), "1j".to_string());
/// assert_eq!(format!("{}", radix(55i, 36)), "1j".into_string());
/// ```
#[unstable = "may be renamed or move to a different module"]
pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<T> Option<T> {
/// to the value inside the original.
///
/// ```
/// let num_as_str: Option<String> = Some("10".to_string());
/// let num_as_str: Option<String> = Some("10".into_string());
/// // First, cast `Option<String>` to `Option<&String>` with `as_ref`,
/// // then consume *that* with `map`, leaving `num_as_str` on the stack.
/// let num_as_int: Option<uint> = num_as_str.as_ref().map(|n| n.len());
Expand Down Expand Up @@ -410,7 +410,7 @@ impl<T> Option<T> {
/// Convert an `Option<String>` into an `Option<uint>`, consuming the original:
///
/// ```
/// let num_as_str: Option<String> = Some("10".to_string());
/// let num_as_str: Option<String> = Some("10".into_string());
/// // `Option::map` takes self *by value*, consuming `num_as_str`
/// let num_as_int: Option<uint> = num_as_str.map(|n| n.len());
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.map_err(stringify), Ok(2u));
///
/// let x: Result<uint, uint> = Err(13);
/// assert_eq!(x.map_err(stringify), Err("error code: 13".to_string()));
/// assert_eq!(x.map_err(stringify), Err("error code: 13".into_string()));
/// ```
#[inline]
#[unstable = "waiting for unboxed closures"]
Expand Down
4 changes: 2 additions & 2 deletions src/libcoretest/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn test_swap() {

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

unsafe {
assert!(vec![76u8] == transmute::<_, Vec<u8>>("L".to_string()));
assert!(vec![76u8] == transmute::<_, Vec<u8>>("L".into_string()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcoretest/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn test_get_ptr() {

#[test]
fn test_get_str() {
let x = "test".to_string();
let x = "test".into_string();
let addr_x = x.as_ptr();
let opt = Some(x);
let y = opt.unwrap();
Expand Down Expand Up @@ -134,7 +134,7 @@ fn test_or_else() {
#[test]
fn test_unwrap() {
assert_eq!(Some(1i).unwrap(), 1);
let s = Some("hello".to_string()).unwrap();
let s = Some("hello".into_string()).unwrap();
assert_eq!(s, "hello");
}

Expand Down
Loading