1
Fork 0

auto merge of #19378 : japaric/rust/no-as-slice, r=alexcrichton

Now that we have an overloaded comparison (`==`) operator, and that `Vec`/`String` deref to `[T]`/`str` on method calls, many `as_slice()`/`as_mut_slice()`/`to_string()` calls have become redundant. This patch removes them. These were the most common patterns:

- `assert_eq(test_output.as_slice(), "ground truth")` -> `assert_eq(test_output, "ground truth")`
- `assert_eq(test_output, "ground truth".to_string())` -> `assert_eq(test_output, "ground truth")`
- `vec.as_mut_slice().sort()` -> `vec.sort()`
- `vec.as_slice().slice(from, to)` -> `vec.slice(from_to)`

---

Note that e.g. `a_string.push_str(b_string.as_slice())` has been left untouched in this PR, since we first need to settle down whether we want to favor the `&*b_string` or the `b_string[]` notation.

This is rebased on top of #19167

cc @alexcrichton @aturon
This commit is contained in:
bors 2014-12-08 02:32:31 +00:00
commit 83a44c7fa6
116 changed files with 954 additions and 988 deletions

View file

@ -678,16 +678,16 @@ mod tests {
assert_eq!(test.to_ascii(), b);
assert_eq!("( ;".to_ascii(), b);
let v = vec![40u8, 32u8, 59u8];
assert_eq!(v.as_slice().to_ascii(), b);
assert_eq!("( ;".to_string().as_slice().to_ascii(), b);
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()));
@ -699,12 +699,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]
@ -721,8 +721,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]
@ -774,14 +774,14 @@ 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ıß".to_ascii_upper(), "Hıß".to_string());
assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL");
assert_eq!("hıß".to_ascii_upper(), "Hıß");
let mut i = 0;
while i <= 500 {
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
else { i };
assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_upper(),
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_upper(),
(from_u32(upper).unwrap()).to_string())
i += 1;
}
@ -789,15 +789,15 @@ 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!("ß".to_ascii_lower(), "ß".to_string());
assert_eq!("ß".to_ascii_lower(), "ß");
let mut i = 0;
while i <= 500 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i };
assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_lower(),
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lower(),
(from_u32(lower).unwrap()).to_string())
i += 1;
}
@ -807,7 +807,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ıß".to_string()).into_ascii_upper(), "Hıß".to_string());
assert_eq!(("hıß".to_string()).into_ascii_upper(), "Hıß");
let mut i = 0;
while i <= 500 {
@ -822,9 +822,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!(("ß".to_string()).into_ascii_lower(), "ß".to_string());
assert_eq!(("ß".to_string()).into_ascii_lower(), "ß");
let mut i = 0;
while i <= 500 {
@ -851,7 +851,7 @@ mod tests {
let c = i;
let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
else { c };
assert!((from_u32(i).unwrap()).to_string().as_slice().eq_ignore_ascii_case(
assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case(
(from_u32(lower).unwrap()).to_string().as_slice()));
i += 1;
}
@ -860,12 +860,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");
}
}