]> git.lizzy.rs Git - rust.git/commitdiff
a few more &mut self -> self changes
authorblitzerr <rusty.blitzerr@gmail.com>
Wed, 23 Sep 2020 04:04:31 +0000 (21:04 -0700)
committerblitzerr <rusty.blitzerr@gmail.com>
Wed, 23 Sep 2020 04:04:31 +0000 (21:04 -0700)
library/alloc/src/alloc.rs
library/core/src/alloc/mod.rs
library/std/src/alloc.rs
src/test/ui/allocator/custom.rs

index 462bcd15fa9415e9e20c15fa2c0bf7d188bd12ce..8b8cdbf252555089b8e1f0db64b367afa1d2240f 100644 (file)
@@ -160,7 +160,7 @@ fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, Allo
     // SAFETY: Same as `AllocRef::grow`
     #[inline]
     unsafe fn grow_impl(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -228,7 +228,7 @@ unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) {
 
     #[inline]
     unsafe fn grow(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -239,7 +239,7 @@ unsafe fn grow(
 
     #[inline]
     unsafe fn grow_zeroed(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -250,7 +250,7 @@ unsafe fn grow_zeroed(
 
     #[inline]
     unsafe fn shrink(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
index 5f9092fe7037e45d2a2584d75b7a963001826acb..f9eb8981bbfc24d1a8dafeb52803d4b391edec3c 100644 (file)
@@ -183,7 +183,7 @@ fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
     ///
     /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
     unsafe fn grow(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -244,7 +244,7 @@ unsafe fn grow(
     ///
     /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
     unsafe fn grow_zeroed(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -308,7 +308,7 @@ unsafe fn grow_zeroed(
     ///
     /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
     unsafe fn shrink(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -337,13 +337,13 @@ unsafe fn shrink(
     ///
     /// The returned adaptor also implements `AllocRef` and will simply borrow this.
     #[inline(always)]
-    fn by_ref(&mut self) -> &mut Self {
+    fn by_ref(&mut self) -> &Self {
         self
     }
 }
 
 #[unstable(feature = "allocator_api", issue = "32838")]
-unsafe impl<A> AllocRef for &mut A
+unsafe impl<A> AllocRef for &A
 where
     A: AllocRef + ?Sized,
 {
@@ -365,7 +365,7 @@ unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) {
 
     #[inline]
     unsafe fn grow(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -376,7 +376,7 @@ unsafe fn grow(
 
     #[inline]
     unsafe fn grow_zeroed(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -387,7 +387,7 @@ unsafe fn grow_zeroed(
 
     #[inline]
     unsafe fn shrink(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
index f41aa28b5ecb546927dba5c8929beff71481994b..ba158511f64c085eae97538d255f77bebc398c95 100644 (file)
@@ -152,7 +152,7 @@ fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, Allo
     // SAFETY: Same as `AllocRef::grow`
     #[inline]
     unsafe fn grow_impl(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -190,7 +190,7 @@ unsafe fn grow_impl(
             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);
-                self.dealloc(ptr, old_layout);
+                AllocRef::dealloc(&self, ptr, old_layout);
                 Ok(new_ptr)
             },
         }
@@ -222,7 +222,7 @@ unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) {
 
     #[inline]
     unsafe fn grow(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -233,7 +233,7 @@ unsafe fn grow(
 
     #[inline]
     unsafe fn grow_zeroed(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -244,7 +244,7 @@ unsafe fn grow_zeroed(
 
     #[inline]
     unsafe fn shrink(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
@@ -257,7 +257,7 @@ unsafe fn shrink(
         match new_layout.size() {
             // SAFETY: conditions must be upheld by the caller
             0 => unsafe {
-                self.dealloc(ptr, old_layout);
+                AllocRef::dealloc(&self, ptr, old_layout);
                 Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
             },
 
@@ -277,9 +277,9 @@ unsafe fn shrink(
             // `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 = self.alloc(new_layout)?;
+                let new_ptr = AllocRef::alloc(&self, new_layout)?;
                 ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), new_size);
-                self.dealloc(ptr, old_layout);
+                AllocRef::dealloc(&self, ptr, old_layout);
                 Ok(new_ptr)
             },
         }
index 73750bf139a7d46245338b2ce46e2c0a149fc543..dfb5d3e9e38d0fb40cd49abd79cf1d32df56d6ce 100644 (file)
@@ -19,7 +19,7 @@
 unsafe impl alloc::GlobalAlloc for A {
     unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
         HITS.fetch_add(1, Ordering::SeqCst);
-        AllocRef::alloc(&System, layout).unwrap().as_mut_ptr()
+        alloc::GlobalAlloc::alloc(&System, layout)
     }
 
     unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {