Skip to content

Commit b17c3a1

Browse files
author
Jorge Aparicio
committed
libstd: remove unnecessary to_string() calls
1 parent ab17b42 commit b17c3a1

File tree

17 files changed

+96
-96
lines changed

17 files changed

+96
-96
lines changed

src/libstd/ascii.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,13 @@ mod tests {
680680
assert_eq!(v.to_ascii(), b);
681681
assert_eq!("( ;".to_string().to_ascii(), b);
682682

683-
assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string());
684-
assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string());
683+
assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#");
684+
assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#");
685685

686-
assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string());
687-
assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string());
686+
assert_eq!("".to_ascii().to_lowercase().into_string(), "");
687+
assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca");
688688
let mixed = "abcDEFxyz:.;".to_ascii();
689-
assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string());
689+
assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;");
690690

691691
assert!("aBcDeF&?#".to_ascii().eq_ignore_case("AbCdEf&?#".to_ascii()));
692692

@@ -698,12 +698,12 @@ mod tests {
698698

699699
#[test]
700700
fn test_ascii_vec_ng() {
701-
assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string());
702-
assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string());
703-
assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string());
704-
assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string());
701+
assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#");
702+
assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#");
703+
assert_eq!("".to_ascii().to_lowercase().into_string(), "");
704+
assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca");
705705
let mixed = "abcDEFxyz:.;".to_ascii();
706-
assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string());
706+
assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;");
707707
}
708708

709709
#[test]
@@ -720,8 +720,8 @@ mod tests {
720720

721721
#[test]
722722
fn test_ascii_into_string() {
723-
assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;".to_string());
724-
assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;".to_string());
723+
assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;");
724+
assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;");
725725
}
726726

727727
#[test]
@@ -773,8 +773,8 @@ mod tests {
773773

774774
#[test]
775775
fn test_to_ascii_upper() {
776-
assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL".to_string());
777-
assert_eq!("hıKß".to_ascii_upper(), "HıKß".to_string());
776+
assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL");
777+
assert_eq!("hıKß".to_ascii_upper(), "HıKß");
778778

779779
let mut i = 0;
780780
while i <= 500 {
@@ -788,9 +788,9 @@ mod tests {
788788

789789
#[test]
790790
fn test_to_ascii_lower() {
791-
assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl".to_string());
791+
assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl");
792792
// Dotted capital I, Kelvin sign, Sharp S.
793-
assert_eq!("HİKß".to_ascii_lower(), "hİKß".to_string());
793+
assert_eq!("HİKß".to_ascii_lower(), "hİKß");
794794

795795
let mut i = 0;
796796
while i <= 500 {
@@ -806,7 +806,7 @@ mod tests {
806806
fn test_into_ascii_upper() {
807807
assert_eq!(("url()URL()uRl()ürl".to_string()).into_ascii_upper(),
808808
"URL()URL()URL()üRL".to_string());
809-
assert_eq!(("hıKß".to_string()).into_ascii_upper(), "HıKß".to_string());
809+
assert_eq!(("hıKß".to_string()).into_ascii_upper(), "HıKß");
810810

811811
let mut i = 0;
812812
while i <= 500 {
@@ -821,9 +821,9 @@ mod tests {
821821
#[test]
822822
fn test_into_ascii_lower() {
823823
assert_eq!(("url()URL()uRl()Ürl".to_string()).into_ascii_lower(),
824-
"url()url()url()Ürl".to_string());
824+
"url()url()url()Ürl");
825825
// Dotted capital I, Kelvin sign, Sharp S.
826-
assert_eq!(("HİKß".to_string()).into_ascii_lower(), "hİKß".to_string());
826+
assert_eq!(("HİKß".to_string()).into_ascii_lower(), "hİKß");
827827

828828
let mut i = 0;
829829
while i <= 500 {
@@ -859,12 +859,12 @@ mod tests {
859859
#[test]
860860
fn test_to_string() {
861861
let s = Ascii{ chr: b't' }.to_string();
862-
assert_eq!(s, "t".to_string());
862+
assert_eq!(s, "t");
863863
}
864864

865865
#[test]
866866
fn test_show() {
867867
let c = Ascii { chr: b't' };
868-
assert_eq!(format!("{}", c), "t".to_string());
868+
assert_eq!(format!("{}", c), "t");
869869
}
870870
}

src/libstd/collections/hash/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,8 +1903,8 @@ mod test_map {
19031903

19041904
let map_str = format!("{}", map);
19051905

1906-
assert!(map_str == "{1: 2, 3: 4}".to_string() || map_str == "{3: 4, 1: 2}".to_string());
1907-
assert_eq!(format!("{}", empty), "{}".to_string());
1906+
assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
1907+
assert_eq!(format!("{}", empty), "{}");
19081908
}
19091909

19101910
#[test]

src/libstd/collections/hash/set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ mod test_set {
862862

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

865-
assert!(set_str == "{1, 2}".to_string() || set_str == "{2, 1}".to_string());
866-
assert_eq!(format!("{}", empty), "{}".to_string());
865+
assert!(set_str == "{1, 2}" || set_str == "{2, 1}");
866+
assert_eq!(format!("{}", empty), "{}");
867867
}
868868
}

src/libstd/collections/lru_cache.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ mod tests {
446446
cache.insert(1, 10);
447447
cache.insert(2, 20);
448448
cache.insert(3, 30);
449-
assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}".to_string());
449+
assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}");
450450
cache.insert(2, 22);
451-
assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}".to_string());
451+
assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}");
452452
cache.insert(6, 60);
453-
assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}".to_string());
453+
assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}");
454454
cache.get(&3);
455-
assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}".to_string());
455+
assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}");
456456
cache.set_capacity(2);
457-
assert_eq!(cache.to_string(), "{3: 30, 6: 60}".to_string());
457+
assert_eq!(cache.to_string(), "{3: 30, 6: 60}");
458458
}
459459

460460
#[test]
@@ -465,6 +465,6 @@ mod tests {
465465
cache.clear();
466466
assert!(cache.get(&1).is_none());
467467
assert!(cache.get(&2).is_none());
468-
assert_eq!(cache.to_string(), "{}".to_string());
468+
assert_eq!(cache.to_string(), "{}");
469469
}
470470
}

src/libstd/io/mem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ mod test {
592592
writer.write_line("testing").unwrap();
593593
writer.write_str("testing").unwrap();
594594
let mut r = BufReader::new(writer.get_ref());
595-
assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting".to_string());
595+
assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting");
596596
}
597597

598598
#[test]
@@ -602,7 +602,7 @@ mod test {
602602
writer.write_char('\n').unwrap();
603603
writer.write_char('ệ').unwrap();
604604
let mut r = BufReader::new(writer.get_ref());
605-
assert_eq!(r.read_to_string().unwrap(), "a\nệ".to_string());
605+
assert_eq!(r.read_to_string().unwrap(), "a\nệ");
606606
}
607607

608608
#[test]

src/libstd/io/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,14 +2005,14 @@ mod tests {
20052005
fn test_show() {
20062006
use super::*;
20072007

2008-
assert_eq!(format!("{}", USER_READ), "0400".to_string());
2009-
assert_eq!(format!("{}", USER_FILE), "0644".to_string());
2010-
assert_eq!(format!("{}", USER_EXEC), "0755".to_string());
2011-
assert_eq!(format!("{}", USER_RWX), "0700".to_string());
2012-
assert_eq!(format!("{}", GROUP_RWX), "0070".to_string());
2013-
assert_eq!(format!("{}", OTHER_RWX), "0007".to_string());
2014-
assert_eq!(format!("{}", ALL_PERMISSIONS), "0777".to_string());
2015-
assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602".to_string());
2008+
assert_eq!(format!("{}", USER_READ), "0400");
2009+
assert_eq!(format!("{}", USER_FILE), "0644");
2010+
assert_eq!(format!("{}", USER_EXEC), "0755");
2011+
assert_eq!(format!("{}", USER_RWX), "0700");
2012+
assert_eq!(format!("{}", GROUP_RWX), "0070");
2013+
assert_eq!(format!("{}", OTHER_RWX), "0007");
2014+
assert_eq!(format!("{}", ALL_PERMISSIONS), "0777");
2015+
assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602");
20162016
}
20172017

20182018
fn _ensure_buffer_is_object_safe<T: Buffer>(x: &T) -> &Buffer {

src/libstd/io/net/ip.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,10 @@ mod test {
640640
#[test]
641641
fn ipv6_addr_to_string() {
642642
let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280);
643-
assert!(a1.to_string() == "::ffff:192.0.2.128".to_string() ||
644-
a1.to_string() == "::FFFF:192.0.2.128".to_string());
643+
assert!(a1.to_string() == "::ffff:192.0.2.128" ||
644+
a1.to_string() == "::FFFF:192.0.2.128");
645645
assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_string(),
646-
"8:9:a:b:c:d:e:f".to_string());
646+
"8:9:a:b:c:d:e:f");
647647
}
648648

649649
#[test]

src/libstd/io/process.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ mod tests {
810810
fn stdout_works() {
811811
let mut cmd = Command::new("echo");
812812
cmd.arg("foobar").stdout(CreatePipe(false, true));
813-
assert_eq!(run_output(cmd), "foobar\n".to_string());
813+
assert_eq!(run_output(cmd), "foobar\n");
814814
}
815815

816816
#[cfg(all(unix, not(target_os="android")))]
@@ -820,7 +820,7 @@ mod tests {
820820
cmd.arg("-c").arg("pwd")
821821
.cwd(&Path::new("/"))
822822
.stdout(CreatePipe(false, true));
823-
assert_eq!(run_output(cmd), "/\n".to_string());
823+
assert_eq!(run_output(cmd), "/\n");
824824
}
825825

826826
#[cfg(all(unix, not(target_os="android")))]
@@ -835,7 +835,7 @@ mod tests {
835835
drop(p.stdin.take());
836836
let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader);
837837
assert!(p.wait().unwrap().success());
838-
assert_eq!(out, "foobar\n".to_string());
838+
assert_eq!(out, "foobar\n");
839839
}
840840

841841
#[cfg(not(target_os="android"))]
@@ -900,7 +900,7 @@ mod tests {
900900
let output_str = str::from_utf8(output.as_slice()).unwrap();
901901

902902
assert!(status.success());
903-
assert_eq!(output_str.trim().to_string(), "hello".to_string());
903+
assert_eq!(output_str.trim().to_string(), "hello");
904904
// FIXME #7224
905905
if !running_on_valgrind() {
906906
assert_eq!(error, Vec::new());
@@ -941,7 +941,7 @@ mod tests {
941941
let output_str = str::from_utf8(output.as_slice()).unwrap();
942942

943943
assert!(status.success());
944-
assert_eq!(output_str.trim().to_string(), "hello".to_string());
944+
assert_eq!(output_str.trim().to_string(), "hello");
945945
// FIXME #7224
946946
if !running_on_valgrind() {
947947
assert_eq!(error, Vec::new());

src/libstd/io/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ mod tests {
527527
set_stdout(box w);
528528
println!("hello!");
529529
});
530-
assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string());
530+
assert_eq!(r.read_to_string().unwrap(), "hello!\n");
531531
}
532532

533533
#[test]

src/libstd/num/strconv.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,28 +428,28 @@ mod tests {
428428
#[test]
429429
fn test_int_to_str_overflow() {
430430
let mut i8_val: i8 = 127_i8;
431-
assert_eq!(i8_val.to_string(), "127".to_string());
431+
assert_eq!(i8_val.to_string(), "127");
432432

433433
i8_val += 1 as i8;
434-
assert_eq!(i8_val.to_string(), "-128".to_string());
434+
assert_eq!(i8_val.to_string(), "-128");
435435

436436
let mut i16_val: i16 = 32_767_i16;
437-
assert_eq!(i16_val.to_string(), "32767".to_string());
437+
assert_eq!(i16_val.to_string(), "32767");
438438

439439
i16_val += 1 as i16;
440-
assert_eq!(i16_val.to_string(), "-32768".to_string());
440+
assert_eq!(i16_val.to_string(), "-32768");
441441

442442
let mut i32_val: i32 = 2_147_483_647_i32;
443-
assert_eq!(i32_val.to_string(), "2147483647".to_string());
443+
assert_eq!(i32_val.to_string(), "2147483647");
444444

445445
i32_val += 1 as i32;
446-
assert_eq!(i32_val.to_string(), "-2147483648".to_string());
446+
assert_eq!(i32_val.to_string(), "-2147483648");
447447

448448
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
449-
assert_eq!(i64_val.to_string(), "9223372036854775807".to_string());
449+
assert_eq!(i64_val.to_string(), "9223372036854775807");
450450

451451
i64_val += 1 as i64;
452-
assert_eq!(i64_val.to_string(), "-9223372036854775808".to_string());
452+
assert_eq!(i64_val.to_string(), "-9223372036854775808");
453453
}
454454
}
455455

src/libstd/num/uint_macros.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,28 @@ mod tests {
7979
#[test]
8080
fn test_uint_to_str_overflow() {
8181
let mut u8_val: u8 = 255_u8;
82-
assert_eq!(u8_val.to_string(), "255".to_string());
82+
assert_eq!(u8_val.to_string(), "255");
8383

8484
u8_val += 1 as u8;
85-
assert_eq!(u8_val.to_string(), "0".to_string());
85+
assert_eq!(u8_val.to_string(), "0");
8686

8787
let mut u16_val: u16 = 65_535_u16;
88-
assert_eq!(u16_val.to_string(), "65535".to_string());
88+
assert_eq!(u16_val.to_string(), "65535");
8989

9090
u16_val += 1 as u16;
91-
assert_eq!(u16_val.to_string(), "0".to_string());
91+
assert_eq!(u16_val.to_string(), "0");
9292

9393
let mut u32_val: u32 = 4_294_967_295_u32;
94-
assert_eq!(u32_val.to_string(), "4294967295".to_string());
94+
assert_eq!(u32_val.to_string(), "4294967295");
9595

9696
u32_val += 1 as u32;
97-
assert_eq!(u32_val.to_string(), "0".to_string());
97+
assert_eq!(u32_val.to_string(), "0");
9898

9999
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
100-
assert_eq!(u64_val.to_string(), "18446744073709551615".to_string());
100+
assert_eq!(u64_val.to_string(), "18446744073709551615");
101101

102102
u64_val += 1 as u64;
103-
assert_eq!(u64_val.to_string(), "0".to_string());
103+
assert_eq!(u64_val.to_string(), "0");
104104
}
105105

106106
#[test]

src/libstd/path/windows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,9 @@ mod tests {
13211321
#[test]
13221322
fn test_display_str() {
13231323
let path = Path::new("foo");
1324-
assert_eq!(path.display().to_string(), "foo".to_string());
1324+
assert_eq!(path.display().to_string(), "foo");
13251325
let path = Path::new(b"\\");
1326-
assert_eq!(path.filename_display().to_string(), "".to_string());
1326+
assert_eq!(path.filename_display().to_string(), "");
13271327

13281328
let path = Path::new("foo");
13291329
let mo = path.display().as_cow();

src/libstd/rt/backtrace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ mod test {
10121012
macro_rules! t( ($a:expr, $b:expr) => ({
10131013
let mut m = Vec::new();
10141014
super::demangle(&mut m, $a).unwrap();
1015-
assert_eq!(String::from_utf8(m).unwrap(), $b.to_string());
1015+
assert_eq!(String::from_utf8(m).unwrap(), $b);
10161016
}) )
10171017

10181018
#[test]

0 commit comments

Comments
 (0)