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
|
@ -265,7 +265,7 @@ impl<'a> StringReader<'a> {
|
|||
/// Calls `f` with a string slice of the source text spanning from `start`
|
||||
/// up to but excluding `end`.
|
||||
fn with_str_from_to<T>(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T {
|
||||
f(self.filemap.src.as_slice().slice(
|
||||
f(self.filemap.src.slice(
|
||||
self.byte_offset(start).to_uint(),
|
||||
self.byte_offset(end).to_uint()))
|
||||
}
|
||||
|
@ -321,7 +321,6 @@ impl<'a> StringReader<'a> {
|
|||
let last_char = self.curr.unwrap();
|
||||
let next = self.filemap
|
||||
.src
|
||||
.as_slice()
|
||||
.char_range_at(current_byte_offset);
|
||||
let byte_offset_diff = next.next - current_byte_offset;
|
||||
self.pos = self.pos + Pos::from_uint(byte_offset_diff);
|
||||
|
@ -343,7 +342,7 @@ impl<'a> StringReader<'a> {
|
|||
pub fn nextch(&self) -> Option<char> {
|
||||
let offset = self.byte_offset(self.pos).to_uint();
|
||||
if offset < self.filemap.src.len() {
|
||||
Some(self.filemap.src.as_slice().char_at(offset))
|
||||
Some(self.filemap.src.char_at(offset))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue