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:
commit
83a44c7fa6
116 changed files with 954 additions and 988 deletions
|
@ -528,7 +528,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]
|
||||
|
@ -543,6 +543,6 @@ mod tests {
|
|||
panic!("my special message");
|
||||
});
|
||||
let s = r.read_to_string().unwrap();
|
||||
assert!(s.as_slice().contains("my special message"));
|
||||
assert!(s.contains("my special message"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue