Skip to content

Commit 2b19b14

Browse files
committed
a few more &mut self -> self changes
1 parent 985dff9 commit 2b19b14

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

library/alloc/src/alloc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Global {
160160
// SAFETY: Same as `AllocRef::grow`
161161
#[inline]
162162
unsafe fn grow_impl(
163-
&mut self,
163+
&self,
164164
ptr: NonNull<u8>,
165165
old_layout: Layout,
166166
new_layout: Layout,
@@ -228,7 +228,7 @@ unsafe impl AllocRef for Global {
228228

229229
#[inline]
230230
unsafe fn grow(
231-
&mut self,
231+
&self,
232232
ptr: NonNull<u8>,
233233
old_layout: Layout,
234234
new_layout: Layout,
@@ -239,7 +239,7 @@ unsafe impl AllocRef for Global {
239239

240240
#[inline]
241241
unsafe fn grow_zeroed(
242-
&mut self,
242+
&self,
243243
ptr: NonNull<u8>,
244244
old_layout: Layout,
245245
new_layout: Layout,
@@ -250,7 +250,7 @@ unsafe impl AllocRef for Global {
250250

251251
#[inline]
252252
unsafe fn shrink(
253-
&mut self,
253+
&self,
254254
ptr: NonNull<u8>,
255255
old_layout: Layout,
256256
new_layout: Layout,

library/core/src/alloc/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub unsafe trait AllocRef {
183183
///
184184
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
185185
unsafe fn grow(
186-
&mut self,
186+
&self,
187187
ptr: NonNull<u8>,
188188
old_layout: Layout,
189189
new_layout: Layout,
@@ -244,7 +244,7 @@ pub unsafe trait AllocRef {
244244
///
245245
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
246246
unsafe fn grow_zeroed(
247-
&mut self,
247+
&self,
248248
ptr: NonNull<u8>,
249249
old_layout: Layout,
250250
new_layout: Layout,
@@ -308,7 +308,7 @@ pub unsafe trait AllocRef {
308308
///
309309
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
310310
unsafe fn shrink(
311-
&mut self,
311+
&self,
312312
ptr: NonNull<u8>,
313313
old_layout: Layout,
314314
new_layout: Layout,
@@ -337,13 +337,13 @@ pub unsafe trait AllocRef {
337337
///
338338
/// The returned adaptor also implements `AllocRef` and will simply borrow this.
339339
#[inline(always)]
340-
fn by_ref(&mut self) -> &mut Self {
340+
fn by_ref(&mut self) -> &Self {
341341
self
342342
}
343343
}
344344

345345
#[unstable(feature = "allocator_api", issue = "32838")]
346-
unsafe impl<A> AllocRef for &mut A
346+
unsafe impl<A> AllocRef for &A
347347
where
348348
A: AllocRef + ?Sized,
349349
{
@@ -365,7 +365,7 @@ where
365365

366366
#[inline]
367367
unsafe fn grow(
368-
&mut self,
368+
&self,
369369
ptr: NonNull<u8>,
370370
old_layout: Layout,
371371
new_layout: Layout,
@@ -376,7 +376,7 @@ where
376376

377377
#[inline]
378378
unsafe fn grow_zeroed(
379-
&mut self,
379+
&self,
380380
ptr: NonNull<u8>,
381381
old_layout: Layout,
382382
new_layout: Layout,
@@ -387,7 +387,7 @@ where
387387

388388
#[inline]
389389
unsafe fn shrink(
390-
&mut self,
390+
&self,
391391
ptr: NonNull<u8>,
392392
old_layout: Layout,
393393
new_layout: Layout,

library/std/src/alloc.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl System {
152152
// SAFETY: Same as `AllocRef::grow`
153153
#[inline]
154154
unsafe fn grow_impl(
155-
&mut self,
155+
&self,
156156
ptr: NonNull<u8>,
157157
old_layout: Layout,
158158
new_layout: Layout,
@@ -190,7 +190,7 @@ impl System {
190190
old_size => unsafe {
191191
let new_ptr = self.alloc_impl(new_layout, zeroed)?;
192192
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), old_size);
193-
self.dealloc(ptr, old_layout);
193+
AllocRef::dealloc(&self, ptr, old_layout);
194194
Ok(new_ptr)
195195
},
196196
}
@@ -222,7 +222,7 @@ unsafe impl AllocRef for System {
222222

223223
#[inline]
224224
unsafe fn grow(
225-
&mut self,
225+
&self,
226226
ptr: NonNull<u8>,
227227
old_layout: Layout,
228228
new_layout: Layout,
@@ -233,7 +233,7 @@ unsafe impl AllocRef for System {
233233

234234
#[inline]
235235
unsafe fn grow_zeroed(
236-
&mut self,
236+
&self,
237237
ptr: NonNull<u8>,
238238
old_layout: Layout,
239239
new_layout: Layout,
@@ -244,7 +244,7 @@ unsafe impl AllocRef for System {
244244

245245
#[inline]
246246
unsafe fn shrink(
247-
&mut self,
247+
&self,
248248
ptr: NonNull<u8>,
249249
old_layout: Layout,
250250
new_layout: Layout,
@@ -257,7 +257,7 @@ unsafe impl AllocRef for System {
257257
match new_layout.size() {
258258
// SAFETY: conditions must be upheld by the caller
259259
0 => unsafe {
260-
self.dealloc(ptr, old_layout);
260+
AllocRef::dealloc(&self, ptr, old_layout);
261261
Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
262262
},
263263

@@ -277,9 +277,9 @@ unsafe impl AllocRef for System {
277277
// `new_ptr`. Thus, the call to `copy_nonoverlapping` is safe. The safety contract
278278
// for `dealloc` must be upheld by the caller.
279279
new_size => unsafe {
280-
let new_ptr = self.alloc(new_layout)?;
280+
let new_ptr = AllocRef::alloc(&self, new_layout)?;
281281
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), new_size);
282-
self.dealloc(ptr, old_layout);
282+
AllocRef::dealloc(&self, ptr, old_layout);
283283
Ok(new_ptr)
284284
},
285285
}

src/test/ui/allocator/custom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct A;
1919
unsafe impl alloc::GlobalAlloc for A {
2020
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
2121
HITS.fetch_add(1, Ordering::SeqCst);
22-
AllocRef::alloc(&System, layout).unwrap().as_mut_ptr()
22+
alloc::GlobalAlloc::alloc(&System, layout)
2323
}
2424

2525
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {

0 commit comments

Comments
 (0)