From 60338d91c4334e5fdfbd37b298cd5b99e8fc0cdd Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 14:43:55 -0500 Subject: libstd: remove unnecessary `as_slice()` calls --- src/libstd/path/mod.rs | 2 +- src/libstd/path/posix.rs | 38 ++++++++++++++++---------------- src/libstd/path/windows.rs | 54 +++++++++++++++++++++++----------------------- 3 files changed, 47 insertions(+), 47 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index b17106e811f..86d55727a5a 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -941,6 +941,6 @@ mod tests { let input = r"\foo\bar\baz"; let path: WindowsPath = WindowsPath::new(input.to_c_str()); - assert_eq!(path.as_str().unwrap(), input.as_slice()); + assert_eq!(path.as_str().unwrap(), input); } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f6778588add..e76d2ed169d 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -131,7 +131,7 @@ impl GenericPathUnsafe for Path { unsafe fn set_filename_unchecked(&mut self, filename: T) { let filename = filename.container_as_bytes(); match self.sepidx { - None if b".." == self.repr.as_slice() => { + None if b".." == self.repr => { let mut v = Vec::with_capacity(3 + filename.len()); v.push_all(dot_dot_static); v.push(SEP_BYTE); @@ -158,7 +158,7 @@ impl GenericPathUnsafe for Path { self.repr = Path::normalize(v.as_slice()); } } - self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); + self.sepidx = self.repr.rposition_elem(&SEP_BYTE); } unsafe fn push_unchecked(&mut self, path: T) { @@ -174,7 +174,7 @@ impl GenericPathUnsafe for Path { // FIXME: this is slow self.repr = Path::normalize(v.as_slice()); } - self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); + self.sepidx = self.repr.rposition_elem(&SEP_BYTE); } } } @@ -191,7 +191,7 @@ impl GenericPath for Path { fn dirname<'a>(&'a self) -> &'a [u8] { match self.sepidx { - None if b".." == self.repr.as_slice() => self.repr.as_slice(), + None if b".." == self.repr => self.repr.as_slice(), None => dot_static, Some(0) => self.repr[..1], Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(), @@ -201,8 +201,8 @@ impl GenericPath for Path { fn filename<'a>(&'a self) -> Option<&'a [u8]> { match self.sepidx { - None if b"." == self.repr.as_slice() || - b".." == self.repr.as_slice() => None, + None if b"." == self.repr || + b".." == self.repr => None, None => Some(self.repr.as_slice()), Some(idx) if self.repr[idx+1..] == b".." => None, Some(0) if self.repr[1..].is_empty() => None, @@ -212,20 +212,20 @@ impl GenericPath for Path { fn pop(&mut self) -> bool { match self.sepidx { - None if b"." == self.repr.as_slice() => false, + None if b"." == self.repr => false, None => { self.repr = vec![b'.']; self.sepidx = None; true } - Some(0) if b"/" == self.repr.as_slice() => false, + Some(0) if b"/" == self.repr => false, Some(idx) => { if idx == 0 { self.repr.truncate(idx+1); } else { self.repr.truncate(idx); } - self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); + self.sepidx = self.repr.rposition_elem(&SEP_BYTE); true } } @@ -250,7 +250,7 @@ impl GenericPath for Path { } else { let mut ita = self.components(); let mut itb = other.components(); - if b"." == self.repr.as_slice() { + if b"." == self.repr { return match itb.next() { None => true, Some(b) => b != b".." @@ -305,7 +305,7 @@ impl GenericPath for Path { } } } - Some(Path::new(comps.as_slice().connect_vec(&SEP_BYTE))) + Some(Path::new(comps.connect_vec(&SEP_BYTE))) } } @@ -406,7 +406,7 @@ impl Path { // None result means the byte vector didn't need normalizing fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option> { - if is_abs && v.as_slice().is_empty() { + if is_abs && v.is_empty() { return None; } let mut comps: Vec<&'a [u8]> = vec![]; @@ -495,8 +495,8 @@ mod tests { t!(s: Path::new("foo/../../.."), "../.."); t!(s: Path::new("foo/../../bar"), "../bar"); - assert_eq!(Path::new(b"foo/bar").into_vec().as_slice(), b"foo/bar"); - assert_eq!(Path::new(b"/foo/../../bar").into_vec().as_slice(), + assert_eq!(Path::new(b"foo/bar").into_vec(), b"foo/bar"); + assert_eq!(Path::new(b"/foo/../../bar").into_vec(), b"/bar"); let p = Path::new(b"foo/bar\x80"); @@ -536,7 +536,7 @@ mod tests { ($path:expr, $disp:ident, $exp:expr) => ( { let path = Path::new($path); - assert!(path.$disp().to_string().as_slice() == $exp); + assert!(path.$disp().to_string() == $exp); } ) ) @@ -579,9 +579,9 @@ mod tests { { let path = Path::new($path); let f = format!("{}", path.display()); - assert!(f.as_slice() == $exp); + assert!(f == $exp); let f = format!("{}", path.filename_display()); - assert!(f.as_slice() == $expf); + assert!(f == $expf); } ) ) @@ -1179,7 +1179,7 @@ mod tests { let path = Path::new($arg); let comps = path.components().collect::>(); let exp: &[&[u8]] = &[$($exp),*]; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.components().rev().collect::>(); let exp = exp.iter().rev().map(|&x|x).collect::>(); assert_eq!(comps, exp) @@ -1211,7 +1211,7 @@ mod tests { let path = Path::new($arg); let comps = path.str_components().collect::>>(); let exp: &[Option<&str>] = &$exp; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.str_components().rev().collect::>>(); let exp = exp.iter().rev().map(|&x|x).collect::>>(); assert_eq!(comps, exp); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 13891a63330..366e3125c65 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -181,7 +181,7 @@ impl GenericPathUnsafe for Path { unsafe fn set_filename_unchecked(&mut self, filename: T) { let filename = filename.container_as_str().unwrap(); match self.sepidx_or_prefix_len() { - None if ".." == self.repr.as_slice() => { + None if ".." == self.repr => { let mut s = String::with_capacity(3 + filename.len()); s.push_str(".."); s.push(SEP); @@ -191,22 +191,22 @@ impl GenericPathUnsafe for Path { None => { self.update_normalized(filename); } - Some((_,idxa,end)) if self.repr.as_slice().slice(idxa,end) == ".." => { + Some((_,idxa,end)) if self.repr.slice(idxa,end) == ".." => { let mut s = String::with_capacity(end + 1 + filename.len()); - s.push_str(self.repr.as_slice().slice_to(end)); + s.push_str(self.repr.slice_to(end)); s.push(SEP); s.push_str(filename); self.update_normalized(s); } Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => { let mut s = String::with_capacity(idxb + filename.len()); - s.push_str(self.repr.as_slice().slice_to(idxb)); + s.push_str(self.repr.slice_to(idxb)); s.push_str(filename); self.update_normalized(s); } Some((idxb,_,_)) => { let mut s = String::with_capacity(idxb + 1 + filename.len()); - s.push_str(self.repr.as_slice().slice_to(idxb)); + s.push_str(self.repr.slice_to(idxb)); s.push(SEP); s.push_str(filename); self.update_normalized(s); @@ -355,21 +355,21 @@ impl GenericPath for Path { /// Always returns a `Some` value. fn dirname_str<'a>(&'a self) -> Option<&'a str> { Some(match self.sepidx_or_prefix_len() { - None if ".." == self.repr.as_slice() => self.repr.as_slice(), + None if ".." == self.repr => self.repr.as_slice(), None => ".", - Some((_,idxa,end)) if self.repr.as_slice().slice(idxa, end) == ".." => { + Some((_,idxa,end)) if self.repr.slice(idxa, end) == ".." => { self.repr.as_slice() } - Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => { + Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => { self.repr.as_slice() } - Some((0,idxa,_)) => self.repr.as_slice().slice_to(idxa), + Some((0,idxa,_)) => self.repr.slice_to(idxa), Some((idxb,idxa,_)) => { match self.prefix { Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => { - self.repr.as_slice().slice_to(idxa) + self.repr.slice_to(idxa) } - _ => self.repr.as_slice().slice_to(idxb) + _ => self.repr.slice_to(idxb) } } }) @@ -414,14 +414,14 @@ impl GenericPath for Path { #[inline] fn pop(&mut self) -> bool { match self.sepidx_or_prefix_len() { - None if "." == self.repr.as_slice() => false, + None if "." == self.repr => false, None => { self.repr = String::from_str("."); self.sepidx = None; true } Some((idxb,idxa,end)) if idxb == idxa && idxb == end => false, - Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => false, + Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => false, Some((idxb,idxa,_)) => { let trunc = match self.prefix { Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => { @@ -441,15 +441,15 @@ impl GenericPath for Path { if self.prefix.is_some() { Some(Path::new(match self.prefix { Some(DiskPrefix) if self.is_absolute() => { - self.repr.as_slice().slice_to(self.prefix_len()+1) + self.repr.slice_to(self.prefix_len()+1) } Some(VerbatimDiskPrefix) => { - self.repr.as_slice().slice_to(self.prefix_len()+1) + self.repr.slice_to(self.prefix_len()+1) } - _ => self.repr.as_slice().slice_to(self.prefix_len()) + _ => self.repr.slice_to(self.prefix_len()) })) } else if is_vol_relative(self) { - Some(Path::new(self.repr.as_slice().slice_to(1))) + Some(Path::new(self.repr.slice_to(1))) } else { None } @@ -468,7 +468,7 @@ impl GenericPath for Path { fn is_absolute(&self) -> bool { match self.prefix { Some(DiskPrefix) => { - let rest = self.repr.as_slice().slice_from(self.prefix_len()); + let rest = self.repr.slice_from(self.prefix_len()); rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE } Some(_) => true, @@ -490,7 +490,7 @@ impl GenericPath for Path { } else { let mut ita = self.str_components().map(|x|x.unwrap()); let mut itb = other.str_components().map(|x|x.unwrap()); - if "." == self.repr.as_slice() { + if "." == self.repr { return itb.next() != Some(".."); } loop { @@ -826,7 +826,7 @@ impl Path { fn update_sepidx(&mut self) { let s = if self.has_nonsemantic_trailing_slash() { - self.repr.as_slice().slice_to(self.repr.len()-1) + self.repr.slice_to(self.repr.len()-1) } else { self.repr.as_slice() }; let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } else { is_sep_verbatim }); @@ -922,7 +922,7 @@ pub fn make_non_verbatim(path: &Path) -> Option { } // now ensure normalization didn't change anything if repr.slice_from(path.prefix_len()) == - new_path.repr.as_slice().slice_from(new_path.prefix_len()) { + new_path.repr.slice_from(new_path.prefix_len()) { Some(new_path) } else { None @@ -1232,8 +1232,8 @@ mod tests { t!(s: Path::new("foo\\..\\..\\.."), "..\\.."); t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar"); - assert_eq!(Path::new(b"foo\\bar").into_vec().as_slice(), b"foo\\bar"); - assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec().as_slice(), b"\\bar"); + assert_eq!(Path::new(b"foo\\bar").into_vec(), b"foo\\bar"); + assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec(), b"\\bar"); t!(s: Path::new("\\\\a"), "\\a"); t!(s: Path::new("\\\\a\\"), "\\a"); @@ -1340,9 +1340,9 @@ mod tests { { let path = Path::new($path); let f = format!("{}", path.display()); - assert_eq!(f.as_slice(), $exp); + assert_eq!(f, $exp); let f = format!("{}", path.filename_display()); - assert_eq!(f.as_slice(), $expf); + assert_eq!(f, $expf); } ) ) @@ -2245,7 +2245,7 @@ mod tests { let comps = path.str_components().map(|x|x.unwrap()) .collect::>(); let exp: &[&str] = &$exp; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.str_components().rev().map(|x|x.unwrap()) .collect::>(); let exp = exp.iter().rev().map(|&x|x).collect::>(); @@ -2302,7 +2302,7 @@ mod tests { let path = Path::new($path); let comps = path.components().collect::>(); let exp: &[&[u8]] = &$exp; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.components().rev().collect::>(); let exp = exp.iter().rev().map(|&x|x).collect::>(); assert_eq!(comps, exp); -- cgit 1.4.1-3-g733a5 From c2da923fc95e29424a7dac1505d6e8ea50c49b9f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:45:47 -0500 Subject: libstd: remove unnecessary `to_string()` calls --- src/libstd/ascii.rs | 42 ++++++++++++++++++------------------- src/libstd/collections/hash/map.rs | 4 ++-- src/libstd/collections/hash/set.rs | 4 ++-- src/libstd/collections/lru_cache.rs | 12 +++++------ src/libstd/io/mem.rs | 4 ++-- src/libstd/io/mod.rs | 16 +++++++------- src/libstd/io/net/ip.rs | 6 +++--- src/libstd/io/process.rs | 10 ++++----- src/libstd/io/stdio.rs | 2 +- src/libstd/num/strconv.rs | 16 +++++++------- src/libstd/num/uint_macros.rs | 16 +++++++------- src/libstd/path/windows.rs | 4 ++-- src/libstd/rt/backtrace.rs | 2 +- src/libstd/sync/future.rs | 12 +++++------ src/libstd/sys/windows/process.rs | 10 ++++----- src/libstd/task.rs | 10 ++++----- src/libstd/time/duration.rs | 22 +++++++++---------- 17 files changed, 96 insertions(+), 96 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index f31c694098f..a03d946f407 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -680,13 +680,13 @@ mod tests { assert_eq!(v.to_ascii(), b); assert_eq!("( ;".to_string().to_ascii(), b); - assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string()); - assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string()); + assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#"); + assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#"); - assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string()); - assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string()); + assert_eq!("".to_ascii().to_lowercase().into_string(), ""); + assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca"); let mixed = "abcDEFxyz:.;".to_ascii(); - assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string()); + assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;"); assert!("aBcDeF&?#".to_ascii().eq_ignore_case("AbCdEf&?#".to_ascii())); @@ -698,12 +698,12 @@ mod tests { #[test] fn test_ascii_vec_ng() { - assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string()); - assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string()); - assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string()); - assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string()); + assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#"); + assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#"); + assert_eq!("".to_ascii().to_lowercase().into_string(), ""); + assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca"); let mixed = "abcDEFxyz:.;".to_ascii(); - assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string()); + assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;"); } #[test] @@ -720,8 +720,8 @@ mod tests { #[test] fn test_ascii_into_string() { - assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;".to_string()); - assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;".to_string()); + assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;"); + assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;"); } #[test] @@ -773,8 +773,8 @@ mod tests { #[test] fn test_to_ascii_upper() { - assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL".to_string()); - assert_eq!("hıKß".to_ascii_upper(), "HıKß".to_string()); + assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL"); + assert_eq!("hıKß".to_ascii_upper(), "HıKß"); let mut i = 0; while i <= 500 { @@ -788,9 +788,9 @@ mod tests { #[test] fn test_to_ascii_lower() { - assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl".to_string()); + assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl"); // Dotted capital I, Kelvin sign, Sharp S. - assert_eq!("HİKß".to_ascii_lower(), "hİKß".to_string()); + assert_eq!("HİKß".to_ascii_lower(), "hİKß"); let mut i = 0; while i <= 500 { @@ -806,7 +806,7 @@ mod tests { fn test_into_ascii_upper() { assert_eq!(("url()URL()uRl()ürl".to_string()).into_ascii_upper(), "URL()URL()URL()üRL".to_string()); - assert_eq!(("hıKß".to_string()).into_ascii_upper(), "HıKß".to_string()); + assert_eq!(("hıKß".to_string()).into_ascii_upper(), "HıKß"); let mut i = 0; while i <= 500 { @@ -821,9 +821,9 @@ mod tests { #[test] fn test_into_ascii_lower() { assert_eq!(("url()URL()uRl()Ürl".to_string()).into_ascii_lower(), - "url()url()url()Ürl".to_string()); + "url()url()url()Ürl"); // Dotted capital I, Kelvin sign, Sharp S. - assert_eq!(("HİKß".to_string()).into_ascii_lower(), "hİKß".to_string()); + assert_eq!(("HİKß".to_string()).into_ascii_lower(), "hİKß"); let mut i = 0; while i <= 500 { @@ -859,12 +859,12 @@ mod tests { #[test] fn test_to_string() { let s = Ascii{ chr: b't' }.to_string(); - assert_eq!(s, "t".to_string()); + assert_eq!(s, "t"); } #[test] fn test_show() { let c = Ascii { chr: b't' }; - assert_eq!(format!("{}", c), "t".to_string()); + assert_eq!(format!("{}", c), "t"); } } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 1fb6279d004..ef7fe48b1ad 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1903,8 +1903,8 @@ mod test_map { let map_str = format!("{}", map); - assert!(map_str == "{1: 2, 3: 4}".to_string() || map_str == "{3: 4, 1: 2}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); + assert_eq!(format!("{}", empty), "{}"); } #[test] diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 9c9f23369e5..ebf7a29ad3f 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -862,7 +862,7 @@ mod test_set { let set_str = format!("{}", set); - assert!(set_str == "{1, 2}".to_string() || set_str == "{2, 1}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(set_str == "{1, 2}" || set_str == "{2, 1}"); + assert_eq!(format!("{}", empty), "{}"); } } diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index 94bea37d187..638ccdb1112 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -446,15 +446,15 @@ mod tests { cache.insert(1, 10); cache.insert(2, 20); cache.insert(3, 30); - assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}".to_string()); + assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}"); cache.insert(2, 22); - assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}".to_string()); + assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}"); cache.insert(6, 60); - assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}".to_string()); + assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}"); cache.get(&3); - assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}".to_string()); + assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}"); cache.set_capacity(2); - assert_eq!(cache.to_string(), "{3: 30, 6: 60}".to_string()); + assert_eq!(cache.to_string(), "{3: 30, 6: 60}"); } #[test] @@ -465,6 +465,6 @@ mod tests { cache.clear(); assert!(cache.get(&1).is_none()); assert!(cache.get(&2).is_none()); - assert_eq!(cache.to_string(), "{}".to_string()); + assert_eq!(cache.to_string(), "{}"); } } diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index c48f487c95c..078daf8feca 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -592,7 +592,7 @@ mod test { writer.write_line("testing").unwrap(); writer.write_str("testing").unwrap(); let mut r = BufReader::new(writer.get_ref()); - assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting".to_string()); + assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting"); } #[test] @@ -602,7 +602,7 @@ mod test { writer.write_char('\n').unwrap(); writer.write_char('ệ').unwrap(); let mut r = BufReader::new(writer.get_ref()); - assert_eq!(r.read_to_string().unwrap(), "a\nệ".to_string()); + assert_eq!(r.read_to_string().unwrap(), "a\nệ"); } #[test] diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 5a56636ffa4..a9e653e267a 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -2005,14 +2005,14 @@ mod tests { fn test_show() { use super::*; - assert_eq!(format!("{}", USER_READ), "0400".to_string()); - assert_eq!(format!("{}", USER_FILE), "0644".to_string()); - assert_eq!(format!("{}", USER_EXEC), "0755".to_string()); - assert_eq!(format!("{}", USER_RWX), "0700".to_string()); - assert_eq!(format!("{}", GROUP_RWX), "0070".to_string()); - assert_eq!(format!("{}", OTHER_RWX), "0007".to_string()); - assert_eq!(format!("{}", ALL_PERMISSIONS), "0777".to_string()); - assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602".to_string()); + assert_eq!(format!("{}", USER_READ), "0400"); + assert_eq!(format!("{}", USER_FILE), "0644"); + assert_eq!(format!("{}", USER_EXEC), "0755"); + assert_eq!(format!("{}", USER_RWX), "0700"); + assert_eq!(format!("{}", GROUP_RWX), "0070"); + assert_eq!(format!("{}", OTHER_RWX), "0007"); + assert_eq!(format!("{}", ALL_PERMISSIONS), "0777"); + assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602"); } fn _ensure_buffer_is_object_safe(x: &T) -> &Buffer { diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 4812e911cc4..20e2753392c 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -640,10 +640,10 @@ mod test { #[test] fn ipv6_addr_to_string() { let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280); - assert!(a1.to_string() == "::ffff:192.0.2.128".to_string() || - a1.to_string() == "::FFFF:192.0.2.128".to_string()); + assert!(a1.to_string() == "::ffff:192.0.2.128" || + a1.to_string() == "::FFFF:192.0.2.128"); assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_string(), - "8:9:a:b:c:d:e:f".to_string()); + "8:9:a:b:c:d:e:f"); } #[test] diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 53c672b4302..a4ca77e92fa 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -810,7 +810,7 @@ mod tests { fn stdout_works() { let mut cmd = Command::new("echo"); cmd.arg("foobar").stdout(CreatePipe(false, true)); - assert_eq!(run_output(cmd), "foobar\n".to_string()); + assert_eq!(run_output(cmd), "foobar\n"); } #[cfg(all(unix, not(target_os="android")))] @@ -820,7 +820,7 @@ mod tests { cmd.arg("-c").arg("pwd") .cwd(&Path::new("/")) .stdout(CreatePipe(false, true)); - assert_eq!(run_output(cmd), "/\n".to_string()); + assert_eq!(run_output(cmd), "/\n"); } #[cfg(all(unix, not(target_os="android")))] @@ -835,7 +835,7 @@ mod tests { drop(p.stdin.take()); let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader); assert!(p.wait().unwrap().success()); - assert_eq!(out, "foobar\n".to_string()); + assert_eq!(out, "foobar\n"); } #[cfg(not(target_os="android"))] @@ -900,7 +900,7 @@ mod tests { let output_str = str::from_utf8(output.as_slice()).unwrap(); assert!(status.success()); - assert_eq!(output_str.trim().to_string(), "hello".to_string()); + assert_eq!(output_str.trim().to_string(), "hello"); // FIXME #7224 if !running_on_valgrind() { assert_eq!(error, Vec::new()); @@ -941,7 +941,7 @@ mod tests { let output_str = str::from_utf8(output.as_slice()).unwrap(); assert!(status.success()); - assert_eq!(output_str.trim().to_string(), "hello".to_string()); + assert_eq!(output_str.trim().to_string(), "hello"); // FIXME #7224 if !running_on_valgrind() { assert_eq!(error, Vec::new()); diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 89d5b7a8acd..fce1ee7e9b4 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -527,7 +527,7 @@ mod tests { set_stdout(box w); println!("hello!"); }); - assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string()); + assert_eq!(r.read_to_string().unwrap(), "hello!\n"); } #[test] diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index b42286c0308..c87f40f351b 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -428,28 +428,28 @@ mod tests { #[test] fn test_int_to_str_overflow() { let mut i8_val: i8 = 127_i8; - assert_eq!(i8_val.to_string(), "127".to_string()); + assert_eq!(i8_val.to_string(), "127"); i8_val += 1 as i8; - assert_eq!(i8_val.to_string(), "-128".to_string()); + assert_eq!(i8_val.to_string(), "-128"); let mut i16_val: i16 = 32_767_i16; - assert_eq!(i16_val.to_string(), "32767".to_string()); + assert_eq!(i16_val.to_string(), "32767"); i16_val += 1 as i16; - assert_eq!(i16_val.to_string(), "-32768".to_string()); + assert_eq!(i16_val.to_string(), "-32768"); let mut i32_val: i32 = 2_147_483_647_i32; - assert_eq!(i32_val.to_string(), "2147483647".to_string()); + assert_eq!(i32_val.to_string(), "2147483647"); i32_val += 1 as i32; - assert_eq!(i32_val.to_string(), "-2147483648".to_string()); + assert_eq!(i32_val.to_string(), "-2147483648"); let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; - assert_eq!(i64_val.to_string(), "9223372036854775807".to_string()); + assert_eq!(i64_val.to_string(), "9223372036854775807"); i64_val += 1 as i64; - assert_eq!(i64_val.to_string(), "-9223372036854775808".to_string()); + assert_eq!(i64_val.to_string(), "-9223372036854775808"); } } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 7b79e535201..0baefb11cf8 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -79,28 +79,28 @@ mod tests { #[test] fn test_uint_to_str_overflow() { let mut u8_val: u8 = 255_u8; - assert_eq!(u8_val.to_string(), "255".to_string()); + assert_eq!(u8_val.to_string(), "255"); u8_val += 1 as u8; - assert_eq!(u8_val.to_string(), "0".to_string()); + assert_eq!(u8_val.to_string(), "0"); let mut u16_val: u16 = 65_535_u16; - assert_eq!(u16_val.to_string(), "65535".to_string()); + assert_eq!(u16_val.to_string(), "65535"); u16_val += 1 as u16; - assert_eq!(u16_val.to_string(), "0".to_string()); + assert_eq!(u16_val.to_string(), "0"); let mut u32_val: u32 = 4_294_967_295_u32; - assert_eq!(u32_val.to_string(), "4294967295".to_string()); + assert_eq!(u32_val.to_string(), "4294967295"); u32_val += 1 as u32; - assert_eq!(u32_val.to_string(), "0".to_string()); + assert_eq!(u32_val.to_string(), "0"); let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; - assert_eq!(u64_val.to_string(), "18446744073709551615".to_string()); + assert_eq!(u64_val.to_string(), "18446744073709551615"); u64_val += 1 as u64; - assert_eq!(u64_val.to_string(), "0".to_string()); + assert_eq!(u64_val.to_string(), "0"); } #[test] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 366e3125c65..512756ececd 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1321,9 +1321,9 @@ mod tests { #[test] fn test_display_str() { let path = Path::new("foo"); - assert_eq!(path.display().to_string(), "foo".to_string()); + assert_eq!(path.display().to_string(), "foo"); let path = Path::new(b"\\"); - assert_eq!(path.filename_display().to_string(), "".to_string()); + assert_eq!(path.filename_display().to_string(), ""); let path = Path::new("foo"); let mo = path.display().as_cow(); diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 159fc3080e8..93690323d31 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -1012,7 +1012,7 @@ mod test { macro_rules! t( ($a:expr, $b:expr) => ({ let mut m = Vec::new(); super::demangle(&mut m, $a).unwrap(); - assert_eq!(String::from_utf8(m).unwrap(), $b.to_string()); + assert_eq!(String::from_utf8(m).unwrap(), $b); }) ) #[test] diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index 79e0d487cad..a8c9983e5aa 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -153,7 +153,7 @@ mod test { #[test] fn test_from_value() { let mut f = Future::from_value("snail".to_string()); - assert_eq!(f.get(), "snail".to_string()); + assert_eq!(f.get(), "snail"); } #[test] @@ -161,25 +161,25 @@ mod test { let (tx, rx) = channel(); tx.send("whale".to_string()); let mut f = Future::from_receiver(rx); - assert_eq!(f.get(), "whale".to_string()); + assert_eq!(f.get(), "whale"); } #[test] fn test_from_fn() { let mut f = Future::from_fn(proc() "brail".to_string()); - assert_eq!(f.get(), "brail".to_string()); + assert_eq!(f.get(), "brail"); } #[test] fn test_interface_get() { let mut f = Future::from_value("fail".to_string()); - assert_eq!(f.get(), "fail".to_string()); + assert_eq!(f.get(), "fail"); } #[test] fn test_interface_unwrap() { let f = Future::from_value("fail".to_string()); - assert_eq!(f.unwrap(), "fail".to_string()); + assert_eq!(f.unwrap(), "fail"); } #[test] @@ -191,7 +191,7 @@ mod test { #[test] fn test_spawn() { let mut f = Future::spawn(proc() "bale".to_string()); - assert_eq!(f.get(), "bale".to_string()); + assert_eq!(f.get(), "bale"); } #[test] diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 2af5e4890e8..02548bedf02 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -484,24 +484,24 @@ mod tests { assert_eq!( test_wrapper("prog", &["aaa", "bbb", "ccc"]), - "prog aaa bbb ccc".to_string() + "prog aaa bbb ccc" ); assert_eq!( test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa"]), - "\"C:\\Program Files\\blah\\blah.exe\" aaa".to_string() + "\"C:\\Program Files\\blah\\blah.exe\" aaa" ); assert_eq!( test_wrapper("C:\\Program Files\\test", &["aa\"bb"]), - "\"C:\\Program Files\\test\" aa\\\"bb".to_string() + "\"C:\\Program Files\\test\" aa\\\"bb" ); assert_eq!( test_wrapper("echo", &["a b c"]), - "echo \"a b c\"".to_string() + "echo \"a b c\"" ); assert_eq!( test_wrapper("\u03c0\u042f\u97f3\u00e6\u221e", &[]), - "\u03c0\u042f\u97f3\u00e6\u221e".to_string() + "\u03c0\u042f\u97f3\u00e6\u221e" ); } } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index c433dfa08f4..0fb9e5b5c43 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -287,21 +287,21 @@ mod test { #[test] fn test_owned_named_task() { TaskBuilder::new().named("ada lovelace".to_string()).try(proc() { - assert!(name().unwrap() == "ada lovelace".to_string()); + assert!(name().unwrap() == "ada lovelace"); }).map_err(|_| ()).unwrap(); } #[test] fn test_static_named_task() { TaskBuilder::new().named("ada lovelace").try(proc() { - assert!(name().unwrap() == "ada lovelace".to_string()); + assert!(name().unwrap() == "ada lovelace"); }).map_err(|_| ()).unwrap(); } #[test] fn test_send_named_task() { TaskBuilder::new().named("ada lovelace".into_cow()).try(proc() { - assert!(name().unwrap() == "ada lovelace".to_string()); + assert!(name().unwrap() == "ada lovelace"); }).map_err(|_| ()).unwrap(); } @@ -462,7 +462,7 @@ mod test { Err(e) => { type T = String; assert!(e.is::()); - assert_eq!(*e.downcast::().unwrap(), "owned string".to_string()); + assert_eq!(*e.downcast::().unwrap(), "owned string"); } Ok(()) => panic!() } @@ -509,7 +509,7 @@ mod test { assert!(r.is_ok()); let output = reader.read_to_string().unwrap(); - assert_eq!(output, "Hello, world!".to_string()); + assert_eq!(output, "Hello, world!"); } // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index ec2d62ff85c..1c36024bd96 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -538,20 +538,20 @@ mod tests { #[test] fn test_duration_fmt() { - assert_eq!(Duration::zero().to_string(), "PT0S".to_string()); - assert_eq!(Duration::days(42).to_string(), "P42D".to_string()); - assert_eq!(Duration::days(-42).to_string(), "-P42D".to_string()); - assert_eq!(Duration::seconds(42).to_string(), "PT42S".to_string()); - assert_eq!(Duration::milliseconds(42).to_string(), "PT0.042S".to_string()); - assert_eq!(Duration::microseconds(42).to_string(), "PT0.000042S".to_string()); - assert_eq!(Duration::nanoseconds(42).to_string(), "PT0.000000042S".to_string()); + assert_eq!(Duration::zero().to_string(), "PT0S"); + assert_eq!(Duration::days(42).to_string(), "P42D"); + assert_eq!(Duration::days(-42).to_string(), "-P42D"); + assert_eq!(Duration::seconds(42).to_string(), "PT42S"); + assert_eq!(Duration::milliseconds(42).to_string(), "PT0.042S"); + assert_eq!(Duration::microseconds(42).to_string(), "PT0.000042S"); + assert_eq!(Duration::nanoseconds(42).to_string(), "PT0.000000042S"); assert_eq!((Duration::days(7) + Duration::milliseconds(6543)).to_string(), - "P7DT6.543S".to_string()); - assert_eq!(Duration::seconds(-86401).to_string(), "-P1DT1S".to_string()); - assert_eq!(Duration::nanoseconds(-1).to_string(), "-PT0.000000001S".to_string()); + "P7DT6.543S"); + assert_eq!(Duration::seconds(-86401).to_string(), "-P1DT1S"); + assert_eq!(Duration::nanoseconds(-1).to_string(), "-PT0.000000001S"); // the format specifier should have no effect on `Duration` assert_eq!(format!("{:30}", Duration::days(1) + Duration::milliseconds(2345)), - "P1DT2.345S".to_string()); + "P1DT2.345S"); } } -- cgit 1.4.1-3-g733a5