Skip to content

Commit 83a44c7

Browse files
committedDec 8, 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 8bca470 + 1fea900 commit 83a44c7

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
@@ -523,7 +523,7 @@ mod tests {
523523
#[test]
524524
fn show_arc() {
525525
let a = Arc::new(5u32);
526-
assert!(format!("{}", a).as_slice() == "5")
526+
assert!(format!("{}", a) == "5")
527527
}
528528

529529
// 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
@@ -170,14 +170,14 @@ mod test {
170170
let b = box Test as Box<Any>;
171171
let a_str = a.to_str();
172172
let b_str = b.to_str();
173-
assert_eq!(a_str.as_slice(), "Box<Any>");
174-
assert_eq!(b_str.as_slice(), "Box<Any>");
173+
assert_eq!(a_str, "Box<Any>");
174+
assert_eq!(b_str, "Box<Any>");
175175

176176
let a = &8u as &Any;
177177
let b = &Test as &Any;
178178
let s = format!("{}", a);
179-
assert_eq!(s.as_slice(), "&Any");
179+
assert_eq!(s, "&Any");
180180
let s = format!("{}", b);
181-
assert_eq!(s.as_slice(), "&Any");
181+
assert_eq!(s, "&Any");
182182
}
183183
}

0 commit comments

Comments
 (0)
Please sign in to comment.