diff options
| author | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
| commit | 474b324eda10440d6568ef872a7307d38e7de95b (patch) | |
| tree | 53fc5aaa615f1c6e5abd757e42a75b3d19ce3abb /src/libstd | |
| parent | 1d00c545ede609b9d43fdf9f252c15da5a66dac7 (diff) | |
| parent | e8fd9d3d0bf0f4974460337df29c0d3ceb514987 (diff) | |
| download | rust-474b324eda10440d6568ef872a7307d38e7de95b.tar.gz rust-474b324eda10440d6568ef872a7307d38e7de95b.zip | |
Auto merge of #21791 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libstd')
40 files changed, 388 insertions, 308 deletions
diff --git a/src/libstd/collections/hash/bench.rs b/src/libstd/collections/hash/bench.rs index 28689767cb0..ce02648b8f2 100644 --- a/src/libstd/collections/hash/bench.rs +++ b/src/libstd/collections/hash/bench.rs @@ -32,7 +32,7 @@ fn new_insert_drop(b : &mut Bencher) { b.iter(|| { let mut m = HashMap::new(); - m.insert(0i, 0i); + m.insert(0, 0); assert_eq!(m.len(), 1); }) } @@ -43,7 +43,7 @@ fn grow_by_insertion(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } @@ -61,12 +61,12 @@ fn find_existing(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } b.iter(|| { - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.contains_key(&i); } }); @@ -78,12 +78,12 @@ fn find_nonexisting(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } b.iter(|| { - for i in range_inclusive(1001i, 2000) { + for i in range_inclusive(1001, 2000) { m.contains_key(&i); } }); @@ -95,11 +95,11 @@ fn hashmap_as_queue(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } - let mut k = 1i; + let mut k = 1; b.iter(|| { m.remove(&k); @@ -114,11 +114,11 @@ fn get_remove_insert(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } - let mut k = 1i; + let mut k = 1; b.iter(|| { m.get(&(k + 400)); diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index a291ec16a62..3e2c7627dbe 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -536,7 +536,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// let s = RandomState::new(); /// let mut map = HashMap::with_hash_state(s); - /// map.insert(1i, 2u); + /// map.insert(1, 2u); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -564,7 +564,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// let s = RandomState::new(); /// let mut map = HashMap::with_capacity_and_hash_state(10, s); - /// map.insert(1i, 2u); + /// map.insert(1, 2u); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -809,7 +809,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -834,7 +834,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -859,7 +859,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -882,7 +882,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -910,7 +910,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -1622,7 +1622,7 @@ mod test_map { fn test_create_capacity_zero() { let mut m = HashMap::with_capacity(0); - assert!(m.insert(1i, 1i).is_none()); + assert!(m.insert(1, 1).is_none()); assert!(m.contains_key(&1)); assert!(!m.contains_key(&0)); @@ -1632,9 +1632,9 @@ mod test_map { fn test_insert() { let mut m = HashMap::new(); assert_eq!(m.len(), 0); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert_eq!(m.len(), 1); - assert!(m.insert(2i, 4i).is_none()); + assert!(m.insert(2, 4).is_none()); assert_eq!(m.len(), 2); assert_eq!(*m.get(&1).unwrap(), 2); assert_eq!(*m.get(&2).unwrap(), 4); @@ -1674,7 +1674,7 @@ mod test_map { #[test] fn test_drops() { DROP_VECTOR.with(|slot| { - *slot.borrow_mut() = repeat(0i).take(200).collect(); + *slot.borrow_mut() = repeat(0).take(200).collect(); }); { @@ -1772,7 +1772,7 @@ mod test_map { } }); - for _ in half {} + for _ in half.by_ref() {} DROP_VECTOR.with(|v| { let nk = (0u..100).filter(|&i| { @@ -1807,10 +1807,10 @@ mod test_map { // Try this a few times to make sure we never screw up the hashmap's // internal state. - for _ in 0i..10 { + for _ in 0..10 { assert!(m.is_empty()); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(m.insert(i, i).is_none()); for j in range_inclusive(1, i) { @@ -1824,12 +1824,12 @@ mod test_map { } } - for i in range_inclusive(1001i, 2000) { + for i in range_inclusive(1001, 2000) { assert!(!m.contains_key(&i)); } // remove forwards - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(m.remove(&i).is_some()); for j in range_inclusive(1, i) { @@ -1841,16 +1841,16 @@ mod test_map { } } - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(!m.contains_key(&i)); } - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(m.insert(i, i).is_none()); } // remove backwards - for i in range_step_inclusive(1000i, 1, -1) { + for i in range_step_inclusive(1000, 1, -1) { assert!(m.remove(&i).is_some()); for j in range_inclusive(i, 1000) { @@ -1867,9 +1867,9 @@ mod test_map { #[test] fn test_find_mut() { let mut m = HashMap::new(); - assert!(m.insert(1i, 12i).is_none()); - assert!(m.insert(2i, 8i).is_none()); - assert!(m.insert(5i, 14i).is_none()); + assert!(m.insert(1, 12).is_none()); + assert!(m.insert(2, 8).is_none()); + assert!(m.insert(5, 14).is_none()); let new = 100; match m.get_mut(&5) { None => panic!(), Some(x) => *x = new @@ -1880,18 +1880,18 @@ mod test_map { #[test] fn test_insert_overwrite() { let mut m = HashMap::new(); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert_eq!(*m.get(&1).unwrap(), 2); - assert!(!m.insert(1i, 3i).is_none()); + assert!(!m.insert(1, 3).is_none()); assert_eq!(*m.get(&1).unwrap(), 3); } #[test] fn test_insert_conflicts() { let mut m = HashMap::with_capacity(4); - assert!(m.insert(1i, 2i).is_none()); - assert!(m.insert(5i, 3i).is_none()); - assert!(m.insert(9i, 4i).is_none()); + assert!(m.insert(1, 2).is_none()); + assert!(m.insert(5, 3).is_none()); + assert!(m.insert(9, 4).is_none()); assert_eq!(*m.get(&9).unwrap(), 4); assert_eq!(*m.get(&5).unwrap(), 3); assert_eq!(*m.get(&1).unwrap(), 2); @@ -1900,7 +1900,7 @@ mod test_map { #[test] fn test_conflict_remove() { let mut m = HashMap::with_capacity(4); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert_eq!(*m.get(&1).unwrap(), 2); assert!(m.insert(5, 3).is_none()); assert_eq!(*m.get(&1).unwrap(), 2); @@ -1917,7 +1917,7 @@ mod test_map { #[test] fn test_is_empty() { let mut m = HashMap::with_capacity(4); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert!(!m.is_empty()); assert!(m.remove(&1).is_some()); assert!(m.is_empty()); @@ -1926,7 +1926,7 @@ mod test_map { #[test] fn test_pop() { let mut m = HashMap::new(); - m.insert(1i, 2i); + m.insert(1, 2); assert_eq!(m.remove(&1), Some(2)); assert_eq!(m.remove(&1), None); } @@ -1950,7 +1950,7 @@ mod test_map { #[test] fn test_keys() { - let vec = vec![(1i, 'a'), (2i, 'b'), (3i, 'c')]; + let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')]; let map = vec.into_iter().collect::<HashMap<int, char>>(); let keys = map.keys().map(|&k| k).collect::<Vec<int>>(); assert_eq!(keys.len(), 3); @@ -1961,7 +1961,7 @@ mod test_map { #[test] fn test_values() { - let vec = vec![(1i, 'a'), (2i, 'b'), (3i, 'c')]; + let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')]; let map = vec.into_iter().collect::<HashMap<int, char>>(); let values = map.values().map(|&v| v).collect::<Vec<char>>(); assert_eq!(values.len(), 3); @@ -1973,8 +1973,8 @@ mod test_map { #[test] fn test_find() { let mut m = HashMap::new(); - assert!(m.get(&1i).is_none()); - m.insert(1i, 2i); + assert!(m.get(&1).is_none()); + m.insert(1, 2); match m.get(&1) { None => panic!(), Some(v) => assert_eq!(*v, 2) @@ -1984,17 +1984,17 @@ mod test_map { #[test] fn test_eq() { let mut m1 = HashMap::new(); - m1.insert(1i, 2i); - m1.insert(2i, 3i); - m1.insert(3i, 4i); + m1.insert(1, 2); + m1.insert(2, 3); + m1.insert(3, 4); let mut m2 = HashMap::new(); - m2.insert(1i, 2i); - m2.insert(2i, 3i); + m2.insert(1, 2); + m2.insert(2, 3); assert!(m1 != m2); - m2.insert(3i, 4i); + m2.insert(3, 4); assert_eq!(m1, m2); } @@ -2004,8 +2004,8 @@ mod test_map { let mut map: HashMap<int, int> = HashMap::new(); let empty: HashMap<int, int> = HashMap::new(); - map.insert(1i, 2i); - map.insert(3i, 4i); + map.insert(1, 2); + map.insert(3, 4); let map_str = format!("{:?}", map); @@ -2127,7 +2127,7 @@ mod test_map { #[test] fn test_from_iter() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2138,7 +2138,7 @@ mod test_map { #[test] fn test_size_hint() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2151,7 +2151,7 @@ mod test_map { #[test] fn test_iter_len() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2164,7 +2164,7 @@ mod test_map { #[test] fn test_mut_size_hint() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let mut map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2177,7 +2177,7 @@ mod test_map { #[test] fn test_iter_mut_len() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let mut map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2213,7 +2213,7 @@ mod test_map { #[test] fn test_entry(){ - let xs = [(1i, 10i), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)]; + let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)]; let mut map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 2b15e50c6fa..3095c2c0e41 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -168,7 +168,7 @@ impl<T, S, H> HashSet<T, S> /// /// let s = RandomState::new(); /// let mut set = HashSet::with_capacity_and_hash_state(10u, s); - /// set.insert(1i); + /// set.insert(1); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -290,8 +290,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Can be seen as `a - b`. /// for x in a.difference(&b) { @@ -299,12 +299,12 @@ impl<T, S, H> HashSet<T, S> /// } /// /// let diff: HashSet<int> = a.difference(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [1i].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [1].iter().map(|&x| x).collect()); /// /// // Note that difference is not symmetric, /// // and `b - a` means something else: /// let diff: HashSet<int> = b.difference(&a).map(|&x| x).collect(); - /// assert_eq!(diff, [4i].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [4].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> { @@ -320,8 +320,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Print 1, 4 in arbitrary order. /// for x in a.symmetric_difference(&b) { @@ -332,7 +332,7 @@ impl<T, S, H> HashSet<T, S> /// let diff2: HashSet<int> = b.symmetric_difference(&a).map(|&x| x).collect(); /// /// assert_eq!(diff1, diff2); - /// assert_eq!(diff1, [1i, 4].iter().map(|&x| x).collect()); + /// assert_eq!(diff1, [1, 4].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>) @@ -346,8 +346,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Print 2, 3 in arbitrary order. /// for x in a.intersection(&b) { @@ -355,7 +355,7 @@ impl<T, S, H> HashSet<T, S> /// } /// /// let diff: HashSet<int> = a.intersection(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [2i, 3].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [2, 3].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> { @@ -371,8 +371,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Print 1, 2, 3, 4 in arbitrary order. /// for x in a.union(&b) { @@ -380,7 +380,7 @@ impl<T, S, H> HashSet<T, S> /// } /// /// let diff: HashSet<int> = a.union(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [1i, 2, 3, 4].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [1, 2, 3, 4].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> { @@ -955,8 +955,8 @@ mod test_set { let mut ys = HashSet::new(); assert!(xs.is_disjoint(&ys)); assert!(ys.is_disjoint(&xs)); - assert!(xs.insert(5i)); - assert!(ys.insert(11i)); + assert!(xs.insert(5)); + assert!(ys.insert(11)); assert!(xs.is_disjoint(&ys)); assert!(ys.is_disjoint(&xs)); assert!(xs.insert(7)); @@ -974,13 +974,13 @@ mod test_set { #[test] fn test_subset_and_superset() { let mut a = HashSet::new(); - assert!(a.insert(0i)); + assert!(a.insert(0)); assert!(a.insert(5)); assert!(a.insert(11)); assert!(a.insert(7)); let mut b = HashSet::new(); - assert!(b.insert(0i)); + assert!(b.insert(0)); assert!(b.insert(7)); assert!(b.insert(19)); assert!(b.insert(250)); @@ -1018,7 +1018,7 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(11i)); + assert!(a.insert(11)); assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(77)); @@ -1026,7 +1026,7 @@ mod test_set { assert!(a.insert(5)); assert!(a.insert(-5)); - assert!(b.insert(2i)); + assert!(b.insert(2)); assert!(b.insert(11)); assert!(b.insert(77)); assert!(b.insert(-9)); @@ -1048,13 +1048,13 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(1i)); + assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(5)); assert!(a.insert(9)); assert!(a.insert(11)); - assert!(b.insert(3i)); + assert!(b.insert(3)); assert!(b.insert(9)); let mut i = 0; @@ -1071,13 +1071,13 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(1i)); + assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(5)); assert!(a.insert(9)); assert!(a.insert(11)); - assert!(b.insert(-2i)); + assert!(b.insert(-2)); assert!(b.insert(3)); assert!(b.insert(9)); assert!(b.insert(14)); @@ -1097,7 +1097,7 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(1i)); + assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(5)); assert!(a.insert(9)); @@ -1106,7 +1106,7 @@ mod test_set { assert!(a.insert(19)); assert!(a.insert(24)); - assert!(b.insert(-2i)); + assert!(b.insert(-2)); assert!(b.insert(1)); assert!(b.insert(5)); assert!(b.insert(9)); @@ -1124,7 +1124,7 @@ mod test_set { #[test] fn test_from_iter() { - let xs = [1i, 2, 3, 4, 5, 6, 7, 8, 9]; + let xs = [1, 2, 3, 4, 5, 6, 7, 8, 9]; let set: HashSet<int> = xs.iter().map(|&x| x).collect(); @@ -1154,13 +1154,13 @@ mod test_set { // I'm keeping them around to prevent a regression. let mut s1 = HashSet::new(); - s1.insert(1i); + s1.insert(1); s1.insert(2); s1.insert(3); let mut s2 = HashSet::new(); - s2.insert(1i); + s2.insert(1); s2.insert(2); assert!(s1 != s2); @@ -1175,7 +1175,7 @@ mod test_set { let mut set: HashSet<int> = HashSet::new(); let empty: HashSet<int> = HashSet::new(); - set.insert(1i); + set.insert(1); set.insert(2); let set_str = format!("{:?}", set); @@ -1201,7 +1201,7 @@ mod test_set { let mut s: HashSet<int> = (1is..100).collect(); // try this a bunch of times to make sure we don't screw up internal state. - for _ in 0i..20 { + for _ in 0..20 { assert_eq!(s.len(), 99); { diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 9e6a45d8bf0..8016a343d67 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -15,7 +15,7 @@ use self::BucketState::*; use clone::Clone; use cmp; use hash::{Hash, Hasher}; -use iter::{Iterator, ExactSizeIterator, count}; +use iter::{Iterator, IteratorExt, ExactSizeIterator, count}; use marker::{Copy, Sized, self}; use mem::{min_align_of, size_of}; use mem; @@ -274,7 +274,7 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> Bucket<K, V, M> { // ... and it's zero at all other times. let maybe_wraparound_dist = (self.idx ^ (self.idx + 1)) & self.table.capacity(); // Finally, we obtain the offset 1 or the offset -cap + 1. - let dist = 1i - (maybe_wraparound_dist as int); + let dist = 1 - (maybe_wraparound_dist as int); self.idx += 1; @@ -921,7 +921,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { #[unsafe_destructor] impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> { fn drop(&mut self) { - for _ in *self {} + for _ in self.by_ref() {} } } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index fdd7aa216d3..2e55c007b55 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -122,7 +122,7 @@ impl Deref for CString { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for CString { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - String::from_utf8_lossy(self.as_bytes()).fmt(f) + fmt::Debug::fmt(&String::from_utf8_lossy(self.as_bytes()), f) } } diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index 4ab43e875cd..8e86aa65196 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -29,10 +29,10 @@ //! ``` //! format!("Hello"); // => "Hello" //! format!("Hello, {}!", "world"); // => "Hello, world!" -//! format!("The number is {}", 1i); // => "The number is 1" -//! format!("{:?}", (3i, 4i)); // => "(3i, 4i)" -//! format!("{value}", value=4i); // => "4" -//! format!("{} {}", 1i, 2u); // => "1 2" +//! format!("The number is {}", 1); // => "The number is 1" +//! format!("{:?}", (3, 4)); // => "(3, 4)" +//! format!("{value}", value=4); // => "4" +//! format!("{} {}", 1, 2u); // => "1 2" //! ``` //! //! From these, you can see that the first argument is a format string. It is @@ -55,7 +55,7 @@ //! the iterator advances. This leads to behavior like this: //! //! ```rust -//! format!("{1} {} {0} {}", 1i, 2i); // => "2 1 1 2" +//! format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2" //! ``` //! //! The internal iterator over the argument has not been advanced by the time @@ -83,8 +83,8 @@ //! //! ``` //! format!("{argument}", argument = "test"); // => "test" -//! format!("{name} {}", 1i, name = 2i); // => "2 1" -//! format!("{a} {c} {b}", a="a", b='b', c=3i); // => "a 3 b" +//! format!("{name} {}", 1, name = 2); // => "2 1" +//! format!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b" //! ``` //! //! It is illegal to put positional parameters (those without names) after @@ -206,7 +206,7 @@ //! let myvector = Vector2D { x: 3, y: 4 }; //! //! println!("{}", myvector); // => "(3, 4)" -//! println!("{:?}", myvector); // => "Vector2D {x: 3i, y:4i}" +//! println!("{:?}", myvector); // => "Vector2D {x: 3, y:4}" //! println!("{:10.3b}", myvector); // => " 5.000" //! } //! ``` @@ -411,9 +411,10 @@ pub use core::fmt::{Display, Debug}; pub use core::fmt::{LowerHex, UpperHex, Pointer}; pub use core::fmt::{LowerExp, UpperExp}; pub use core::fmt::Error; -pub use core::fmt::{Argument, Arguments, write, radix, Radix, RadixFmt}; +pub use core::fmt::{ArgumentV1, Arguments, write, radix, Radix, RadixFmt}; #[doc(hidden)] +#[cfg(stage0)] pub use core::fmt::{argument, argumentuint}; /// The format function takes a precompiled format string and a list of @@ -431,9 +432,7 @@ pub use core::fmt::{argument, argumentuint}; /// let s = fmt::format(format_args!("Hello, {}!", "world")); /// assert_eq!(s, "Hello, world!".to_string()); /// ``` -#[unstable(feature = "std_misc", - reason = "this is an implementation detail of format! and should not \ - be called directly")] +#[stable(feature = "rust1", since = "1.0.0")] pub fn format(args: Arguments) -> string::String { let mut output = string::String::new(); let _ = write!(&mut output, "{}", args); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a016ba8fb0c..96aebb735ef 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -97,7 +97,6 @@ #![crate_name = "std"] #![stable(feature = "rust1", since = "1.0.0")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -106,28 +105,29 @@ html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![allow(unknown_features)] -#![feature(linkage, thread_local, asm)] -#![feature(lang_items, unsafe_destructor)] -#![feature(slicing_syntax, unboxed_closures)] +#![feature(alloc)] #![feature(box_syntax)] -#![feature(old_impl_check)] -#![feature(optin_builtin_traits)] -#![feature(int_uint)] -#![feature(int_uint)] +#![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] +#![feature(lang_items, unsafe_destructor)] #![feature(libc)] -#![feature(alloc)] -#![feature(unicode)] -#![feature(collections)] +#![feature(linkage, thread_local, asm)] +#![feature(old_impl_check)] +#![feature(optin_builtin_traits)] #![feature(rand)] -#![feature(hash)] +#![feature(staged_api)] +#![feature(unboxed_closures)] +#![feature(unicode)] +#![cfg_attr(not(stage0), feature(macro_reexport))] #![cfg_attr(test, feature(test))] // Don't link to std. We are std. #![no_std] #![deny(missing_docs)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap #[cfg(test)] #[macro_use] @@ -310,4 +310,6 @@ mod std { pub use slice; pub use boxed; // used for vec![] + // for-loops + pub use iter; } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9c3285a9d08..e91e8241a55 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -32,7 +32,7 @@ /// # #![allow(unreachable_code)] /// panic!(); /// panic!("this is a terrible mistake!"); -/// panic!(4i); // panic with the value of 4 to be collected elsewhere +/// panic!(4); // panic with the value of 4 to be collected elsewhere /// panic!("this is a {} {message}", "fancy", message = "message"); /// ``` #[macro_export] @@ -68,7 +68,7 @@ macro_rules! panic { /// ``` /// format!("test"); /// format!("hello {}", "world!"); -/// format!("x = {}, y = {y}", 10i, y = 30i); +/// format!("x = {}, y = {y}", 10, y = 30); /// ``` #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] @@ -282,7 +282,7 @@ pub mod builtin { /// # Example /// /// ``` - /// let s = concat!("test", 10i, 'b', true); + /// let s = concat!("test", 10, 'b', true); /// assert_eq!(s, "test10btrue"); /// ``` #[macro_export] diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index d010a5de622..a996ad1f5b3 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -356,11 +356,11 @@ pub fn test_num<T>(ten: T, two: T) where + Rem<Output=T> + Debug + Copy { - assert_eq!(ten.add(two), cast(12i).unwrap()); - assert_eq!(ten.sub(two), cast(8i).unwrap()); - assert_eq!(ten.mul(two), cast(20i).unwrap()); - assert_eq!(ten.div(two), cast(5i).unwrap()); - assert_eq!(ten.rem(two), cast(0i).unwrap()); + assert_eq!(ten.add(two), cast(12).unwrap()); + assert_eq!(ten.sub(two), cast(8).unwrap()); + assert_eq!(ten.mul(two), cast(20).unwrap()); + assert_eq!(ten.div(two), cast(5).unwrap()); + assert_eq!(ten.rem(two), cast(0).unwrap()); assert_eq!(ten.add(two), ten + two); assert_eq!(ten.sub(two), ten - two); @@ -393,7 +393,7 @@ mod tests { assert_eq!(20u16, _20.to_u16().unwrap()); assert_eq!(20u32, _20.to_u32().unwrap()); assert_eq!(20u64, _20.to_u64().unwrap()); - assert_eq!(20i, _20.to_int().unwrap()); + assert_eq!(20, _20.to_int().unwrap()); assert_eq!(20i8, _20.to_i8().unwrap()); assert_eq!(20i16, _20.to_i16().unwrap()); assert_eq!(20i32, _20.to_i32().unwrap()); @@ -406,7 +406,7 @@ mod tests { assert_eq!(_20, NumCast::from(20u16).unwrap()); assert_eq!(_20, NumCast::from(20u32).unwrap()); assert_eq!(_20, NumCast::from(20u64).unwrap()); - assert_eq!(_20, NumCast::from(20i).unwrap()); + assert_eq!(_20, NumCast::from(20).unwrap()); assert_eq!(_20, NumCast::from(20i8).unwrap()); assert_eq!(_20, NumCast::from(20i16).unwrap()); assert_eq!(_20, NumCast::from(20i32).unwrap()); @@ -419,7 +419,7 @@ mod tests { assert_eq!(_20, cast(20u16).unwrap()); assert_eq!(_20, cast(20u32).unwrap()); assert_eq!(_20, cast(20u64).unwrap()); - assert_eq!(_20, cast(20i).unwrap()); + assert_eq!(_20, cast(20).unwrap()); assert_eq!(_20, cast(20i8).unwrap()); assert_eq!(_20, cast(20i16).unwrap()); assert_eq!(_20, cast(20i32).unwrap()); @@ -438,7 +438,7 @@ mod tests { #[test] fn test_i16_cast() { test_cast_20!(20i16) } #[test] fn test_i32_cast() { test_cast_20!(20i32) } #[test] fn test_i64_cast() { test_cast_20!(20i64) } - #[test] fn test_int_cast() { test_cast_20!(20i) } + #[test] fn test_int_cast() { test_cast_20!(20) } #[test] fn test_f32_cast() { test_cast_20!(20f32) } #[test] fn test_f64_cast() { test_cast_20!(20f64) } @@ -831,23 +831,23 @@ mod tests { #[test] fn test_saturating_add_int() { use int::{MIN,MAX}; - assert_eq!(3i.saturating_add(5i), 8i); - assert_eq!(3i.saturating_add(MAX-1), MAX); + assert_eq!(3.saturating_add(5), 8); + assert_eq!(3.saturating_add(MAX-1), MAX); assert_eq!(MAX.saturating_add(MAX), MAX); assert_eq!((MAX-2).saturating_add(1), MAX-1); - assert_eq!(3i.saturating_add(-5i), -2i); - assert_eq!(MIN.saturating_add(-1i), MIN); - assert_eq!((-2i).saturating_add(-MAX), MIN); + assert_eq!(3.saturating_add(-5), -2); + assert_eq!(MIN.saturating_add(-1), MIN); + assert_eq!((-2).saturating_add(-MAX), MIN); } #[test] fn test_saturating_sub_int() { use int::{MIN,MAX}; - assert_eq!(3i.saturating_sub(5i), -2i); - assert_eq!(MIN.saturating_sub(1i), MIN); - assert_eq!((-2i).saturating_sub(MAX), MIN); - assert_eq!(3i.saturating_sub(-5i), 8i); - assert_eq!(3i.saturating_sub(-(MAX-1)), MAX); + assert_eq!(3.saturating_sub(5), -2); + assert_eq!(MIN.saturating_sub(1), MIN); + assert_eq!((-2).saturating_sub(MAX), MIN); + assert_eq!(3.saturating_sub(-5), 8); + assert_eq!(3.saturating_sub(-(MAX-1)), MAX); assert_eq!(MAX.saturating_sub(-MAX), MAX); assert_eq!((MAX-2).saturating_sub(-1), MAX-1); } @@ -1010,10 +1010,10 @@ mod tests { assert_eq!(result, naive_pow($num, $exp)); }} } - assert_pow!((3i, 0 ) => 1); - assert_pow!((5i, 1 ) => 5); - assert_pow!((-4i, 2 ) => 16); - assert_pow!((8i, 3 ) => 512); + assert_pow!((3, 0 ) => 1); + assert_pow!((5, 1 ) => 5); + assert_pow!((-4, 2 ) => 16); + assert_pow!((8, 3 ) => 512); assert_pow!((2u64, 50) => 1125899906842624); } } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 82c55d7b5b8..4cd6391318f 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -20,7 +20,7 @@ mod tests { use num::FromStrRadix; fn from_str<T: ::str::FromStr>(t: &str) -> Option<T> { - ::str::FromStr::from_str(t) + ::str::FromStr::from_str(t).ok() } #[test] @@ -38,15 +38,15 @@ mod tests { #[test] pub fn test_parse_bytes() { - assert_eq!(FromStrRadix::from_str_radix("123", 10), Some(123u as $T)); - assert_eq!(FromStrRadix::from_str_radix("1001", 2), Some(9u as $T)); - assert_eq!(FromStrRadix::from_str_radix("123", 8), Some(83u as $T)); - assert_eq!(FromStrRadix::from_str_radix("123", 16), Some(291u as u16)); - assert_eq!(FromStrRadix::from_str_radix("ffff", 16), Some(65535u as u16)); - assert_eq!(FromStrRadix::from_str_radix("z", 36), Some(35u as $T)); - - assert_eq!(FromStrRadix::from_str_radix("Z", 10), None::<$T>); - assert_eq!(FromStrRadix::from_str_radix("_", 2), None::<$T>); + assert_eq!(FromStrRadix::from_str_radix("123", 10), Ok(123u as $T)); + assert_eq!(FromStrRadix::from_str_radix("1001", 2), Ok(9u as $T)); + assert_eq!(FromStrRadix::from_str_radix("123", 8), Ok(83u as $T)); + assert_eq!(FromStrRadix::from_str_radix("123", 16), Ok(291u as u16)); + assert_eq!(FromStrRadix::from_str_radix("ffff", 16), Ok(65535u as u16)); + assert_eq!(FromStrRadix::from_str_radix("z", 36), Ok(35u as $T)); + + assert_eq!(FromStrRadix::from_str_radix("Z", 10).ok(), None::<$T>); + assert_eq!(FromStrRadix::from_str_radix("_", 2).ok(), None::<$T>); } #[test] diff --git a/src/libstd/old_io/buffered.rs b/src/libstd/old_io/buffered.rs index 1590598c0b8..586cc1477f8 100644 --- a/src/libstd/old_io/buffered.rs +++ b/src/libstd/old_io/buffered.rs @@ -111,7 +111,7 @@ impl<R: Reader> Buffer for BufferedReader<R> { impl<R: Reader> Reader for BufferedReader<R> { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { - if self.pos == self.cap && buf.len() >= self.buf.capacity() { + if self.pos == self.cap && buf.len() >= self.buf.len() { return self.inner.read(buf); } let nread = { diff --git a/src/libstd/old_io/fs.rs b/src/libstd/old_io/fs.rs index 99c7e399b1c..1337675544d 100644 --- a/src/libstd/old_io/fs.rs +++ b/src/libstd/old_io/fs.rs @@ -981,7 +981,7 @@ mod test { let initial_msg = "food-is-yummy"; let overwrite_msg = "-the-bar!!"; let final_msg = "foo-the-bar!!"; - let seek_idx = 3i; + let seek_idx = 3; let mut read_mem = [0; 13]; let tmpdir = tmpdir(); let filename = &tmpdir.join("file_rt_io_file_test_seek_and_write.txt"); @@ -1101,10 +1101,10 @@ mod test { let dir = &tmpdir.join("di_readdir"); check!(mkdir(dir, old_io::USER_RWX)); let prefix = "foo"; - for n in 0i..3 { + for n in 0is..3 { let f = dir.join(format!("{}.txt", n)); let mut w = check!(File::create(&f)); - let msg_str = format!("{}{}", prefix, n.to_string()); + let msg_str = format!("{}{}", prefix, n); let msg = msg_str.as_bytes(); check!(w.write(msg)); } diff --git a/src/libstd/old_io/net/ip.rs b/src/libstd/old_io/net/ip.rs index f0b73bd37f2..565f9d83818 100644 --- a/src/libstd/old_io/net/ip.rs +++ b/src/libstd/old_io/net/ip.rs @@ -25,7 +25,7 @@ use iter::{Iterator, IteratorExt}; use ops::{FnOnce, FnMut}; use option::Option; use option::Option::{None, Some}; -use result::Result::{Ok, Err}; +use result::Result::{self, Ok, Err}; use slice::SliceExt; use str::{FromStr, StrExt}; use vec::Vec; @@ -350,17 +350,28 @@ impl<'a> Parser<'a> { } impl FromStr for IpAddr { - fn from_str(s: &str) -> Option<IpAddr> { - Parser::new(s).read_till_eof(|p| p.read_ip_addr()) + type Err = ParseError; + fn from_str(s: &str) -> Result<IpAddr, ParseError> { + match Parser::new(s).read_till_eof(|p| p.read_ip_addr()) { + Some(s) => Ok(s), + None => Err(ParseError), + } } } impl FromStr for SocketAddr { - fn from_str(s: &str) -> Option<SocketAddr> { - Parser::new(s).read_till_eof(|p| p.read_socket_addr()) + type Err = ParseError; + fn from_str(s: &str) -> Result<SocketAddr, ParseError> { + match Parser::new(s).read_till_eof(|p| p.read_socket_addr()) { + Some(s) => Ok(s), + None => Err(ParseError), + } } } +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParseError; + /// A trait for objects which can be converted or resolved to one or more `SocketAddr` values. /// /// Implementing types minimally have to implement either `to_socket_addr` or `to_socket_addr_all` @@ -493,7 +504,7 @@ fn parse_and_resolve_socket_addr(s: &str) -> IoResult<Vec<SocketAddr>> { let mut parts_iter = s.rsplitn(2, ':'); let port_str = try_opt!(parts_iter.next(), "invalid socket address"); let host = try_opt!(parts_iter.next(), "invalid socket address"); - let port: u16 = try_opt!(FromStr::from_str(port_str), "invalid port value"); + let port: u16 = try_opt!(port_str.parse().ok(), "invalid port value"); resolve_socket_addr(host, port) } @@ -502,7 +513,7 @@ impl<'a> ToSocketAddr for (&'a str, u16) { let (host, port) = *self; // try to parse the host as a regular IpAddr first - match FromStr::from_str(host) { + match host.parse().ok() { Some(addr) => return Ok(vec![SocketAddr { ip: addr, port: port @@ -518,7 +529,7 @@ impl<'a> ToSocketAddr for (&'a str, u16) { impl<'a> ToSocketAddr for &'a str { fn to_socket_addr(&self) -> IoResult<SocketAddr> { // try to parse as a regular SocketAddr first - match FromStr::from_str(*self) { + match self.parse().ok() { Some(addr) => return Ok(addr), None => {} } @@ -535,7 +546,7 @@ impl<'a> ToSocketAddr for &'a str { fn to_socket_addr_all(&self) -> IoResult<Vec<SocketAddr>> { // try to parse as a regular SocketAddr first - match FromStr::from_str(*self) { + match self.parse().ok() { Some(addr) => return Ok(vec![addr]), None => {} } @@ -553,95 +564,94 @@ mod test { #[test] fn test_from_str_ipv4() { - assert_eq!(Some(Ipv4Addr(127, 0, 0, 1)), FromStr::from_str("127.0.0.1")); - assert_eq!(Some(Ipv4Addr(255, 255, 255, 255)), FromStr::from_str("255.255.255.255")); - assert_eq!(Some(Ipv4Addr(0, 0, 0, 0)), FromStr::from_str("0.0.0.0")); + assert_eq!(Ok(Ipv4Addr(127, 0, 0, 1)), "127.0.0.1".parse()); + assert_eq!(Ok(Ipv4Addr(255, 255, 255, 255)), "255.255.255.255".parse()); + assert_eq!(Ok(Ipv4Addr(0, 0, 0, 0)), "0.0.0.0".parse()); // out of range - let none: Option<IpAddr> = FromStr::from_str("256.0.0.1"); + let none: Option<IpAddr> = "256.0.0.1".parse().ok(); assert_eq!(None, none); // too short - let none: Option<IpAddr> = FromStr::from_str("255.0.0"); + let none: Option<IpAddr> = "255.0.0".parse().ok(); assert_eq!(None, none); // too long - let none: Option<IpAddr> = FromStr::from_str("255.0.0.1.2"); + let none: Option<IpAddr> = "255.0.0.1.2".parse().ok(); assert_eq!(None, none); // no number between dots - let none: Option<IpAddr> = FromStr::from_str("255.0..1"); + let none: Option<IpAddr> = "255.0..1".parse().ok(); assert_eq!(None, none); } #[test] fn test_from_str_ipv6() { - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), FromStr::from_str("0:0:0:0:0:0:0:0")); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), FromStr::from_str("0:0:0:0:0:0:0:1")); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), "0:0:0:0:0:0:0:0".parse()); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), "0:0:0:0:0:0:0:1".parse()); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), FromStr::from_str("::1")); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), FromStr::from_str("::")); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), "::1".parse()); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), "::".parse()); - assert_eq!(Some(Ipv6Addr(0x2a02, 0x6b8, 0, 0, 0, 0, 0x11, 0x11)), - FromStr::from_str("2a02:6b8::11:11")); + assert_eq!(Ok(Ipv6Addr(0x2a02, 0x6b8, 0, 0, 0, 0, 0x11, 0x11)), + "2a02:6b8::11:11".parse()); // too long group - let none: Option<IpAddr> = FromStr::from_str("::00000"); + let none: Option<IpAddr> = "::00000".parse().ok(); assert_eq!(None, none); // too short - let none: Option<IpAddr> = FromStr::from_str("1:2:3:4:5:6:7"); + let none: Option<IpAddr> = "1:2:3:4:5:6:7".parse().ok(); assert_eq!(None, none); // too long - let none: Option<IpAddr> = FromStr::from_str("1:2:3:4:5:6:7:8:9"); + let none: Option<IpAddr> = "1:2:3:4:5:6:7:8:9".parse().ok(); assert_eq!(None, none); // triple colon - let none: Option<IpAddr> = FromStr::from_str("1:2:::6:7:8"); + let none: Option<IpAddr> = "1:2:::6:7:8".parse().ok(); assert_eq!(None, none); // two double colons - let none: Option<IpAddr> = FromStr::from_str("1:2::6::8"); + let none: Option<IpAddr> = "1:2::6::8".parse().ok(); assert_eq!(None, none); } #[test] fn test_from_str_ipv4_in_ipv6() { - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 49152, 545)), - FromStr::from_str("::192.0.2.33")); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0xFFFF, 49152, 545)), - FromStr::from_str("::FFFF:192.0.2.33")); - assert_eq!(Some(Ipv6Addr(0x64, 0xff9b, 0, 0, 0, 0, 49152, 545)), - FromStr::from_str("64:ff9b::192.0.2.33")); - assert_eq!(Some(Ipv6Addr(0x2001, 0xdb8, 0x122, 0xc000, 0x2, 0x2100, 49152, 545)), - FromStr::from_str("2001:db8:122:c000:2:2100:192.0.2.33")); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 49152, 545)), + "::192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0xFFFF, 49152, 545)), + "::FFFF:192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr(0x64, 0xff9b, 0, 0, 0, 0, 49152, 545)), + "64:ff9b::192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr(0x2001, 0xdb8, 0x122, 0xc000, 0x2, 0x2100, 49152, 545)), + "2001:db8:122:c000:2:2100:192.0.2.33".parse()); // colon after v4 - let none: Option<IpAddr> = FromStr::from_str("::127.0.0.1:"); + let none: Option<IpAddr> = "::127.0.0.1:".parse().ok(); assert_eq!(None, none); // not enough groups - let none: Option<IpAddr> = FromStr::from_str("1.2.3.4.5:127.0.0.1"); + let none: Option<IpAddr> = "1.2.3.4.5:127.0.0.1".parse().ok(); assert_eq!(None, none); // too many groups - let none: Option<IpAddr> = - FromStr::from_str("1.2.3.4.5:6:7:127.0.0.1"); + let none: Option<IpAddr> = "1.2.3.4.5:6:7:127.0.0.1".parse().ok(); assert_eq!(None, none); } #[test] fn test_from_str_socket_addr() { - assert_eq!(Some(SocketAddr { ip: Ipv4Addr(77, 88, 21, 11), port: 80 }), - FromStr::from_str("77.88.21.11:80")); - assert_eq!(Some(SocketAddr { ip: Ipv6Addr(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), port: 53 }), - FromStr::from_str("[2a02:6b8:0:1::1]:53")); - assert_eq!(Some(SocketAddr { ip: Ipv6Addr(0, 0, 0, 0, 0, 0, 0x7F00, 1), port: 22 }), - FromStr::from_str("[::127.0.0.1]:22")); + assert_eq!(Ok(SocketAddr { ip: Ipv4Addr(77, 88, 21, 11), port: 80 }), + "77.88.21.11:80".parse()); + assert_eq!(Ok(SocketAddr { ip: Ipv6Addr(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), port: 53 }), + "[2a02:6b8:0:1::1]:53".parse()); + assert_eq!(Ok(SocketAddr { ip: Ipv6Addr(0, 0, 0, 0, 0, 0, 0x7F00, 1), port: 22 }), + "[::127.0.0.1]:22".parse()); // without port - let none: Option<SocketAddr> = FromStr::from_str("127.0.0.1"); + let none: Option<SocketAddr> = "127.0.0.1".parse().ok(); assert_eq!(None, none); // without port - let none: Option<SocketAddr> = FromStr::from_str("127.0.0.1:"); + let none: Option<SocketAddr> = "127.0.0.1:".parse().ok(); assert_eq!(None, none); // wrong brackets around v4 - let none: Option<SocketAddr> = FromStr::from_str("[127.0.0.1]:22"); + let none: Option<SocketAddr> = "[127.0.0.1]:22".parse().ok(); assert_eq!(None, none); // port out of range - let none: Option<SocketAddr> = FromStr::from_str("127.0.0.1:123456"); + let none: Option<SocketAddr> = "127.0.0.1:123456".parse().ok(); assert_eq!(None, none); } diff --git a/src/libstd/old_io/net/tcp.rs b/src/libstd/old_io/net/tcp.rs index e0feaa4e558..122ac4c3445 100644 --- a/src/libstd/old_io/net/tcp.rs +++ b/src/libstd/old_io/net/tcp.rs @@ -1160,7 +1160,7 @@ mod test { tx.send(TcpStream::connect(addr).unwrap()).unwrap(); }); let _l = rx.recv().unwrap(); - for i in 0i..1001 { + for i in 0is..1001 { match a.accept() { Ok(..) => break, Err(ref e) if e.kind == TimedOut => {} @@ -1260,7 +1260,7 @@ mod test { assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut); s.set_timeout(Some(20)); - for i in 0i..1001 { + for i in 0is..1001 { match s.write(&[0; 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, @@ -1299,7 +1299,7 @@ mod test { assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut); tx.send(()).unwrap(); - for _ in 0i..100 { + for _ in 0..100 { assert!(s.write(&[0;128 * 1024]).is_ok()); } } @@ -1318,7 +1318,7 @@ mod test { let mut s = a.accept().unwrap(); s.set_write_timeout(Some(20)); - for i in 0i..1001 { + for i in 0is..1001 { match s.write(&[0; 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, @@ -1388,7 +1388,7 @@ mod test { }); // Try to ensure that the reading clone is indeed reading - for _ in 0i..50 { + for _ in 0..50 { ::thread::Thread::yield_now(); } diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs index d3e60de2780..f253f9799e9 100644 --- a/src/libstd/old_io/process.rs +++ b/src/libstd/old_io/process.rs @@ -393,14 +393,15 @@ impl Command { } } +#[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for Command { /// Format the program and arguments of a Command for display. Any /// non-utf8 data is lossily converted using the utf8 replacement /// character. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{}", String::from_utf8_lossy(self.program.as_bytes()))); + try!(write!(f, "{:?}", self.program)); for arg in self.args.iter() { - try!(write!(f, " '{}'", String::from_utf8_lossy(arg.as_bytes()))); + try!(write!(f, " '{:?}'", arg)); } Ok(()) } @@ -1142,7 +1143,7 @@ mod tests { fn test_zero() { let mut p = sleeper(); p.signal_kill().unwrap(); - for _ in 0i..20 { + for _ in 0..20 { if p.signal(0).is_err() { assert!(!p.wait().unwrap().success()); return diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 38c0a7b8f9b..600ca60349a 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1484,7 +1484,7 @@ mod tests { #[ignore] fn test_getenv_big() { let mut s = "".to_string(); - let mut i = 0i; + let mut i = 0; while i < 100 { s.push_str("aaaaaaaaaa"); i += 1; diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 588f724134e..6a0c8a93010 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -19,6 +19,7 @@ use iter::{AdditiveIterator, Extend}; use iter::{Iterator, IteratorExt, Map}; use marker::Sized; use option::Option::{self, Some, None}; +use result::Result::{self, Ok, Err}; use slice::{AsSlice, Split, SliceExt, SliceConcatExt}; use str::{self, FromStr, StrExt}; use vec::Vec; @@ -86,11 +87,19 @@ impl Ord for Path { } impl FromStr for Path { - fn from_str(s: &str) -> Option<Path> { - Path::new_opt(s) + type Err = ParsePathError; + fn from_str(s: &str) -> Result<Path, ParsePathError> { + match Path::new_opt(s) { + Some(p) => Ok(p), + None => Err(ParsePathError), + } } } +/// Valuelue indicating that a path could not be parsed from a string. +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParsePathError; + impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Path { #[inline] fn hash(&self, state: &mut S) { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 88db27013ac..b524b89ef9f 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -27,6 +27,7 @@ use mem; use option::Option::{self, Some, None}; #[cfg(stage0)] use ops::FullRange; +use result::Result::{self, Ok, Err}; use slice::{SliceExt, SliceConcatExt}; use str::{SplitTerminator, FromStr, StrExt}; use string::{String, ToString}; @@ -115,11 +116,19 @@ impl Ord for Path { } impl FromStr for Path { - fn from_str(s: &str) -> Option<Path> { - Path::new_opt(s) + type Err = ParsePathError; + fn from_str(s: &str) -> Result<Path, ParsePathError> { + match Path::new_opt(s) { + Some(p) => Ok(p), + None => Err(ParsePathError), + } } } +/// Value indicating that a path could not be parsed from a string. +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParsePathError; + impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Path { #[cfg(not(test))] #[inline] @@ -557,7 +566,7 @@ impl GenericPath for Path { } (Some(a), Some(_)) => { comps.push(".."); - for _ in itb { + for _ in itb.by_ref() { comps.push(".."); } comps.push(a); diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 2969eec4737..211abc2fc83 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -427,7 +427,7 @@ pub fn random<T: Rand>() -> T { /// use std::rand::{thread_rng, sample}; /// /// let mut rng = thread_rng(); -/// let sample = sample(&mut rng, 1i..100, 5); +/// let sample = sample(&mut rng, 1..100, 5); /// println!("{:?}", sample); /// ``` pub fn sample<T, I: Iterator<Item=T>, R: Rng>(rng: &mut R, @@ -481,16 +481,16 @@ mod test { fn test_gen_range() { let mut r = thread_rng(); for _ in 0u..1000 { - let a = r.gen_range(-3i, 42); + let a = r.gen_range(-3, 42); assert!(a >= -3 && a < 42); - assert_eq!(r.gen_range(0i, 1), 0); - assert_eq!(r.gen_range(-12i, -11), -12); + assert_eq!(r.gen_range(0, 1), 0); + assert_eq!(r.gen_range(-12, -11), -12); } for _ in 0u..1000 { - let a = r.gen_range(10i, 42); + let a = r.gen_range(10, 42); assert!(a >= 10 && a < 42); - assert_eq!(r.gen_range(0i, 1), 0); + assert_eq!(r.gen_range(0, 1), 0); assert_eq!(r.gen_range(3_000_000, 3_000_001), 3_000_000); } @@ -500,7 +500,7 @@ mod test { #[should_fail] fn test_gen_range_panic_int() { let mut r = thread_rng(); - r.gen_range(5i, -2); + r.gen_range(5, -2); } #[test] @@ -544,7 +544,7 @@ mod test { #[test] fn test_choose() { let mut r = thread_rng(); - assert_eq!(r.choose(&[1i, 1, 1]).map(|&x|x), Some(1)); + assert_eq!(r.choose(&[1, 1, 1]).map(|&x|x), Some(1)); let v: &[int] = &[]; assert_eq!(r.choose(v), None); @@ -555,16 +555,16 @@ mod test { let mut r = thread_rng(); let empty: &mut [int] = &mut []; r.shuffle(empty); - let mut one = [1i]; + let mut one = [1]; r.shuffle(&mut one); let b: &[_] = &[1]; assert_eq!(one, b); - let mut two = [1i, 2]; + let mut two = [1, 2]; r.shuffle(&mut two); assert!(two == [1, 2] || two == [2, 1]); - let mut x = [1i, 1, 1]; + let mut x = [1, 1, 1]; r.shuffle(&mut x); let b: &[_] = &[1, 1, 1]; assert_eq!(x, b); @@ -574,7 +574,7 @@ mod test { fn test_thread_rng() { let mut r = thread_rng(); r.gen::<int>(); - let mut v = [1i, 1, 1]; + let mut v = [1, 1, 1]; r.shuffle(&mut v); let b: &[_] = &[1, 1, 1]; assert_eq!(v, b); @@ -597,8 +597,8 @@ mod test { #[test] fn test_sample() { - let min_val = 1i; - let max_val = 100i; + let min_val = 1; + let max_val = 100; let mut r = thread_rng(); let vals = (min_val..max_val).collect::<Vec<int>>(); diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 757aecaaaff..fb40a6c8f60 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -160,7 +160,7 @@ pub fn panicking() -> bool { // An uninlined, unmangled function upon which to slap yer breakpoints #[inline(never)] #[no_mangle] -#[allow(private_no_mangle_fns)] +#[cfg_attr(not(stage0), allow(private_no_mangle_fns))] fn rust_panic(cause: Box<Any + Send>) -> ! { rtdebug!("begin_unwind()"); @@ -238,7 +238,7 @@ pub mod eabi { #[lang="eh_personality"] #[no_mangle] // referenced from rust_try.ll - #[allow(private_no_mangle_fns)] + #[cfg_attr(not(stage0), allow(private_no_mangle_fns))] extern fn rust_eh_personality( version: c_int, actions: uw::_Unwind_Action, diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 4023a0a4c10..f5727a38b69 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -51,7 +51,7 @@ pub fn min_stack() -> uint { 0 => {} n => return n - 1, } - let amt = os::getenv("RUST_MIN_STACK").and_then(|s| s.parse()); + let amt = os::getenv("RUST_MIN_STACK").and_then(|s| s.parse().ok()); let amt = amt.unwrap_or(2 * 1024 * 1024); // 0 is our sentinel value, so ensure that we'll never see 0 after // initialization has run @@ -64,7 +64,7 @@ pub fn min_stack() -> uint { pub fn default_sched_threads() -> uint { match os::getenv("RUST_THREADS") { Some(nstr) => { - let opt_n: Option<uint> = nstr.parse(); + let opt_n: Option<uint> = nstr.parse().ok(); match opt_n { Some(n) if n > 0 => n, _ => panic!("`RUST_THREADS` is `{}`, should be a positive integer", nstr) diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index a79fb684f47..8340652d19a 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -193,7 +193,7 @@ mod test { #[test] fn test_get_ref_method() { - let mut f = Future::from_value(22i); + let mut f = Future::from_value(22); assert_eq!(*f.get_ref(), 22); } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 6a43eccbaba..39c57a21d75 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -59,9 +59,9 @@ //! // Create a simple streaming channel //! let (tx, rx) = channel(); //! Thread::spawn(move|| { -//! tx.send(10i).unwrap(); +//! tx.send(10).unwrap(); //! }); -//! assert_eq!(rx.recv().unwrap(), 10i); +//! assert_eq!(rx.recv().unwrap(), 10); //! ``` //! //! Shared usage: @@ -74,14 +74,14 @@ //! // where tx is the sending half (tx for transmission), and rx is the receiving //! // half (rx for receiving). //! let (tx, rx) = channel(); -//! for i in 0i..10i { +//! for i in 0..10 { //! let tx = tx.clone(); //! Thread::spawn(move|| { //! tx.send(i).unwrap(); //! }); //! } //! -//! for _ in 0i..10i { +//! for _ in 0..10 { //! let j = rx.recv().unwrap(); //! assert!(0 <= j && j < 10); //! } @@ -382,8 +382,8 @@ impl<T> !Sync for SyncSender<T> {} /// A `send` operation can only fail if the receiving end of a channel is /// disconnected, implying that the data could never be received. The error /// contains the data being sent as a payload so it can be recovered. -#[derive(PartialEq, Eq)] #[stable(feature = "rust1", since = "1.0.0")] +#[derive(PartialEq, Eq, Clone, Copy)] pub struct SendError<T>(pub T); /// An error returned from the `recv` function on a `Receiver`. @@ -396,7 +396,7 @@ pub struct RecvError; /// This enumeration is the list of the possible reasons that try_recv could not /// return data when called. -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Eq, Clone, Copy, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub enum TryRecvError { /// This channel is currently empty, but the sender(s) have not yet @@ -412,8 +412,8 @@ pub enum TryRecvError { /// This enumeration is the list of the possible error outcomes for the /// `SyncSender::try_send` method. -#[derive(PartialEq, Clone)] #[stable(feature = "rust1", since = "1.0.0")] +#[derive(PartialEq, Eq, Clone, Copy)] pub enum TrySendError<T> { /// The data could not be sent on the channel because it would require that /// the callee block to send the data. @@ -514,15 +514,15 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) { /// let (tx, rx) = sync_channel(1); /// /// // this returns immediately -/// tx.send(1i).unwrap(); +/// tx.send(1).unwrap(); /// /// Thread::spawn(move|| { /// // this will block until the previous message has been received -/// tx.send(2i).unwrap(); +/// tx.send(2).unwrap(); /// }); /// -/// assert_eq!(rx.recv().unwrap(), 1i); -/// assert_eq!(rx.recv().unwrap(), 2i); +/// assert_eq!(rx.recv().unwrap(), 1); +/// assert_eq!(rx.recv().unwrap(), 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) { @@ -562,11 +562,11 @@ impl<T: Send> Sender<T> { /// let (tx, rx) = channel(); /// /// // This send is always successful - /// tx.send(1i).unwrap(); + /// tx.send(1).unwrap(); /// /// // This send will fail because the receiver is gone /// drop(rx); - /// assert_eq!(tx.send(1i).err().unwrap().0, 1); + /// assert_eq!(tx.send(1).err().unwrap().0, 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn send(&self, t: T) -> Result<(), SendError<T>> { @@ -1045,7 +1045,7 @@ mod test { #[test] fn drop_full() { let (tx, _rx) = channel(); - tx.send(box 1i).unwrap(); + tx.send(box 1).unwrap(); } #[test] @@ -1053,7 +1053,7 @@ mod test { let (tx, _rx) = channel(); drop(tx.clone()); drop(tx.clone()); - tx.send(box 1i).unwrap(); + tx.send(box 1).unwrap(); } #[test] @@ -1147,7 +1147,7 @@ mod test { fn stress() { let (tx, rx) = channel::<int>(); let t = Thread::scoped(move|| { - for _ in 0u..10000 { tx.send(1i).unwrap(); } + for _ in 0u..10000 { tx.send(1).unwrap(); } }); for _ in 0u..10000 { assert_eq!(rx.recv().unwrap(), 1); @@ -1187,13 +1187,13 @@ mod test { let (tx2, rx2) = channel::<int>(); let t1 = Thread::scoped(move|| { tx1.send(()).unwrap(); - for _ in 0i..40 { + for _ in 0..40 { assert_eq!(rx2.recv().unwrap(), 1); } }); rx1.recv().unwrap(); let t2 = Thread::scoped(move|| { - for _ in 0i..40 { + for _ in 0..40 { tx2.send(1).unwrap(); } }); @@ -1205,7 +1205,7 @@ mod test { fn recv_from_outside_runtime() { let (tx, rx) = channel::<int>(); let t = Thread::scoped(move|| { - for _ in 0i..40 { + for _ in 0..40 { assert_eq!(rx.recv().unwrap(), 1); } }); @@ -1391,9 +1391,9 @@ mod test { for _ in 0..stress_factor() { let (tx, rx) = channel(); let _t = Thread::spawn(move|| { - tx.send(box 10i).unwrap(); + tx.send(box 10).unwrap(); }); - assert!(rx.recv().unwrap() == box 10i); + assert!(rx.recv().unwrap() == box 10); } } @@ -1429,8 +1429,8 @@ mod test { fn recv_a_lot() { // Regression test that we don't run out of stack in scheduler context let (tx, rx) = channel(); - for _ in 0i..10000 { tx.send(()).unwrap(); } - for _ in 0i..10000 { rx.recv().unwrap(); } + for _ in 0..10000 { tx.send(()).unwrap(); } + for _ in 0..10000 { rx.recv().unwrap(); } } #[test] @@ -1567,7 +1567,7 @@ mod sync_tests { #[test] fn drop_full() { let (tx, _rx) = sync_channel(1); - tx.send(box 1i).unwrap(); + tx.send(box 1).unwrap(); } #[test] @@ -1855,9 +1855,9 @@ mod sync_tests { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::<Box<int>>(0); let _t = Thread::spawn(move|| { - tx.send(box 10i).unwrap(); + tx.send(box 10).unwrap(); }); - assert!(rx.recv().unwrap() == box 10i); + assert!(rx.recv().unwrap() == box 10); } } diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 53eba131674..3980d2a1fef 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -165,8 +165,8 @@ mod tests { #[test] fn test_full() { let q = Queue::new(); - q.push(box 1i); - q.push(box 2i); + q.push(box 1); + q.push(box 2); } #[test] diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index f70e2dee8ee..85c7572404b 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -32,15 +32,15 @@ //! let (tx1, rx1) = channel(); //! let (tx2, rx2) = channel(); //! -//! tx1.send(1i).unwrap(); -//! tx2.send(2i).unwrap(); +//! tx1.send(1).unwrap(); +//! tx2.send(2).unwrap(); //! //! select! { //! val = rx1.recv() => { -//! assert_eq!(val.unwrap(), 1i); +//! assert_eq!(val.unwrap(), 1); //! }, //! val = rx2.recv() => { -//! assert_eq!(val.unwrap(), 2i); +//! assert_eq!(val.unwrap(), 2); //! } //! } //! ``` diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 45503f0b58e..c80aa567173 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -253,9 +253,9 @@ mod test { fn smoke() { unsafe { let queue = Queue::new(0); - queue.push(1i); + queue.push(1); queue.push(2); - assert_eq!(queue.pop(), Some(1i)); + assert_eq!(queue.pop(), Some(1)); assert_eq!(queue.pop(), Some(2)); assert_eq!(queue.pop(), None); queue.push(3); @@ -270,7 +270,7 @@ mod test { fn peek() { unsafe { let queue = Queue::new(0); - queue.push(vec![1i]); + queue.push(vec![1]); // Ensure the borrowchecker works match queue.peek() { @@ -290,8 +290,8 @@ mod test { fn drop_full() { unsafe { let q = Queue::new(0); - q.push(box 1i); - q.push(box 2i); + q.push(box 1); + q.push(box 2); } } @@ -299,7 +299,7 @@ mod test { fn smoke_bound() { unsafe { let q = Queue::new(0); - q.push(1i); + q.push(1); q.push(2); assert_eq!(q.pop(), Some(1)); assert_eq!(q.pop(), Some(2)); @@ -328,7 +328,7 @@ mod test { for _ in 0u..100000 { loop { match q2.pop() { - Some(1i) => break, + Some(1) => break, Some(_) => panic!(), None => {} } @@ -336,7 +336,7 @@ mod test { } tx.send(()).unwrap(); }); - for _ in 0i..100000 { + for _ in 0..100000 { q.push(1); } rx.recv().unwrap(); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index c31010c170d..7531d5b058d 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -428,7 +428,7 @@ mod test { #[test] fn test_arc_condvar_poison() { - let packet = Packet(Arc::new((Mutex::new(1i), Condvar::new()))); + let packet = Packet(Arc::new((Mutex::new(1), Condvar::new()))); let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); @@ -457,7 +457,7 @@ mod test { #[test] fn test_mutex_arc_poison() { - let arc = Arc::new(Mutex::new(1i)); + let arc = Arc::new(Mutex::new(1)); let arc2 = arc.clone(); let _ = Thread::scoped(move|| { let lock = arc2.lock().unwrap(); @@ -470,7 +470,7 @@ mod test { fn test_mutex_arc_nested() { // Tests nested mutexes and access // to underlying data. - let arc = Arc::new(Mutex::new(1i)); + let arc = Arc::new(Mutex::new(1)); let arc2 = Arc::new(Mutex::new(arc)); let (tx, rx) = channel(); let _t = Thread::spawn(move|| { @@ -484,7 +484,7 @@ mod test { #[test] fn test_mutex_arc_access_in_unwind() { - let arc = Arc::new(Mutex::new(1i)); + let arc = Arc::new(Mutex::new(1)); let arc2 = arc.clone(); let _ = Thread::scoped(move|| -> () { struct Unwinder { diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 0604003cecd..2df211f3768 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -134,7 +134,7 @@ mod test { #[test] fn smoke_once() { static O: Once = ONCE_INIT; - let mut a = 0i; + let mut a = 0; O.call_once(|| a += 1); assert_eq!(a, 1); O.call_once(|| a += 1); diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index b5817ad64f6..95b570dd9c8 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -41,7 +41,7 @@ use sys_common::rwlock as sys; /// ``` /// use std::sync::RwLock; /// -/// let lock = RwLock::new(5i); +/// let lock = RwLock::new(5); /// /// // many reader locks can be held at once /// { @@ -437,7 +437,7 @@ mod tests { #[test] fn test_rw_arc_poison_wr() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.write().unwrap(); @@ -448,7 +448,7 @@ mod tests { #[test] fn test_rw_arc_poison_ww() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.write().unwrap(); @@ -459,7 +459,7 @@ mod tests { #[test] fn test_rw_arc_no_poison_rr() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.read().unwrap(); @@ -470,7 +470,7 @@ mod tests { } #[test] fn test_rw_arc_no_poison_rw() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.read().unwrap(); @@ -482,7 +482,7 @@ mod tests { #[test] fn test_rw_arc() { - let arc = Arc::new(RwLock::new(0i)); + let arc = Arc::new(RwLock::new(0)); let arc2 = arc.clone(); let (tx, rx) = channel(); @@ -520,7 +520,7 @@ mod tests { #[test] fn test_rw_arc_access_in_unwind() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _ = Thread::scoped(move|| -> () { struct Unwinder { diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs index c3e12586829..a71676c6bf2 100644 --- a/src/libstd/sys/common/backtrace.rs +++ b/src/libstd/sys/common/backtrace.rs @@ -54,7 +54,7 @@ pub fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { let mut chars = inner.chars(); while valid { let mut i = 0; - for c in chars { + for c in chars.by_ref() { if c.is_numeric() { i = i * 10 + c as uint - '0' as uint; } else { diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index 92b936e74f6..7c9758ca924 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -56,6 +56,10 @@ pub fn stack_guard() -> uint { pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) { THREAD_INFO.with(|c| assert!(c.borrow().is_none())); + match thread.name() { + Some(name) => unsafe { ::sys::thread::set_name(name.as_slice()); }, + None => {} + } THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{ stack_bounds: stack_bounds, stack_guard: stack_guard, diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 5d5cda03f01..dd343baa7c9 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -196,7 +196,7 @@ pub fn load_self() -> Option<Vec<u8>> { #[cfg(target_os = "dragonfly")] pub fn load_self() -> Option<Vec<u8>> { - use std::io; + use old_io; match old_io::fs::readlink(&Path::new("/proc/curproc/file")) { Ok(path) => Some(path.into_vec()), diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 3fcca2f35e1..b004a47f8a3 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -509,7 +509,7 @@ impl Process { // which will wake up the other end at some point, so we just allow this // signal to be coalesced with the pending signals on the pipe. extern fn sigchld_handler(_signum: libc::c_int) { - let msg = 1i; + let msg = 1; match unsafe { libc::write(WRITE_FD, &msg as *const _ as *const libc::c_void, 1) } { diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 2b5ced5085b..a526f3393f2 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -162,7 +162,7 @@ mod imp { pub static SIGSTKSZ: libc::size_t = 8192; - pub const SIG_DFL: sighandler_t = 0i as sighandler_t; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; // This definition is not as accurate as it could be, {si_addr} is // actually a giant union. Currently we're only interested in that field, @@ -214,7 +214,7 @@ mod imp { pub const SIGSTKSZ: libc::size_t = 131072; - pub const SIG_DFL: sighandler_t = 0i as sighandler_t; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; pub type sigset_t = u32; @@ -271,7 +271,7 @@ mod imp { } pub unsafe fn make_handler() -> super::Handler { - super::Handler { _data: 0i as *mut libc::c_void } + super::Handler { _data: 0 as *mut libc::c_void } } pub unsafe fn drop_handler(_handler: &mut super::Handler) { diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index ac51b68795f..26a450b8599 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -17,6 +17,7 @@ use ptr; use libc::consts::os::posix01::{PTHREAD_CREATE_JOINABLE, PTHREAD_STACK_MIN}; use libc; use thunk::Thunk; +use ffi::CString; use sys_common::stack::RED_ZONE; use sys_common::thread::*; @@ -206,6 +207,37 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { native } +#[cfg(any(target_os = "linux", target_os = "android"))] +pub unsafe fn set_name(name: &str) { + // pthread_setname_np() since glibc 2.12 + // availability autodetected via weak linkage + let cname = CString::from_slice(name.as_bytes()); + type F = unsafe extern "C" fn(libc::pthread_t, *const libc::c_char) -> libc::c_int; + extern { + #[linkage = "extern_weak"] + static pthread_setname_np: *const (); + } + if !pthread_setname_np.is_null() { + unsafe { + mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(), cname.as_ptr()); + } + } +} + +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +pub unsafe fn set_name(name: &str) { + // pthread_set_name_np() since almost forever on all BSDs + let cname = CString::from_slice(name.as_bytes()); + pthread_set_name_np(pthread_self(), cname.as_ptr()); +} + +#[cfg(any(target_os = "macos", target_os = "ios"))] +pub unsafe fn set_name(name: &str) { + // pthread_setname_np() since OS X 10.6 and iOS 3.2 + let cname = CString::from_slice(name.as_bytes()); + pthread_setname_np(cname.as_ptr()); +} + pub unsafe fn join(native: rust_thread) { assert_eq!(pthread_join(native, ptr::null_mut()), 0); } @@ -246,7 +278,7 @@ fn min_stack_size(_: *const libc::pthread_attr_t) -> libc::size_t { PTHREAD_STACK_MIN } -#[cfg(any(target_os = "linux"))] +#[cfg(any(target_os = "linux", target_os = "android"))] extern { pub fn pthread_self() -> libc::pthread_t; pub fn pthread_getattr_np(native: libc::pthread_t, @@ -258,11 +290,18 @@ extern { stacksize: *mut libc::size_t) -> libc::c_int; } -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +extern { + pub fn pthread_self() -> libc::pthread_t; + fn pthread_set_name_np(tid: libc::pthread_t, name: *const libc::c_char); +} + +#[cfg(any(target_os = "macos", target_os = "ios"))] extern { pub fn pthread_self() -> libc::pthread_t; pub fn pthread_get_stackaddr_np(thread: libc::pthread_t) -> *mut libc::c_void; pub fn pthread_get_stacksize_np(thread: libc::pthread_t) -> libc::size_t; + fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int; } extern { diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index a186465f234..1be1a412ffa 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -333,7 +333,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> { let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; // And now that we're done with all the setup, do the stack walking! - let mut i = 0i; + let mut i = 0; try!(write!(w, "stack backtrace:\n")); while StackWalk64(image, process, thread, &mut frame, &mut context, ptr::null_mut(), diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs index e8b447022cb..0cb4c573ae3 100644 --- a/src/libstd/sys/windows/stack_overflow.rs +++ b/src/libstd/sys/windows/stack_overflow.rs @@ -81,7 +81,7 @@ pub unsafe fn make_handler() -> Handler { panic!("failed to reserve stack space for exception handling"); } - Handler { _data: 0i as *mut libc::c_void } + Handler { _data: 0 as *mut libc::c_void } } pub struct EXCEPTION_RECORD { diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 30707488b30..a94adcb3bc7 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -67,6 +67,13 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { return ret; } +pub unsafe fn set_name(_name: &str) { + // Windows threads are nameless + // The names in MSVC debugger are obtained using a "magic" exception, + // which requires a use of MS C++ extensions. + // See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx +} + pub unsafe fn join(native: rust_thread) { use libc::consts::os::extra::INFINITE; WaitForSingleObject(native, INFINITE); diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 655195a3c28..0f8ceed39a6 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -235,7 +235,7 @@ unsafe extern "system" fn on_tls_callback(h: LPVOID, unsafe fn run_dtors() { let mut any_run = true; - for _ in 0..5i { + for _ in 0..5 { if !any_run { break } any_run = false; let dtors = { diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 2a911557765..988b13cd160 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -35,9 +35,9 @@ //! let x = ("colorless", "green", "ideas", "sleep", "furiously"); //! assert_eq!(x.3, "sleep"); //! -//! let v = (3i, 3i); -//! let u = (1i, -5i); -//! assert_eq!(v.0 * u.0 + v.1 * u.1, -12i); +//! let v = (3, 3); +//! let u = (1, -5); +//! assert_eq!(v.0 * u.0 + v.1 * u.1, -12); //! ``` //! //! Using traits implemented for tuples: @@ -45,8 +45,8 @@ //! ``` //! use std::default::Default; //! -//! let a = (1i, 2i); -//! let b = (3i, 4i); +//! let a = (1, 2); +//! let b = (3, 4); //! assert!(a != b); //! //! let c = b.clone(); |
