Skip to content

Commit

Permalink
Rollup merge of rust-lang#98233 - RalfJung:ref-alloc, r=thomcc
Browse files Browse the repository at this point in the history
Remove accidental uses of `&A: Allocator`

Cc rust-lang#98232

Fixes rust-lang#98176 (for real this time)
  • Loading branch information
Dylan-DPC committed Jun 19, 2022
2 parents e7441cf + b05d71f commit 17cfc77
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,11 +1644,11 @@ impl<K, V, A: Allocator + Clone> IntoIter<K, V, A> {
&mut self,
) -> Option<Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>> {
if self.length == 0 {
self.range.deallocating_end(&self.alloc);
self.range.deallocating_end(self.alloc.clone());
None
} else {
self.length -= 1;
Some(unsafe { self.range.deallocating_next_unchecked(&self.alloc) })
Some(unsafe { self.range.deallocating_next_unchecked(self.alloc.clone()) })
}
}

Expand All @@ -1658,11 +1658,11 @@ impl<K, V, A: Allocator + Clone> IntoIter<K, V, A> {
&mut self,
) -> Option<Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>> {
if self.length == 0 {
self.range.deallocating_end(&self.alloc);
self.range.deallocating_end(self.alloc.clone());
None
} else {
self.length -= 1;
Some(unsafe { self.range.deallocating_next_back_unchecked(&self.alloc) })
Some(unsafe { self.range.deallocating_next_back_unchecked(self.alloc.clone()) })
}
}
}
Expand Down Expand Up @@ -1849,7 +1849,7 @@ where
type Item = (K, V);

fn next(&mut self) -> Option<(K, V)> {
self.inner.next(&mut self.pred, &self.alloc)
self.inner.next(&mut self.pred, self.alloc.clone())
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ where
fn next(&mut self) -> Option<T> {
let pred = &mut self.pred;
let mut mapped_pred = |k: &T, _v: &mut ()| pred(k);
self.inner.next(&mut mapped_pred, &self.alloc).map(|(k, _)| k)
self.inner.next(&mut mapped_pred, self.alloc.clone()).map(|(k, _)| k)
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl System {
old_size => unsafe {
let new_ptr = self.alloc_impl(new_layout, zeroed)?;
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), old_size);
Allocator::deallocate(&self, ptr, old_layout);
Allocator::deallocate(self, ptr, old_layout);
Ok(new_ptr)
},
}
Expand Down Expand Up @@ -254,7 +254,7 @@ unsafe impl Allocator for System {
match new_layout.size() {
// SAFETY: conditions must be upheld by the caller
0 => unsafe {
Allocator::deallocate(&self, ptr, old_layout);
Allocator::deallocate(self, ptr, old_layout);
Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
},

Expand All @@ -274,9 +274,9 @@ unsafe impl Allocator for System {
// `new_ptr`. Thus, the call to `copy_nonoverlapping` is safe. The safety contract
// for `dealloc` must be upheld by the caller.
new_size => unsafe {
let new_ptr = Allocator::allocate(&self, new_layout)?;
let new_ptr = Allocator::allocate(self, new_layout)?;
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), new_size);
Allocator::deallocate(&self, ptr, old_layout);
Allocator::deallocate(self, ptr, old_layout);
Ok(new_ptr)
},
}
Expand Down

0 comments on commit 17cfc77

Please sign in to comment.