diff options
| author | Fenrir <[email protected]> | 2017-12-01 21:57:34 -0700 |
|---|---|---|
| committer | FenrirWolf <[email protected]> | 2017-12-01 22:33:03 -0700 |
| commit | 8ba058552b61484248fc295dfbbe2e18a9d49e48 (patch) | |
| tree | 0c1bdd596147abee8dda56ac98ca009fa699a707 /ctr-std/src/collections/hash/table.rs | |
| parent | Update bindings for libctru v1.4.0 (diff) | |
| download | archived-ctru-rs-8ba058552b61484248fc295dfbbe2e18a9d49e48.tar.xz archived-ctru-rs-8ba058552b61484248fc295dfbbe2e18a9d49e48.zip | |
Patch `std` to be compatible with Rust nightly-2017-12-01
This only fixes things enough so that the project compiles again. More standard library changes from upstream Rust will be pulled in later.
Diffstat (limited to 'ctr-std/src/collections/hash/table.rs')
| -rw-r--r-- | ctr-std/src/collections/hash/table.rs | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/ctr-std/src/collections/hash/table.rs b/ctr-std/src/collections/hash/table.rs index 3844690..7e623a0 100644 --- a/ctr-std/src/collections/hash/table.rs +++ b/ctr-std/src/collections/hash/table.rs @@ -353,14 +353,14 @@ impl<K, V, M: Deref<Target = RawTable<K, V>>> Bucket<K, V, M> { let ib_index = ib_index & table.capacity_mask; Bucket { raw: table.raw_bucket_at(ib_index), - table: table, + table, } } pub fn first(table: M) -> Bucket<K, V, M> { Bucket { raw: table.raw_bucket_at(0), - table: table, + table, } } @@ -455,7 +455,7 @@ impl<K, V, M: Deref<Target = RawTable<K, V>>> EmptyBucket<K, V, M> { match self.next().peek() { Full(bucket) => { Ok(GapThenFull { - gap: gap, + gap, full: bucket, }) } @@ -563,7 +563,7 @@ impl<'t, K, V> FullBucket<K, V, &'t mut RawTable<K, V>> { /// /// This works similarly to `put`, building an `EmptyBucket` out of the /// taken bucket. - pub fn take(mut self) -> (EmptyBucket<K, V, &'t mut RawTable<K, V>>, K, V) { + pub fn take(self) -> (EmptyBucket<K, V, &'t mut RawTable<K, V>>, K, V) { self.table.size -= 1; unsafe { @@ -717,26 +717,25 @@ fn calculate_offsets(hashes_size: usize, (pairs_offset, end_of_pairs, oflo) } -// Returns a tuple of (minimum required malloc alignment, hash_offset, +// Returns a tuple of (minimum required malloc alignment, // array_size), from the start of a mallocated array. fn calculate_allocation(hash_size: usize, hash_align: usize, pairs_size: usize, pairs_align: usize) - -> (usize, usize, usize, bool) { - let hash_offset = 0; + -> (usize, usize, bool) { let (_, end_of_pairs, oflo) = calculate_offsets(hash_size, pairs_size, pairs_align); let align = cmp::max(hash_align, pairs_align); - (align, hash_offset, end_of_pairs, oflo) + (align, end_of_pairs, oflo) } #[test] fn test_offset_calculation() { - assert_eq!(calculate_allocation(128, 8, 16, 8), (8, 0, 144, false)); - assert_eq!(calculate_allocation(3, 1, 2, 1), (1, 0, 5, false)); - assert_eq!(calculate_allocation(6, 2, 12, 4), (4, 0, 20, false)); + assert_eq!(calculate_allocation(128, 8, 16, 8), (8, 144, false)); + assert_eq!(calculate_allocation(3, 1, 2, 1), (1, 5, false)); + assert_eq!(calculate_allocation(6, 2, 12, 4), (4, 20, false)); assert_eq!(calculate_offsets(128, 15, 4), (128, 143, false)); assert_eq!(calculate_offsets(3, 2, 4), (4, 6, false)); assert_eq!(calculate_offsets(6, 12, 4), (8, 20, false)); @@ -768,10 +767,10 @@ impl<K, V> RawTable<K, V> { // This is great in theory, but in practice getting the alignment // right is a little subtle. Therefore, calculating offsets has been // factored out into a different function. - let (alignment, hash_offset, size, oflo) = calculate_allocation(hashes_size, - align_of::<HashUint>(), - pairs_size, - align_of::<(K, V)>()); + let (alignment, size, oflo) = calculate_allocation(hashes_size, + align_of::<HashUint>(), + pairs_size, + align_of::<(K, V)>()); assert!(!oflo, "capacity overflow"); // One check for overflow that covers calculation and rounding of size. @@ -784,7 +783,7 @@ impl<K, V> RawTable<K, V> { let buffer = Heap.alloc(Layout::from_size_align(size, alignment).unwrap()) .unwrap_or_else(|e| Heap.oom(e)); - let hashes = buffer.offset(hash_offset as isize) as *mut HashUint; + let hashes = buffer as *mut HashUint; RawTable { capacity_mask: capacity.wrapping_sub(1), @@ -860,8 +859,8 @@ impl<K, V> RawTable<K, V> { // Replace the marker regardless of lifetime bounds on parameters. IntoIter { iter: RawBuckets { - raw: raw, - elems_left: elems_left, + raw, + elems_left, marker: marker::PhantomData, }, table: self, @@ -873,8 +872,8 @@ impl<K, V> RawTable<K, V> { // Replace the marker regardless of lifetime bounds on parameters. Drain { iter: RawBuckets { - raw: raw, - elems_left: elems_left, + raw, + elems_left, marker: marker::PhantomData, }, table: Shared::from(self), @@ -925,7 +924,7 @@ struct RawBuckets<'a, K, V> { marker: marker::PhantomData<&'a ()>, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` +// FIXME(#26925) Remove in favor of `#[derive(Clone)]` impl<'a, K, V> Clone for RawBuckets<'a, K, V> { fn clone(&self) -> RawBuckets<'a, K, V> { RawBuckets { @@ -976,7 +975,7 @@ pub struct Iter<'a, K: 'a, V: 'a> { unsafe impl<'a, K: Sync, V: Sync> Sync for Iter<'a, K, V> {} unsafe impl<'a, K: Sync, V: Sync> Send for Iter<'a, K, V> {} -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` +// FIXME(#26925) Remove in favor of `#[derive(Clone)]` impl<'a, K, V> Clone for Iter<'a, K, V> { fn clone(&self) -> Iter<'a, K, V> { Iter { @@ -1157,6 +1156,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> { } new_ht.size = self.size(); + new_ht.set_tag(self.tag()); new_ht } @@ -1183,10 +1183,10 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable<K, V> { let hashes_size = self.capacity() * size_of::<HashUint>(); let pairs_size = self.capacity() * size_of::<(K, V)>(); - let (align, _, size, oflo) = calculate_allocation(hashes_size, - align_of::<HashUint>(), - pairs_size, - align_of::<(K, V)>()); + let (align, size, oflo) = calculate_allocation(hashes_size, + align_of::<HashUint>(), + pairs_size, + align_of::<(K, V)>()); debug_assert!(!oflo, "should be impossible"); |