diff options
| author | bors <bors@rust-lang.org> | 2015-02-06 23:30:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-06 23:30:17 +0000 |
| commit | d3732a12e896ab98aa27eaffab99a78bbaf837e4 (patch) | |
| tree | c0d1d61f5e603754ec67ddb0893ff188167a3104 /src/libstd | |
| parent | b75b21cb9b187a6f836da61769a8110354fd6dad (diff) | |
| parent | df7db970dcdb7b7fb1080b9d66baf2e45b689914 (diff) | |
| download | rust-d3732a12e896ab98aa27eaffab99a78bbaf837e4.tar.gz rust-d3732a12e896ab98aa27eaffab99a78bbaf837e4.zip | |
Auto merge of #21997 - Manishearth:rollup, r=alexcrichton
None
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/bench.rs | 2 | ||||
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 162 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 88 | ||||
| -rw-r--r-- | src/libstd/collections/hash/table.rs | 68 | ||||
| -rw-r--r-- | src/libstd/collections/mod.rs | 26 | ||||
| -rw-r--r-- | src/libstd/dynamic_lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/env.rs | 34 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/os.rs | 3 | ||||
| -rwxr-xr-x | src/libstd/path.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rand/os.rs | 1 | ||||
| -rw-r--r-- | src/libstd/rt/unwind.rs | 7 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sync/barrier.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/oneshot.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/poison.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/common/wtf8.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/c.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 23 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread_local.rs | 2 | ||||
| -rw-r--r-- | src/libstd/time/duration.rs | 4 |
22 files changed, 233 insertions, 210 deletions
diff --git a/src/libstd/collections/hash/bench.rs b/src/libstd/collections/hash/bench.rs index ce02648b8f2..ca506e8c36f 100644 --- a/src/libstd/collections/hash/bench.rs +++ b/src/libstd/collections/hash/bench.rs @@ -21,7 +21,7 @@ fn new_drop(b : &mut Bencher) { use super::map::HashMap; b.iter(|| { - let m : HashMap<int, int> = HashMap::new(); + let m : HashMap<i32, i32> = HashMap::new(); assert_eq!(m.len(), 0); }) } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 63270610472..aec9446773f 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -45,9 +45,9 @@ use super::table::BucketState::{ }; use super::state::HashState; -const INITIAL_LOG2_CAP: uint = 5; +const INITIAL_LOG2_CAP: usize = 5; #[unstable(feature = "std_misc")] -pub const INITIAL_CAPACITY: uint = 1 << INITIAL_LOG2_CAP; // 2^5 +pub const INITIAL_CAPACITY: usize = 1 << INITIAL_LOG2_CAP; // 2^5 /// The default behavior of HashMap implements a load factor of 90.9%. /// This behavior is characterized by the following condition: @@ -62,7 +62,7 @@ impl DefaultResizePolicy { } #[inline] - fn min_capacity(&self, usable_size: uint) -> uint { + fn min_capacity(&self, usable_size: usize) -> usize { // Here, we are rephrasing the logic by specifying the lower limit // on capacity: // @@ -72,7 +72,7 @@ impl DefaultResizePolicy { /// An inverse of `min_capacity`, approximately. #[inline] - fn usable_capacity(&self, cap: uint) -> uint { + fn usable_capacity(&self, cap: usize) -> usize { // As the number of entries approaches usable capacity, // min_capacity(size) must be smaller than the internal capacity, // so that the map is not resized: @@ -90,7 +90,7 @@ impl DefaultResizePolicy { fn test_resize_policy() { use prelude::v1::*; let rp = DefaultResizePolicy; - for n in 0u..1000 { + for n in 0..1000 { assert!(rp.min_capacity(rp.usable_capacity(n)) <= n); assert!(rp.usable_capacity(rp.min_capacity(n)) <= n); } @@ -287,9 +287,9 @@ fn test_resize_policy() { /// // Use a HashMap to store the vikings' health points. /// let mut vikings = HashMap::new(); /// -/// vikings.insert(Viking::new("Einar", "Norway"), 25u); -/// vikings.insert(Viking::new("Olaf", "Denmark"), 24u); -/// vikings.insert(Viking::new("Harald", "Iceland"), 12u); +/// vikings.insert(Viking::new("Einar", "Norway"), 25); +/// vikings.insert(Viking::new("Olaf", "Denmark"), 24); +/// vikings.insert(Viking::new("Harald", "Iceland"), 12); /// /// // Use derived implementation to print the status of the vikings. /// for (viking, health) in vikings.iter() { @@ -369,7 +369,7 @@ fn pop_internal<K, V>(starting_bucket: FullBucketMut<K, V>) -> (K, V) { /// /// `hash`, `k`, and `v` are the elements to "robin hood" into the hashtable. fn robin_hood<'a, K: 'a, V: 'a>(mut bucket: FullBucketMut<'a, K, V>, - mut ib: uint, + mut ib: usize, mut hash: SafeHash, mut k: K, mut v: V) @@ -515,7 +515,7 @@ impl<K: Hash<Hasher> + Eq, V> HashMap<K, V, RandomState> { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn with_capacity(capacity: uint) -> HashMap<K, V, RandomState> { + pub fn with_capacity(capacity: usize) -> HashMap<K, V, RandomState> { HashMap::with_capacity_and_hash_state(capacity, Default::default()) } } @@ -537,7 +537,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// let s = RandomState::new(); /// let mut map = HashMap::with_hash_state(s); - /// map.insert(1, 2u); + /// map.insert(1, 2); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -565,11 +565,11 @@ 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(1, 2u); + /// map.insert(1, 2); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] - pub fn with_capacity_and_hash_state(capacity: uint, hash_state: S) + pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) -> HashMap<K, V, S> { let resize_policy = DefaultResizePolicy::new(); let min_cap = max(INITIAL_CAPACITY, resize_policy.min_capacity(capacity)); @@ -593,7 +593,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn capacity(&self) -> uint { + pub fn capacity(&self) -> usize { self.resize_policy.usable_capacity(self.table.capacity()) } @@ -603,7 +603,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// # Panics /// - /// Panics if the new allocation size overflows `uint`. + /// Panics if the new allocation size overflows `usize`. /// /// # Example /// @@ -613,7 +613,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// map.reserve(10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn reserve(&mut self, additional: uint) { + pub fn reserve(&mut self, additional: usize) { let new_size = self.len().checked_add(additional).expect("capacity overflow"); let min_cap = self.resize_policy.min_capacity(new_size); @@ -631,7 +631,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// 1) Make sure the new capacity is enough for all the elements, accounting /// for the load factor. /// 2) Ensure new_capacity is a power of two or zero. - fn resize(&mut self, new_capacity: uint) { + fn resize(&mut self, new_capacity: usize) { assert!(self.table.size() <= new_capacity); assert!(new_capacity.is_power_of_two() || new_capacity == 0); @@ -793,7 +793,7 @@ impl<K, V, S, H> HashMap<K, V, S> if (ib as int) < robin_ib { // Found a luckier bucket than me. Better steal his spot. - return robin_hood(bucket, robin_ib as uint, hash, k, v); + return robin_hood(bucket, robin_ib as usize, hash, k, v); } probe = bucket.next(); @@ -929,10 +929,8 @@ impl<K, V, S, H> HashMap<K, V, S> } /// Gets the given key's corresponding entry in the map for in-place manipulation. - #[unstable(feature = "std_misc", - reason = "precise API still being fleshed out")] - pub fn entry<'a>(&'a mut self, key: K) -> Entry<'a, K, V> - { + #[stable(feature = "rust1", since = "1.0.0")] + pub fn entry(&mut self, key: K) -> Entry<K, V> { // Gotta resize now. self.reserve(1); @@ -949,11 +947,11 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// let mut a = HashMap::new(); /// assert_eq!(a.len(), 0); - /// a.insert(1u, "a"); + /// a.insert(1, "a"); /// assert_eq!(a.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> uint { self.table.size() } + pub fn len(&self) -> usize { self.table.size() } /// Returns true if the map contains no elements. /// @@ -964,7 +962,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// let mut a = HashMap::new(); /// assert!(a.is_empty()); - /// a.insert(1u, "a"); + /// a.insert(1, "a"); /// assert!(!a.is_empty()); /// ``` #[inline] @@ -980,8 +978,8 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut a = HashMap::new(); - /// a.insert(1u, "a"); - /// a.insert(2u, "b"); + /// a.insert(1, "a"); + /// a.insert(2, "b"); /// /// for (k, v) in a.drain().take(1) { /// assert!(k == 1 || k == 2); @@ -1011,7 +1009,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut a = HashMap::new(); - /// a.insert(1u, "a"); + /// a.insert(1, "a"); /// a.clear(); /// assert!(a.is_empty()); /// ``` @@ -1033,7 +1031,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert(1u, "a"); + /// map.insert(1, "a"); /// assert_eq!(map.get(&1), Some(&"a")); /// assert_eq!(map.get(&2), None); /// ``` @@ -1056,7 +1054,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert(1u, "a"); + /// map.insert(1, "a"); /// assert_eq!(map.contains_key(&1), true); /// assert_eq!(map.contains_key(&2), false); /// ``` @@ -1079,7 +1077,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert(1u, "a"); + /// map.insert(1, "a"); /// match map.get_mut(&1) { /// Some(x) => *x = "b", /// None => (), @@ -1102,7 +1100,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// assert_eq!(map.insert(37u, "a"), None); + /// assert_eq!(map.insert(37, "a"), None); /// assert_eq!(map.is_empty(), false); /// /// map.insert(37, "b"); @@ -1134,7 +1132,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert(1u, "a"); + /// map.insert(1, "a"); /// assert_eq!(map.remove(&1), Some("a")); /// assert_eq!(map.remove(&1), None); /// ``` @@ -1188,7 +1186,7 @@ fn search_entry_hashed<'a, K: Eq, V>(table: &'a mut RawTable<K,V>, hash: SafeHas return Vacant(VacantEntry { hash: hash, key: k, - elem: NeqElem(bucket, robin_ib as uint), + elem: NeqElem(bucket, robin_ib as usize), }); } @@ -1371,7 +1369,7 @@ pub enum Entry<'a, K: 'a, V: 'a> { enum VacantEntryState<K, V, M> { /// The index is occupied, but the key to insert has precedence, /// and will kick the current one out on insertion. - NeqElem(FullBucket<K, V, M>, uint), + NeqElem(FullBucket<K, V, M>, usize), /// The index is genuinely vacant. NoElem(EmptyBucket<K, V, M>), } @@ -1496,26 +1494,28 @@ impl<'a, K, V> Entry<'a, K, V> { } } -#[unstable(feature = "std_misc", - reason = "matches collection reform v2 specification, waiting for dust to settle")] impl<'a, K, V> OccupiedEntry<'a, K, V> { /// Gets a reference to the value in the entry. + #[stable(feature = "rust1", since = "1.0.0")] pub fn get(&self) -> &V { self.elem.read().1 } /// Gets a mutable reference to the value in the entry. + #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut(&mut self) -> &mut V { self.elem.read_mut().1 } /// Converts the OccupiedEntry into a mutable reference to the value in the entry /// with a lifetime bound to the map itself + #[stable(feature = "rust1", since = "1.0.0")] pub fn into_mut(self) -> &'a mut V { self.elem.into_mut_refs().1 } /// Sets the value of the entry, and returns the entry's old value + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, mut value: V) -> V { let old_value = self.get_mut(); mem::swap(&mut value, old_value); @@ -1523,16 +1523,16 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { } /// Takes the value out of the entry, and returns it + #[stable(feature = "rust1", since = "1.0.0")] pub fn remove(self) -> V { pop_internal(self.elem).1 } } -#[unstable(feature = "std_misc", - reason = "matches collection reform v2 specification, waiting for dust to settle")] impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> { /// Sets the value of the entry with the VacantEntry's key, /// and returns a mutable reference to it + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(self, value: V) -> &'a mut V { match self.elem { NeqElem(bucket, ib) => { @@ -1580,7 +1580,6 @@ impl<K, V, S, H> Extend<(K, V)> for HashMap<K, V, S> /// `Hasher`, but the hashers created by two different `RandomState` /// instances are unlikely to produce the same result for the same values. #[derive(Clone)] -#[allow(missing_copy_implementations)] #[unstable(feature = "std_misc", reason = "hashing an hash maps may be altered")] pub struct RandomState { @@ -1623,7 +1622,6 @@ impl Default for RandomState { /// This is the default hasher used in a `HashMap` to hash keys. Types do not /// typically declare an ability to explicitly hash into this particular type, /// but rather in a `H: hash::Writer` type parameter. -#[allow(missing_copy_implementations)] #[unstable(feature = "std_misc", reason = "hashing an hash maps may be altered")] pub struct Hasher { inner: SipHasher } @@ -1674,11 +1672,11 @@ mod test_map { #[derive(Hash, PartialEq, Eq)] struct Dropable { - k: uint + k: usize } impl Dropable { - fn new(k: uint) -> Dropable { + fn new(k: usize) -> Dropable { DROP_VECTOR.with(|slot| { slot.borrow_mut()[k] += 1; }); @@ -1711,24 +1709,24 @@ mod test_map { let mut m = HashMap::new(); DROP_VECTOR.with(|v| { - for i in 0u..200 { + for i in 0..200 { assert_eq!(v.borrow()[i], 0); } }); - for i in 0u..100 { + for i in 0..100 { let d1 = Dropable::new(i); let d2 = Dropable::new(i+100); m.insert(d1, d2); } DROP_VECTOR.with(|v| { - for i in 0u..200 { + for i in 0..200 { assert_eq!(v.borrow()[i], 1); } }); - for i in 0u..50 { + for i in 0..50 { let k = Dropable::new(i); let v = m.remove(&k); @@ -1741,12 +1739,12 @@ mod test_map { } DROP_VECTOR.with(|v| { - for i in 0u..50 { + for i in 0..50 { assert_eq!(v.borrow()[i], 0); assert_eq!(v.borrow()[i+100], 0); } - for i in 50u..100 { + for i in 50..100 { assert_eq!(v.borrow()[i], 1); assert_eq!(v.borrow()[i+100], 1); } @@ -1754,7 +1752,7 @@ mod test_map { } DROP_VECTOR.with(|v| { - for i in 0u..200 { + for i in 0..200 { assert_eq!(v.borrow()[i], 0); } }); @@ -1770,19 +1768,19 @@ mod test_map { let mut hm = HashMap::new(); DROP_VECTOR.with(|v| { - for i in 0u..200 { + for i in 0..200 { assert_eq!(v.borrow()[i], 0); } }); - for i in 0u..100 { + for i in 0..100 { let d1 = Dropable::new(i); let d2 = Dropable::new(i+100); hm.insert(d1, d2); } DROP_VECTOR.with(|v| { - for i in 0u..200 { + for i in 0..200 { assert_eq!(v.borrow()[i], 1); } }); @@ -1797,7 +1795,7 @@ mod test_map { let mut half = hm.into_iter().take(50); DROP_VECTOR.with(|v| { - for i in 0u..200 { + for i in 0..200 { assert_eq!(v.borrow()[i], 1); } }); @@ -1805,11 +1803,11 @@ mod test_map { for _ in half.by_ref() {} DROP_VECTOR.with(|v| { - let nk = (0u..100).filter(|&i| { + let nk = (0..100).filter(|&i| { v.borrow()[i] == 1 }).count(); - let nv = (0u..100).filter(|&i| { + let nv = (0..100).filter(|&i| { v.borrow()[i+100] == 1 }).count(); @@ -1819,7 +1817,7 @@ mod test_map { }; DROP_VECTOR.with(|v| { - for i in 0u..200 { + for i in 0..200 { assert_eq!(v.borrow()[i], 0); } }); @@ -1964,7 +1962,7 @@ mod test_map { #[test] fn test_iterate() { let mut m = HashMap::with_capacity(4); - for i in 0u..32 { + for i in 0..32 { assert!(m.insert(i, i*2).is_none()); } assert_eq!(m.len(), 32); @@ -1981,8 +1979,8 @@ mod test_map { #[test] fn test_keys() { 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>>(); + let map: HashMap<_, _> = vec.into_iter().collect(); + let keys: Vec<_> = map.keys().cloned().collect(); assert_eq!(keys.len(), 3); assert!(keys.contains(&1)); assert!(keys.contains(&2)); @@ -1992,8 +1990,8 @@ mod test_map { #[test] fn test_values() { 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>>(); + let map: HashMap<_, _> = vec.into_iter().collect(); + let values: Vec<_> = map.values().cloned().collect(); assert_eq!(values.len(), 3); assert!(values.contains(&'a')); assert!(values.contains(&'b')); @@ -2031,8 +2029,8 @@ mod test_map { #[test] fn test_show() { - let mut map: HashMap<int, int> = HashMap::new(); - let empty: HashMap<int, int> = HashMap::new(); + let mut map = HashMap::new(); + let empty: HashMap<i32, i32> = HashMap::new(); map.insert(1, 2); map.insert(3, 4); @@ -2051,7 +2049,7 @@ mod test_map { assert_eq!(m.len(), 0); assert!(m.is_empty()); - let mut i = 0u; + let mut i = 0; let old_cap = m.table.capacity(); while old_cap == m.table.capacity() { m.insert(i, i); @@ -2079,7 +2077,7 @@ mod test_map { assert_eq!(cap, initial_cap * 2); - let mut i = 0u; + let mut i = 0; for _ in 0..cap * 3 / 4 { m.insert(i, i); i += 1; @@ -2121,21 +2119,21 @@ mod test_map { #[test] fn test_reserve_shrink_to_fit() { let mut m = HashMap::new(); - m.insert(0u, 0u); + m.insert(0, 0); m.remove(&0); assert!(m.capacity() >= m.len()); - for i in 0us..128 { + for i in 0..128 { m.insert(i, i); } m.reserve(256); let usable_cap = m.capacity(); - for i in 128us..128+256 { + for i in 128..(128 + 256) { m.insert(i, i); assert_eq!(m.capacity(), usable_cap); } - for i in 100us..128+256 { + for i in 100..(128 + 256) { assert_eq!(m.remove(&i), Some(i)); } m.shrink_to_fit(); @@ -2144,7 +2142,7 @@ mod test_map { assert!(!m.is_empty()); assert!(m.capacity() >= m.len()); - for i in 0us..100 { + for i in 0..100 { assert_eq!(m.remove(&i), Some(i)); } m.shrink_to_fit(); @@ -2159,7 +2157,7 @@ mod test_map { fn test_from_iter() { 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(); + let map: HashMap<_, _> = xs.iter().cloned().collect(); for &(k, v) in &xs { assert_eq!(map.get(&k), Some(&v)); @@ -2170,7 +2168,7 @@ mod test_map { fn test_size_hint() { 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(); + let map: HashMap<_, _> = xs.iter().cloned().collect(); let mut iter = map.iter(); @@ -2183,7 +2181,7 @@ mod test_map { fn test_iter_len() { 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(); + let map: HashMap<_, _> = xs.iter().cloned().collect(); let mut iter = map.iter(); @@ -2196,7 +2194,7 @@ mod test_map { fn test_mut_size_hint() { 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(); + let mut map: HashMap<_, _> = xs.iter().cloned().collect(); let mut iter = map.iter_mut(); @@ -2209,7 +2207,7 @@ mod test_map { fn test_iter_mut_len() { 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(); + let mut map: HashMap<_, _> = xs.iter().cloned().collect(); let mut iter = map.iter_mut(); @@ -2220,7 +2218,7 @@ mod test_map { #[test] fn test_index() { - let mut map: HashMap<int, int> = HashMap::new(); + let mut map = HashMap::new(); map.insert(1, 2); map.insert(2, 1); @@ -2232,7 +2230,7 @@ mod test_map { #[test] #[should_fail] fn test_index_nonexistent() { - let mut map: HashMap<int, int> = HashMap::new(); + let mut map = HashMap::new(); map.insert(1, 2); map.insert(2, 1); @@ -2245,7 +2243,7 @@ mod test_map { fn test_entry(){ 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(); + let mut map: HashMap<_, _> = xs.iter().cloned().collect(); // Existing key (insert) match map.entry(1) { @@ -2296,7 +2294,7 @@ mod test_map { #[test] fn test_entry_take_doesnt_corrupt() { // Test for #19292 - fn check(m: &HashMap<int, ()>) { + fn check(m: &HashMap<isize, ()>) { for k in m.keys() { assert!(m.contains_key(k), "{} is in keys() but not in the map?", k); @@ -2307,12 +2305,12 @@ mod test_map { let mut rng = weak_rng(); // Populate the map with some items. - for _ in 0u..50 { + for _ in 0..50 { let x = rng.gen_range(-10, 10); m.insert(x, ()); } - for i in 0u..1000 { + for i in 0..1000 { let x = rng.gen_range(-10, 10); match m.entry(x) { Vacant(_) => {}, diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index f5877e1dd99..e40f17f29e8 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -76,15 +76,15 @@ use super::state::HashState; /// #[derive(Hash, Eq, PartialEq, Debug)] /// struct Viking<'a> { /// name: &'a str, -/// power: uint, +/// power: usize, /// } /// /// let mut vikings = HashSet::new(); /// -/// vikings.insert(Viking { name: "Einar", power: 9u }); -/// vikings.insert(Viking { name: "Einar", power: 9u }); -/// vikings.insert(Viking { name: "Olaf", power: 4u }); -/// vikings.insert(Viking { name: "Harald", power: 8u }); +/// vikings.insert(Viking { name: "Einar", power: 9 }); +/// vikings.insert(Viking { name: "Einar", power: 9 }); +/// vikings.insert(Viking { name: "Olaf", power: 4 }); +/// vikings.insert(Viking { name: "Harald", power: 8 }); /// /// // Use derived implementation to print the vikings. /// for x in vikings.iter() { @@ -123,7 +123,7 @@ impl<T: Hash<Hasher> + Eq> HashSet<T, RandomState> { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn with_capacity(capacity: uint) -> HashSet<T, RandomState> { + pub fn with_capacity(capacity: usize) -> HashSet<T, RandomState> { HashSet { map: HashMap::with_capacity(capacity) } } } @@ -146,7 +146,7 @@ impl<T, S, H> HashSet<T, S> /// /// let s = RandomState::new(); /// let mut set = HashSet::with_hash_state(s); - /// set.insert(2u); + /// set.insert(2); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -169,12 +169,12 @@ impl<T, S, H> HashSet<T, S> /// use std::collections::hash_map::RandomState; /// /// let s = RandomState::new(); - /// let mut set = HashSet::with_capacity_and_hash_state(10u, s); + /// let mut set = HashSet::with_capacity_and_hash_state(10, s); /// set.insert(1); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] - pub fn with_capacity_and_hash_state(capacity: uint, hash_state: S) + pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) -> HashSet<T, S> { HashSet { map: HashMap::with_capacity_and_hash_state(capacity, hash_state), @@ -192,7 +192,7 @@ impl<T, S, H> HashSet<T, S> /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn capacity(&self) -> uint { + pub fn capacity(&self) -> usize { self.map.capacity() } @@ -202,7 +202,7 @@ impl<T, S, H> HashSet<T, S> /// /// # Panics /// - /// Panics if the new allocation size overflows `uint`. + /// Panics if the new allocation size overflows `usize`. /// /// # Example /// @@ -212,7 +212,7 @@ impl<T, S, H> HashSet<T, S> /// set.reserve(10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn reserve(&mut self, additional: uint) { + pub fn reserve(&mut self, additional: usize) { self.map.reserve(additional) } @@ -398,11 +398,11 @@ impl<T, S, H> HashSet<T, S> /// /// let mut v = HashSet::new(); /// assert_eq!(v.len(), 0); - /// v.insert(1u); + /// v.insert(1); /// assert_eq!(v.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> uint { self.map.len() } + pub fn len(&self) -> usize { self.map.len() } /// Returns true if the set contains no elements /// @@ -413,7 +413,7 @@ impl<T, S, H> HashSet<T, S> /// /// let mut v = HashSet::new(); /// assert!(v.is_empty()); - /// v.insert(1u); + /// v.insert(1); /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -438,7 +438,7 @@ impl<T, S, H> HashSet<T, S> /// use std::collections::HashSet; /// /// let mut v = HashSet::new(); - /// v.insert(1u); + /// v.insert(1); /// v.clear(); /// assert!(v.is_empty()); /// ``` @@ -456,7 +456,7 @@ impl<T, S, H> HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let set: HashSet<uint> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); /// assert_eq!(set.contains(&1), true); /// assert_eq!(set.contains(&4), false); /// ``` @@ -475,8 +475,8 @@ impl<T, S, H> HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<uint> = [1, 2, 3].iter().map(|&x| x).collect(); - /// let mut b: HashSet<uint> = HashSet::new(); + /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut b = HashSet::new(); /// /// assert_eq!(a.is_disjoint(&b), true); /// b.insert(4); @@ -496,8 +496,8 @@ impl<T, S, H> HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let sup: HashSet<uint> = [1, 2, 3].iter().map(|&x| x).collect(); - /// let mut set: HashSet<uint> = HashSet::new(); + /// let sup: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut set = HashSet::new(); /// /// assert_eq!(set.is_subset(&sup), true); /// set.insert(2); @@ -517,8 +517,8 @@ impl<T, S, H> HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let sub: HashSet<uint> = [1, 2].iter().map(|&x| x).collect(); - /// let mut set: HashSet<uint> = HashSet::new(); + /// let sub: HashSet<_> = [1, 2].iter().cloned().collect(); + /// let mut set = HashSet::new(); /// /// assert_eq!(set.is_superset(&sub), false); /// @@ -545,7 +545,7 @@ impl<T, S, H> HashSet<T, S> /// /// let mut set = HashSet::new(); /// - /// assert_eq!(set.insert(2u), true); + /// assert_eq!(set.insert(2), true); /// assert_eq!(set.insert(2), false); /// assert_eq!(set.len(), 1); /// ``` @@ -566,7 +566,7 @@ impl<T, S, H> HashSet<T, S> /// /// let mut set = HashSet::new(); /// - /// set.insert(2u); + /// set.insert(2); /// assert_eq!(set.remove(&2), true); /// assert_eq!(set.remove(&2), false); /// ``` @@ -670,10 +670,10 @@ impl<'a, 'b, T, S, H> BitOr<&'b HashSet<T, S>> for &'a HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<int> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<int> = vec![3, 4, 5].into_iter().collect(); + /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: HashSet<_> = vec![3, 4, 5].into_iter().collect(); /// - /// let set: HashSet<int> = &a | &b; + /// let set = &a | &b; /// /// let mut i = 0; /// let expected = [1, 2, 3, 4, 5]; @@ -703,10 +703,10 @@ impl<'a, 'b, T, S, H> BitAnd<&'b HashSet<T, S>> for &'a HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<int> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<int> = vec![2, 3, 4].into_iter().collect(); + /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: HashSet<_> = vec![2, 3, 4].into_iter().collect(); /// - /// let set: HashSet<int> = &a & &b; + /// let set = &a & &b; /// /// let mut i = 0; /// let expected = [2, 3]; @@ -736,10 +736,10 @@ impl<'a, 'b, T, S, H> BitXor<&'b HashSet<T, S>> for &'a HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<int> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<int> = vec![3, 4, 5].into_iter().collect(); + /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: HashSet<_> = vec![3, 4, 5].into_iter().collect(); /// - /// let set: HashSet<int> = &a ^ &b; + /// let set = &a ^ &b; /// /// let mut i = 0; /// let expected = [1, 2, 4, 5]; @@ -769,10 +769,10 @@ impl<'a, 'b, T, S, H> Sub<&'b HashSet<T, S>> for &'a HashSet<T, S> /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<int> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<int> = vec![3, 4, 5].into_iter().collect(); + /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: HashSet<_> = vec![3, 4, 5].into_iter().collect(); /// - /// let set: HashSet<int> = &a - &b; + /// let set = &a - &b; /// /// let mut i = 0; /// let expected = [1, 2]; @@ -1029,7 +1029,7 @@ mod test_set { #[test] fn test_iterate() { let mut a = HashSet::new(); - for i in 0u..32 { + for i in 0..32 { assert!(a.insert(i)); } let mut observed: u32 = 0; @@ -1152,7 +1152,7 @@ mod test_set { fn test_from_iter() { let xs = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - let set: HashSet<int> = xs.iter().map(|&x| x).collect(); + let set: HashSet<_> = xs.iter().cloned().collect(); for x in &xs { assert!(set.contains(x)); @@ -1198,8 +1198,8 @@ mod test_set { #[test] fn test_show() { - let mut set: HashSet<int> = HashSet::new(); - let empty: HashSet<int> = HashSet::new(); + let mut set = HashSet::new(); + let empty = HashSet::<i32>::new(); set.insert(1); set.insert(2); @@ -1212,19 +1212,19 @@ mod test_set { #[test] fn test_trivial_drain() { - let mut s = HashSet::<int>::new(); + let mut s = HashSet::<i32>::new(); for _ in s.drain() {} assert!(s.is_empty()); drop(s); - let mut s = HashSet::<int>::new(); + let mut s = HashSet::<i32>::new(); drop(s.drain()); assert!(s.is_empty()); } #[test] fn test_drain() { - let mut s: HashSet<i32> = (1..100).collect(); + let mut s: HashSet<_> = (1..100).collect(); // try this a bunch of times to make sure we don't screw up internal state. for _ in 0..20 { diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 8952b816901..0bb6bd4cf35 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -67,8 +67,8 @@ const EMPTY_BUCKET: u64 = 0u64; /// but in general is just a tricked out `Vec<Option<u64, K, V>>`. #[unsafe_no_drop_flag] pub struct RawTable<K, V> { - capacity: uint, - size: uint, + capacity: usize, + size: usize, hashes: *mut u64, // Because K/V do not appear directly in any of the types in the struct, // inform rustc that in fact instances of K and V are reachable from here. @@ -88,7 +88,7 @@ impl<K,V> Copy for RawBucket<K,V> {} pub struct Bucket<K, V, M> { raw: RawBucket<K, V>, - idx: uint, + idx: usize, table: M } @@ -96,13 +96,13 @@ impl<K,V,M:Copy> Copy for Bucket<K,V,M> {} pub struct EmptyBucket<K, V, M> { raw: RawBucket<K, V>, - idx: uint, + idx: usize, table: M } pub struct FullBucket<K, V, M> { raw: RawBucket<K, V>, - idx: uint, + idx: usize, table: M } @@ -190,7 +190,7 @@ impl<K, V, M> FullBucket<K, V, M> { self.table } /// Get the raw index. - pub fn index(&self) -> uint { + pub fn index(&self) -> usize { self.idx } } @@ -212,21 +212,21 @@ impl<K, V, M> Bucket<K, V, M> { self.table } /// Get the raw index. - pub fn index(&self) -> uint { + pub fn index(&self) -> usize { self.idx } } impl<K, V, M: Deref<Target=RawTable<K, V>>> Bucket<K, V, M> { pub fn new(table: M, hash: SafeHash) -> Bucket<K, V, M> { - Bucket::at_index(table, hash.inspect() as uint) + Bucket::at_index(table, hash.inspect() as usize) } - pub fn at_index(table: M, ib_index: uint) -> Bucket<K, V, M> { + pub fn at_index(table: M, ib_index: usize) -> Bucket<K, V, M> { let ib_index = ib_index & (table.capacity() - 1); Bucket { raw: unsafe { - table.first_bucket_raw().offset(ib_index as int) + table.first_bucket_raw().offset(ib_index as isize) }, idx: ib_index, table: table @@ -276,7 +276,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 = 1 - (maybe_wraparound_dist as int); + let dist = 1 - (maybe_wraparound_dist as isize); self.idx += 1; @@ -366,11 +366,11 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> FullBucket<K, V, M> { /// /// In the cited blog posts above, this is called the "distance to /// initial bucket", or DIB. Also known as "probe count". - pub fn distance(&self) -> uint { + pub fn distance(&self) -> usize { // Calculates the distance one has to travel when going from // `hash mod capacity` onwards to `idx mod capacity`, wrapping around // if the destination is not reached before the end of the table. - (self.idx - self.hash().inspect() as uint) & (self.table.capacity() - 1) + (self.idx - self.hash().inspect() as usize) & (self.table.capacity() - 1) } #[inline] @@ -503,7 +503,7 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> GapThenFull<K, V, M> { /// # Panics /// /// Panics if `target_alignment` is not a power of two. -fn round_up_to_next(unrounded: uint, target_alignment: uint) -> uint { +fn round_up_to_next(unrounded: usize, target_alignment: usize) -> usize { assert!(target_alignment.is_power_of_two()); (unrounded + target_alignment - 1) & !(target_alignment - 1) } @@ -520,10 +520,10 @@ fn test_rounding() { // Returns a tuple of (key_offset, val_offset), // from the start of a mallocated array. -fn calculate_offsets(hashes_size: uint, - keys_size: uint, keys_align: uint, - vals_align: uint) - -> (uint, uint) { +fn calculate_offsets(hashes_size: usize, + keys_size: usize, keys_align: usize, + vals_align: usize) + -> (usize, usize) { let keys_offset = round_up_to_next(hashes_size, keys_align); let end_of_keys = keys_offset + keys_size; @@ -534,10 +534,10 @@ fn calculate_offsets(hashes_size: uint, // Returns a tuple of (minimum required malloc alignment, hash_offset, // array_size), from the start of a mallocated array. -fn calculate_allocation(hash_size: uint, hash_align: uint, - keys_size: uint, keys_align: uint, - vals_size: uint, vals_align: uint) - -> (uint, uint, uint) { +fn calculate_allocation(hash_size: usize, hash_align: usize, + keys_size: usize, keys_align: usize, + vals_size: usize, vals_align: usize) + -> (usize, usize, usize) { let hash_offset = 0; let (_, vals_offset) = calculate_offsets(hash_size, keys_size, keys_align, @@ -562,7 +562,7 @@ fn test_offset_calculation() { impl<K, V> RawTable<K, V> { /// Does not initialize the buckets. The caller should ensure they, /// at the very least, set every hash to EMPTY_BUCKET. - unsafe fn new_uninitialized(capacity: uint) -> RawTable<K, V> { + unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> { if capacity == 0 { return RawTable { size: 0, @@ -601,7 +601,7 @@ impl<K, V> RawTable<K, V> { let buffer = allocate(size, malloc_alignment); if buffer.is_null() { ::alloc::oom() } - let hashes = buffer.offset(hash_offset as int) as *mut u64; + let hashes = buffer.offset(hash_offset as isize) as *mut u64; RawTable { capacity: capacity, @@ -623,15 +623,15 @@ impl<K, V> RawTable<K, V> { unsafe { RawBucket { hash: self.hashes, - key: buffer.offset(keys_offset as int) as *mut K, - val: buffer.offset(vals_offset as int) as *mut V + key: buffer.offset(keys_offset as isize) as *mut K, + val: buffer.offset(vals_offset as isize) as *mut V } } } /// Creates a new raw table from a given capacity. All buckets are /// initially empty. - pub fn new(capacity: uint) -> RawTable<K, V> { + pub fn new(capacity: usize) -> RawTable<K, V> { unsafe { let ret = RawTable::new_uninitialized(capacity); zero_memory(ret.hashes, capacity); @@ -640,13 +640,13 @@ impl<K, V> RawTable<K, V> { } /// The hashtable's capacity, similar to a vector's. - pub fn capacity(&self) -> uint { + pub fn capacity(&self) -> usize { self.capacity } /// The number of elements ever `put` in the hashtable, minus the number /// of elements ever `take`n. - pub fn size(&self) -> uint { + pub fn size(&self) -> usize { self.size } @@ -654,7 +654,7 @@ impl<K, V> RawTable<K, V> { RawBuckets { raw: self.first_bucket_raw(), hashes_end: unsafe { - self.hashes.offset(self.capacity as int) + self.hashes.offset(self.capacity as isize) }, marker: marker::ContravariantLifetime, } @@ -705,7 +705,7 @@ impl<K, V> RawTable<K, V> { unsafe fn rev_move_buckets(&mut self) -> RevMoveBuckets<K, V> { let raw_bucket = self.first_bucket_raw(); RevMoveBuckets { - raw: raw_bucket.offset(self.capacity as int), + raw: raw_bucket.offset(self.capacity as isize), hashes_end: raw_bucket.hash, elems_left: self.size, marker: marker::ContravariantLifetime, @@ -758,7 +758,7 @@ impl<'a, K, V> Iterator for RawBuckets<'a, K, V> { struct RevMoveBuckets<'a, K, V> { raw: RawBucket<K, V>, hashes_end: *mut u64, - elems_left: uint, + elems_left: usize, marker: marker::ContravariantLifetime<'a>, } @@ -791,7 +791,7 @@ impl<'a, K, V> Iterator for RevMoveBuckets<'a, K, V> { /// Iterator over shared references to entries in a table. pub struct Iter<'a, K: 'a, V: 'a> { iter: RawBuckets<'a, K, V>, - elems_left: uint, + elems_left: usize, } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -808,7 +808,7 @@ impl<'a, K, V> Clone for Iter<'a, K, V> { /// Iterator over mutable references to entries in a table. pub struct IterMut<'a, K: 'a, V: 'a> { iter: RawBuckets<'a, K, V>, - elems_left: uint, + elems_left: usize, } /// Iterator over the entries in a table, consuming the table. diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 0c55850b32a..55924bc73a8 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -209,7 +209,7 @@ //! all the contents of the collection. //! //! ``` -//! let vec = vec![1u, 2, 3, 4]; +//! let vec = vec![1, 2, 3, 4]; //! for x in vec.iter() { //! println!("vec contained {}", x); //! } @@ -219,7 +219,7 @@ //! This is great for mutating all the contents of the collection. //! //! ``` -//! let mut vec = vec![1u, 2, 3, 4]; +//! let mut vec = vec![1, 2, 3, 4]; //! for x in vec.iter_mut() { //! *x += 1; //! } @@ -234,15 +234,15 @@ //! previous section to do this as efficiently as possible. //! //! ``` -//! let mut vec1 = vec![1u, 2, 3, 4]; -//! let vec2 = vec![10u, 20, 30, 40]; +//! let mut vec1 = vec![1, 2, 3, 4]; +//! let vec2 = vec![10, 20, 30, 40]; //! vec1.extend(vec2.into_iter()); //! ``` //! //! ``` //! use std::collections::RingBuf; //! -//! let vec = vec![1u, 2, 3, 4]; +//! let vec = vec![1, 2, 3, 4]; //! let buf: RingBuf<uint> = vec.into_iter().collect(); //! ``` //! @@ -253,7 +253,7 @@ //! iterators as the way to iterate over them in reverse order. //! //! ``` -//! let vec = vec![1u, 2, 3, 4]; +//! let vec = vec![1, 2, 3, 4]; //! for x in vec.iter().rev() { //! println!("vec contained {}", x); //! } @@ -299,21 +299,21 @@ //! #### Counting the number of times each character in a string occurs //! //! ``` -//! use std::collections::btree_map::{BTreeMap, Occupied, Vacant}; +//! use std::collections::btree_map::{BTreeMap, Entry}; //! //! let mut count = BTreeMap::new(); //! let message = "she sells sea shells by the sea shore"; //! //! for c in message.chars() { //! match count.entry(c) { -//! Vacant(entry) => { entry.insert(1u); }, -//! Occupied(mut entry) => *entry.get_mut() += 1, +//! Entry::Vacant(entry) => { entry.insert(1); }, +//! Entry::Occupied(mut entry) => *entry.get_mut() += 1, //! } //! } //! //! assert_eq!(count.get(&'s'), Some(&8)); //! -//! println!("Number of occurences of each character"); +//! println!("Number of occurrences of each character"); //! for (char, count) in count.iter() { //! println!("{}: {}", char, count); //! } @@ -326,7 +326,7 @@ //! #### Tracking the inebriation of customers at a bar //! //! ``` -//! use std::collections::btree_map::{BTreeMap, Occupied, Vacant}; +//! use std::collections::btree_map::{BTreeMap, Entry}; //! //! // A client of the bar. They have an id and a blood alcohol level. //! struct Person { id: u32, blood_alcohol: f32 }; @@ -341,8 +341,8 @@ //! // If this is the first time we've seen this customer, initialize them //! // with no blood alcohol. Otherwise, just retrieve them. //! let person = match blood_alcohol.entry(id) { -//! Vacant(entry) => entry.insert(Person{id: id, blood_alcohol: 0.0}), -//! Occupied(entry) => entry.into_mut(), +//! Entry::Vacant(entry) => entry.insert(Person{id: id, blood_alcohol: 0.0}), +//! Entry::Occupied(entry) => entry.into_mut(), //! }; //! //! // Reduce their blood alcohol level. It takes time to order and drink a beer! diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index e1bcfe3ab72..bee9a0d0033 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -22,7 +22,6 @@ use mem; use env; use str; -#[allow(missing_copy_implementations)] pub struct DynamicLibrary { handle: *mut u8 } diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 559a68542ef..e73797bc66c 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -337,7 +337,7 @@ pub fn temp_dir() -> Path { /// /// # Errors /// -/// Acquring the path to the current executable is a platform-specific operation +/// Acquiring the path to the current executable is a platform-specific operation /// that can fail for a good number of reasons. Some errors can include, but not /// be limited to filesystem operations failing or general syscall failures. /// @@ -563,6 +563,38 @@ pub mod consts { } /// Constants associated with the current target +#[cfg(target_os = "openbsd")] +pub mod consts { + pub use super::arch_consts::ARCH; + + pub const FAMILY: &'static str = "unix"; + + /// A string describing the specific operating system in use: in this + /// case, `dragonfly`. + pub const OS: &'static str = "openbsd"; + + /// Specifies the filename prefix used for shared libraries on this + /// platform: in this case, `lib`. + pub const DLL_PREFIX: &'static str = "lib"; + + /// Specifies the filename suffix used for shared libraries on this + /// platform: in this case, `.so`. + pub const DLL_SUFFIX: &'static str = ".so"; + + /// Specifies the file extension used for shared libraries on this + /// platform that goes after the dot: in this case, `so`. + pub const DLL_EXTENSION: &'static str = "so"; + + /// Specifies the filename suffix used for executable binaries on this + /// platform: in this case, the empty string. + pub const EXE_SUFFIX: &'static str = ""; + + /// Specifies the file extension, if any, used for executable binaries + /// on this platform: in this case, the empty string. + pub const EXE_EXTENSION: &'static str = ""; +} + +/// Constants associated with the current target #[cfg(target_os = "android")] pub mod consts { pub use super::arch_consts::ARCH; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 419bee1a624..2668baba095 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -96,7 +96,7 @@ fn with_end_to_cap<F>(v: &mut Vec<u8>, f: F) -> Result<usize> // // To this end, we use an RAII guard (to protect against panics) which updates // the length of the string when it is dropped. This guard initially truncates -// the string to the prior length and only afer we've validated that the +// the string to the prior length and only after we've validated that the // new contents are valid UTF-8 do we allow it to set a longer length. // // The unsafety in this function is twofold: @@ -663,7 +663,7 @@ impl<T> Take<T> { /// /// # Note /// - /// This instance may reach EOF after reading fewer bytes than indiccated by + /// This instance may reach EOF after reading fewer bytes than indicated by /// this method if the underlying `Read` instance reaches EOF. pub fn limit(&self) -> u64 { self.limit } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 093a0695f62..1a617694456 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -759,7 +759,6 @@ pub fn page_size() -> uint { /// /// The memory map is released (unmapped) when the destructor is run, so don't /// let it leave scope by accident if you want it to stick around. -#[allow(missing_copy_implementations)] pub struct MemoryMap { data: *mut u8, len: uint, @@ -1289,6 +1288,8 @@ pub mod consts { } #[cfg(target_os = "openbsd")] +#[deprecated(since = "1.0.0", reason = "renamed to env::consts")] +#[unstable(feature = "os")] pub mod consts { pub use os::arch_consts::ARCH; diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 3f4f1ec4c0d..cb213863030 100755 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -922,7 +922,7 @@ impl PathBuf { /// /// If `self.file_name()` is `None`, does nothing and returns `false`. /// - /// Otherwise, returns `tru`; if `self.exension()` is `None`, the extension + /// Otherwise, returns `true`; if `self.extension()` is `None`, the extension /// is added; otherwise it is replaced. pub fn set_extension<S: ?Sized + AsOsStr>(&mut self, extension: &S) -> bool { if self.file_name().is_none() { return false; } @@ -1062,7 +1062,7 @@ impl Path { PathBuf::new(self) } - /// A path is *absolute* if it is indepedent of the current directory. + /// A path is *absolute* if it is independent of the current directory. /// /// * On Unix, a path is absolute if it starts with the root, so /// `is_absolute` and `has_root` are equivalent. diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 797b9332f17..535af08c96c 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -206,7 +206,6 @@ mod imp { /// - iOS: calls SecRandomCopyBytes as /dev/(u)random is sandboxed. /// /// This does not block. - #[allow(missing_copy_implementations)] pub struct OsRng { // dummy field to ensure that this struct cannot be constructed outside of this module _dummy: (), diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 81ca5aa0e8a..e064663b9e7 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -98,8 +98,8 @@ thread_local! { static PANICKING: Cell<bool> = Cell::new(false) } /// Invoke a closure, capturing the cause of panic if one occurs. /// -/// This function will return `None` if the closure did not panic, and will -/// return `Some(cause)` if the closure panics. The `cause` returned is the +/// This function will return `Ok(())` if the closure did not panic, and will +/// return `Err(cause)` if the closure panics. The `cause` returned is the /// object with which panic was originally invoked. /// /// This function also is unsafe for a variety of reasons: @@ -390,13 +390,10 @@ pub mod eabi { use libc::{c_void, c_int}; #[repr(C)] - #[allow(missing_copy_implementations)] pub struct EXCEPTION_RECORD; #[repr(C)] - #[allow(missing_copy_implementations)] pub struct CONTEXT; #[repr(C)] - #[allow(missing_copy_implementations)] pub struct DISPATCHER_CONTEXT; #[repr(C)] diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 86d21cf7278..703dca4d29b 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -88,7 +88,6 @@ pub fn default_sched_threads() -> uint { pub const ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert); -#[allow(missing_copy_implementations)] pub struct Stdio(libc::c_int); #[allow(non_upper_case_globals)] diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index 581e540d3b6..cca376f7b6d 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -46,7 +46,6 @@ struct BarrierState { /// /// Currently this opaque structure only has one method, `.is_leader()`. Only /// one thread will receive a result that will return `true` from this function. -#[allow(missing_copy_implementations)] pub struct BarrierWaitResult(bool); impl Barrier { diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 39c57a21d75..2e60d684d68 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Multi-producer, single-consumer communication primitives threads +//! Multi-producer, single-consumer FIFO queue communication primitives. //! //! This module provides message-based communication over channels, concretely //! defined among three types: diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index ca667e65e30..eb45681fa62 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -45,7 +45,7 @@ use core::mem; use sync::atomic::{AtomicUsize, Ordering}; // Various states you can find a port in. -const EMPTY: uint = 0; // initial state: no data, no blocked reciever +const EMPTY: uint = 0; // initial state: no data, no blocked receiver const DATA: uint = 1; // data ready for receiver to take const DISCONNECTED: uint = 2; // channel is disconnected OR upgraded // Any other value represents a pointer to a SignalToken value. The diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index 18680b96592..d9bc37d312e 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -42,7 +42,6 @@ impl Flag { } } -#[allow(missing_copy_implementations)] pub struct Guard { panicking: bool, } diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 04cba804e8d..89200471465 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -84,7 +84,7 @@ impl CodePoint { /// Create a new `CodePoint` from a `char`. /// - /// Since all Unicode scalar values are code points, this always succeds. + /// Since all Unicode scalar values are code points, this always succeeds. #[inline] pub fn from_char(value: char) -> CodePoint { CodePoint { value: value as u32 } diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs index 50a8e6b73e3..22194145252 100644 --- a/src/libstd/sys/unix/c.rs +++ b/src/libstd/sys/unix/c.rs @@ -74,6 +74,8 @@ pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70; #[cfg(any(target_os = "macos", target_os = "freebsd"))] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71; +#[cfg(target_os = "openbsd")] +pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101; #[cfg(target_os = "android")] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048; @@ -91,7 +93,8 @@ pub struct passwd { #[repr(C)] #[cfg(any(target_os = "macos", - target_os = "freebsd"))] + target_os = "freebsd", + target_os = "openbsd"))] pub struct passwd { pub pw_name: *mut libc::c_char, pub pw_passwd: *mut libc::c_char, diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 5004ff713c4..b191eda583c 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -47,13 +47,9 @@ pub fn errno() -> i32 { } #[cfg(target_os = "openbsd")] - fn errno_location() -> *const c_int { - extern { - fn __errno() -> *const c_int; - } - unsafe { - __errno() - } + unsafe fn errno_location() -> *const c_int { + extern { fn __errno() -> *const c_int; } + __errno() } #[cfg(any(target_os = "linux", target_os = "android"))] @@ -197,23 +193,23 @@ pub fn current_exe() -> IoResult<Path> { } #[cfg(target_os = "openbsd")] -pub fn load_self() -> Option<Vec<u8>> { +pub fn current_exe() -> IoResult<Path> { use sync::{StaticMutex, MUTEX_INIT}; static LOCK: StaticMutex = MUTEX_INIT; extern { - fn rust_load_self() -> *const c_char; + fn rust_current_exe() -> *const c_char; } let _guard = LOCK.lock(); unsafe { - let v = rust_load_self(); + let v = rust_current_exe(); if v.is_null() { - None + Err(IoError::last_error()) } else { - Some(ffi::c_str_to_bytes(&v).to_vec()) + Ok(Path::new(ffi::c_str_to_bytes(&v).to_vec())) } } } @@ -333,7 +329,8 @@ pub fn args() -> Args { #[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", - target_os = "dragonfly"))] + target_os = "dragonfly", + target_os = "openbsd"))] pub fn args() -> Args { use rt; let bytes = rt::args::clone().unwrap_or(Vec::new()); diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 54a32e43daf..0c24ab1fa09 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -191,7 +191,7 @@ unsafe fn unregister_dtor(key: Key) -> bool { // # What's up with this callback? // // The callback specified receives a number of parameters from... someone! -// (the kernel? the runtime? I'm not qute sure!) There are a few events that +// (the kernel? the runtime? I'm not quite sure!) There are a few events that // this gets invoked for, but we're currently only interested on when a // thread or a process "detaches" (exits). The process part happens for the // last thread and the thread part happens for any normal thread. diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 76b8d736aad..42ef3459a0e 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -232,7 +232,7 @@ impl Duration { secs_part.checked_add(nanos_part as i64) } - /// Add two durations, returning `None` if overflow occured. + /// Add two durations, returning `None` if overflow occurred. #[unstable(feature = "std_misc")] pub fn checked_add(&self, rhs: &Duration) -> Option<Duration> { let mut secs = try_opt!(self.secs.checked_add(rhs.secs)); @@ -247,7 +247,7 @@ impl Duration { if d < MIN || d > MAX { None } else { Some(d) } } - /// Subtract two durations, returning `None` if overflow occured. + /// Subtract two durations, returning `None` if overflow occurred. #[unstable(feature = "std_misc")] pub fn checked_sub(&self, rhs: &Duration) -> Option<Duration> { let mut secs = try_opt!(self.secs.checked_sub(rhs.secs)); |
