summary refs log tree commit diff
path: root/src/libstd/collections
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-12-08 02:32:31 +0000
committerbors <bors@rust-lang.org>2014-12-08 02:32:31 +0000
commit83a44c7fa676b4e5e546ce3d4624e585f9a1e899 (patch)
tree36d7db1d2567d86816d4ac6a1ec86276974dbc65 /src/libstd/collections
parent8bca470c5acf13aa20022a2c462a89f72de721fc (diff)
parent1fea900de7f11d665086141806246842c03b9fc5 (diff)
downloadrust-83a44c7fa676b4e5e546ce3d4624e585f9a1e899.tar.gz
rust-83a44c7fa676b4e5e546ce3d4624e585f9a1e899.zip
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 
Diffstat (limited to 'src/libstd/collections')
-rw-r--r--src/libstd/collections/hash/map.rs34
-rw-r--r--src/libstd/collections/hash/set.rs6
-rw-r--r--src/libstd/collections/lru_cache.rs12
3 files changed, 26 insertions, 26 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index 8f879bd50d0..a8dce232d26 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -1548,7 +1548,7 @@ mod test_map {
 
             DROP_VECTOR.with(|v| {
                 for i in range(0u, 200) {
-                    assert_eq!(v.borrow().as_slice()[i], 0);
+                    assert_eq!(v.borrow()[i], 0);
                 }
             });
 
@@ -1560,7 +1560,7 @@ mod test_map {
 
             DROP_VECTOR.with(|v| {
                 for i in range(0u, 200) {
-                    assert_eq!(v.borrow().as_slice()[i], 1);
+                    assert_eq!(v.borrow()[i], 1);
                 }
             });
 
@@ -1571,27 +1571,27 @@ mod test_map {
                 assert!(v.is_some());
 
                 DROP_VECTOR.with(|v| {
-                    assert_eq!(v.borrow().as_slice()[i], 1);
-                    assert_eq!(v.borrow().as_slice()[i+100], 1);
+                    assert_eq!(v.borrow()[i], 1);
+                    assert_eq!(v.borrow()[i+100], 1);
                 });
             }
 
             DROP_VECTOR.with(|v| {
                 for i in range(0u, 50) {
-                    assert_eq!(v.borrow().as_slice()[i], 0);
-                    assert_eq!(v.borrow().as_slice()[i+100], 0);
+                    assert_eq!(v.borrow()[i], 0);
+                    assert_eq!(v.borrow()[i+100], 0);
                 }
 
                 for i in range(50u, 100) {
-                    assert_eq!(v.borrow().as_slice()[i], 1);
-                    assert_eq!(v.borrow().as_slice()[i+100], 1);
+                    assert_eq!(v.borrow()[i], 1);
+                    assert_eq!(v.borrow()[i+100], 1);
                 }
             });
         }
 
         DROP_VECTOR.with(|v| {
             for i in range(0u, 200) {
-                assert_eq!(v.borrow().as_slice()[i], 0);
+                assert_eq!(v.borrow()[i], 0);
             }
         });
     }
@@ -1607,7 +1607,7 @@ mod test_map {
 
             DROP_VECTOR.with(|v| {
                 for i in range(0u, 200) {
-                    assert_eq!(v.borrow().as_slice()[i], 0);
+                    assert_eq!(v.borrow()[i], 0);
                 }
             });
 
@@ -1619,7 +1619,7 @@ mod test_map {
 
             DROP_VECTOR.with(|v| {
                 for i in range(0u, 200) {
-                    assert_eq!(v.borrow().as_slice()[i], 1);
+                    assert_eq!(v.borrow()[i], 1);
                 }
             });
 
@@ -1634,7 +1634,7 @@ mod test_map {
 
             DROP_VECTOR.with(|v| {
                 for i in range(0u, 200) {
-                    assert_eq!(v.borrow().as_slice()[i], 1);
+                    assert_eq!(v.borrow()[i], 1);
                 }
             });
 
@@ -1642,11 +1642,11 @@ mod test_map {
 
             DROP_VECTOR.with(|v| {
                 let nk = range(0u, 100).filter(|&i| {
-                    v.borrow().as_slice()[i] == 1
+                    v.borrow()[i] == 1
                 }).count();
 
                 let nv = range(0u, 100).filter(|&i| {
-                    v.borrow().as_slice()[i+100] == 1
+                    v.borrow()[i+100] == 1
                 }).count();
 
                 assert_eq!(nk, 50);
@@ -1656,7 +1656,7 @@ mod test_map {
 
         DROP_VECTOR.with(|v| {
             for i in range(0u, 200) {
-                assert_eq!(v.borrow().as_slice()[i], 0);
+                assert_eq!(v.borrow()[i], 0);
             }
         });
     }
@@ -1905,8 +1905,8 @@ mod test_map {
 
         let map_str = format!("{}", map);
 
-        assert!(map_str == "{1: 2, 3: 4}".to_string() || map_str == "{3: 4, 1: 2}".to_string());
-        assert_eq!(format!("{}", empty), "{}".to_string());
+        assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
+        assert_eq!(format!("{}", empty), "{}");
     }
 
     #[test]
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs
index fd32d207e79..b3ccfdbb47c 100644
--- a/src/libstd/collections/hash/set.rs
+++ b/src/libstd/collections/hash/set.rs
@@ -827,7 +827,7 @@ mod test_set {
         };
 
         let v = hs.into_iter().collect::<Vec<char>>();
-        assert!(['a', 'b'][] == v.as_slice() || ['b', 'a'][] == v.as_slice());
+        assert!(['a', 'b'] == v || ['b', 'a'] == v);
     }
 
     #[test]
@@ -862,7 +862,7 @@ mod test_set {
 
         let set_str = format!("{}", set);
 
-        assert!(set_str == "{1, 2}".to_string() || set_str == "{2, 1}".to_string());
-        assert_eq!(format!("{}", empty), "{}".to_string());
+        assert!(set_str == "{1, 2}" || set_str == "{2, 1}");
+        assert_eq!(format!("{}", empty), "{}");
     }
 }
diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs
index adbc135364b..6caa2f7b4da 100644
--- a/src/libstd/collections/lru_cache.rs
+++ b/src/libstd/collections/lru_cache.rs
@@ -447,15 +447,15 @@ mod tests {
         cache.insert(1, 10);
         cache.insert(2, 20);
         cache.insert(3, 30);
-        assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}".to_string());
+        assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}");
         cache.insert(2, 22);
-        assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}".to_string());
+        assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}");
         cache.insert(6, 60);
-        assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}".to_string());
+        assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}");
         cache.get(&3);
-        assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}".to_string());
+        assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}");
         cache.set_capacity(2);
-        assert_eq!(cache.to_string(), "{3: 30, 6: 60}".to_string());
+        assert_eq!(cache.to_string(), "{3: 30, 6: 60}");
     }
 
     #[test]
@@ -466,6 +466,6 @@ mod tests {
         cache.clear();
         assert!(cache.get(&1).is_none());
         assert!(cache.get(&2).is_none());
-        assert_eq!(cache.to_string(), "{}".to_string());
+        assert_eq!(cache.to_string(), "{}");
     }
 }