Remove unnecessary as[_mut]_slice/to_string() calls#19378
Remove unnecessary as[_mut]_slice/to_string() calls#19378japaric wants to merge 35 commits intorust-lang:masterfrom
as[_mut]_slice/to_string() calls#19378Conversation
src/libcollections/vec.rs
Outdated
There was a problem hiding this comment.
Can you explain why the impls above and below compare &**self, whereas this only compares *self?
There was a problem hiding this comment.
These three implementations merely defer their job to the impl PartialEq<[B]> for [A] one, where the signature of eq is fn eq(&Self = &[A], &[B]). The *self vs &**self is just about playing the deref game:
- In this case
selfhas type&&[A]so*selfhas type&[A] - In case above,
selfhas type&Vec<A>,*selfhas typeVec<A>, and the next*actually triggersDeref<[A]>, so&**selfhas type&[A]. - In case below,
selfhas type&&mut [A],*self has type "&mut [A]" (yes, I know the compiler won't actually let you do that), and the next&*is a "explicit immutable reborrow" to get&[A]`.
Equivalently, I could have written &**self in all these three cases.
|
Hey! I've been offline for Thanksgiving but just got back to #19167. Hopefully we can move this through quickly. |
|
@alexcrichton just a heads-up, #19167 has been approved. |
|
@alexcrichton rebased, and tested. |
4ae48bd to
f569d5c
Compare
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
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
|
Ahh, sorry, a recent PR modified an existing test, and I missed that change during my last rebase. I've now amended my mistake and |
|
😢 A syntax error on the android tests, which didn't get parsed when I ran |
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
…ru-at-end-of-analysis-stats analysis-stats: run Salsa's LRU at the end of analysis
Now that we have an overloaded comparison (
==) operator, and thatVec/Stringderef to[T]/stron method calls, manyas_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_stringor theb_string[]notation.This is rebased on top of #19167
cc @alexcrichton @aturon