Skip to content

Commit 12b7b44

Browse files
committedDec 6, 2014
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
2 parents 6f4c11b + f569d5c commit 12b7b44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+956
-990
lines changed
 

‎src/liballoc/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ mod tests {
521521
#[test]
522522
fn show_arc() {
523523
let a = Arc::new(5u32);
524-
assert!(format!("{}", a).as_slice() == "5")
524+
assert!(format!("{}", a) == "5")
525525
}
526526

527527
// Make sure deriving works with Arc<T>

‎src/liballoc/boxed.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ mod test {
169169
let b = box Test as Box<Any>;
170170
let a_str = a.to_str();
171171
let b_str = b.to_str();
172-
assert_eq!(a_str.as_slice(), "Box<Any>");
173-
assert_eq!(b_str.as_slice(), "Box<Any>");
172+
assert_eq!(a_str, "Box<Any>");
173+
assert_eq!(b_str, "Box<Any>");
174174

175175
let a = &8u as &Any;
176176
let b = &Test as &Any;
177177
let s = format!("{}", a);
178-
assert_eq!(s.as_slice(), "&Any");
178+
assert_eq!(s, "&Any");
179179
let s = format!("{}", b);
180-
assert_eq!(s.as_slice(), "&Any");
180+
assert_eq!(s, "&Any");
181181
}
182182
}

0 commit comments

Comments
 (0)