Skip to content

Commit 5829560

Browse files
author
Jacob Hughes
committed
Rename AllocErr to AllocError
1 parent d62d3f7 commit 5829560

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

library/alloc/src/alloc.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
145145

146146
impl Global {
147147
#[inline]
148-
fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocErr> {
148+
fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> {
149149
match layout.size() {
150150
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
151151
// SAFETY: `layout` is non-zero in size,
152152
size => unsafe {
153153
let raw_ptr = if zeroed { alloc_zeroed(layout) } else { alloc(layout) };
154-
let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
154+
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
155155
Ok(NonNull::slice_from_raw_parts(ptr, size))
156156
},
157157
}
@@ -165,7 +165,7 @@ impl Global {
165165
old_layout: Layout,
166166
new_layout: Layout,
167167
zeroed: bool,
168-
) -> Result<NonNull<[u8]>, AllocErr> {
168+
) -> Result<NonNull<[u8]>, AllocError> {
169169
debug_assert!(
170170
new_layout.size() >= old_layout.size(),
171171
"`new_layout.size()` must be greater than or equal to `old_layout.size()`"
@@ -183,7 +183,7 @@ impl Global {
183183
intrinsics::assume(new_size >= old_layout.size());
184184

185185
let raw_ptr = realloc(ptr.as_ptr(), old_layout, new_size);
186-
let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
186+
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
187187
if zeroed {
188188
raw_ptr.add(old_size).write_bytes(0, new_size - old_size);
189189
}
@@ -208,12 +208,12 @@ impl Global {
208208
#[unstable(feature = "allocator_api", issue = "32838")]
209209
unsafe impl AllocRef for Global {
210210
#[inline]
211-
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
211+
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
212212
self.alloc_impl(layout, false)
213213
}
214214

215215
#[inline]
216-
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
216+
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
217217
self.alloc_impl(layout, true)
218218
}
219219

@@ -232,7 +232,7 @@ unsafe impl AllocRef for Global {
232232
ptr: NonNull<u8>,
233233
old_layout: Layout,
234234
new_layout: Layout,
235-
) -> Result<NonNull<[u8]>, AllocErr> {
235+
) -> Result<NonNull<[u8]>, AllocError> {
236236
// SAFETY: all conditions must be upheld by the caller
237237
unsafe { self.grow_impl(ptr, old_layout, new_layout, false) }
238238
}
@@ -243,7 +243,7 @@ unsafe impl AllocRef for Global {
243243
ptr: NonNull<u8>,
244244
old_layout: Layout,
245245
new_layout: Layout,
246-
) -> Result<NonNull<[u8]>, AllocErr> {
246+
) -> Result<NonNull<[u8]>, AllocError> {
247247
// SAFETY: all conditions must be upheld by the caller
248248
unsafe { self.grow_impl(ptr, old_layout, new_layout, true) }
249249
}
@@ -254,7 +254,7 @@ unsafe impl AllocRef for Global {
254254
ptr: NonNull<u8>,
255255
old_layout: Layout,
256256
new_layout: Layout,
257-
) -> Result<NonNull<[u8]>, AllocErr> {
257+
) -> Result<NonNull<[u8]>, AllocError> {
258258
debug_assert!(
259259
new_layout.size() <= old_layout.size(),
260260
"`new_layout.size()` must be smaller than or equal to `old_layout.size()`"
@@ -273,7 +273,7 @@ unsafe impl AllocRef for Global {
273273
intrinsics::assume(new_size <= old_layout.size());
274274

275275
let raw_ptr = realloc(ptr.as_ptr(), old_layout, new_size);
276-
let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
276+
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
277277
Ok(NonNull::slice_from_raw_parts(ptr, new_size))
278278
},
279279

library/alloc/src/raw_vec/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cell::Cell;
33

44
#[test]
55
fn allocator_param() {
6-
use crate::alloc::AllocErr;
6+
use crate::alloc::AllocError;
77

88
// Writing a test of integration between third-party
99
// allocators and `RawVec` is a little tricky because the `RawVec`
@@ -21,10 +21,10 @@ fn allocator_param() {
2121
fuel: Cell<usize>,
2222
}
2323
unsafe impl AllocRef for BoundedAlloc {
24-
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
24+
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
2525
let size = layout.size();
2626
if size > self.fuel.get() {
27-
return Err(AllocErr);
27+
return Err(AllocError);
2828
}
2929
match Global.alloc(layout) {
3030
ok @ Ok(_) => {

library/alloc/src/rc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ use core::pin::Pin;
247247
use core::ptr::{self, NonNull};
248248
use core::slice::from_raw_parts_mut;
249249

250-
use crate::alloc::{box_free, handle_alloc_error, AllocErr, AllocRef, Global, Layout};
250+
use crate::alloc::{box_free, handle_alloc_error, AllocError, AllocRef, Global, Layout};
251251
use crate::borrow::{Cow, ToOwned};
252252
use crate::string::String;
253253
use crate::vec::Vec;
@@ -996,7 +996,7 @@ impl<T: ?Sized> Rc<T> {
996996
/// and must return back a (potentially fat)-pointer for the `RcBox<T>`.
997997
unsafe fn allocate_for_layout(
998998
value_layout: Layout,
999-
allocate: impl FnOnce(Layout) -> Result<NonNull<[u8]>, AllocErr>,
999+
allocate: impl FnOnce(Layout) -> Result<NonNull<[u8]>, AllocError>,
10001000
mem_to_rcbox: impl FnOnce(*mut u8) -> *mut RcBox<T>,
10011001
) -> *mut RcBox<T> {
10021002
// Calculate layout using the given value layout.

library/alloc/src/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::slice::from_raw_parts_mut;
2121
use core::sync::atomic;
2222
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst};
2323

24-
use crate::alloc::{box_free, handle_alloc_error, AllocErr, AllocRef, Global, Layout};
24+
use crate::alloc::{box_free, handle_alloc_error, AllocError, AllocRef, Global, Layout};
2525
use crate::borrow::{Cow, ToOwned};
2626
use crate::boxed::Box;
2727
use crate::rc::is_dangling;
@@ -969,7 +969,7 @@ impl<T: ?Sized> Arc<T> {
969969
/// and must return back a (potentially fat)-pointer for the `ArcInner<T>`.
970970
unsafe fn allocate_for_layout(
971971
value_layout: Layout,
972-
allocate: impl FnOnce(Layout) -> Result<NonNull<[u8]>, AllocErr>,
972+
allocate: impl FnOnce(Layout) -> Result<NonNull<[u8]>, AllocError>,
973973
mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T>,
974974
) -> *mut ArcInner<T> {
975975
// Calculate layout using the given value layout.

library/core/src/alloc/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ pub use self::layout::{Layout, LayoutErr};
1313
use crate::fmt;
1414
use crate::ptr::{self, NonNull};
1515

16-
/// The `AllocErr` error indicates an allocation failure
16+
/// The `AllocError` error indicates an allocation failure
1717
/// that may be due to resource exhaustion or to
1818
/// something wrong when combining the given input arguments with this
1919
/// allocator.
2020
#[unstable(feature = "allocator_api", issue = "32838")]
2121
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
22-
pub struct AllocErr;
22+
pub struct AllocError;
2323

2424
// (we need this for downstream impl of trait Error)
2525
#[unstable(feature = "allocator_api", issue = "32838")]
26-
impl fmt::Display for AllocErr {
26+
impl fmt::Display for AllocError {
2727
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2828
f.write_str("memory allocation failed")
2929
}
@@ -109,7 +109,7 @@ pub unsafe trait AllocRef {
109109
/// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar.
110110
///
111111
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
112-
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr>;
112+
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>;
113113

114114
/// Behaves like `alloc`, but also ensures that the returned memory is zero-initialized.
115115
///
@@ -126,7 +126,7 @@ pub unsafe trait AllocRef {
126126
/// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar.
127127
///
128128
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
129-
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
129+
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
130130
let ptr = self.alloc(layout)?;
131131
// SAFETY: `alloc` returns a valid memory block
132132
unsafe { ptr.as_non_null_ptr().as_ptr().write_bytes(0, ptr.len()) }
@@ -187,7 +187,7 @@ pub unsafe trait AllocRef {
187187
ptr: NonNull<u8>,
188188
old_layout: Layout,
189189
new_layout: Layout,
190-
) -> Result<NonNull<[u8]>, AllocErr> {
190+
) -> Result<NonNull<[u8]>, AllocError> {
191191
debug_assert!(
192192
new_layout.size() >= old_layout.size(),
193193
"`new_layout.size()` must be greater than or equal to `old_layout.size()`"
@@ -248,7 +248,7 @@ pub unsafe trait AllocRef {
248248
ptr: NonNull<u8>,
249249
old_layout: Layout,
250250
new_layout: Layout,
251-
) -> Result<NonNull<[u8]>, AllocErr> {
251+
) -> Result<NonNull<[u8]>, AllocError> {
252252
debug_assert!(
253253
new_layout.size() >= old_layout.size(),
254254
"`new_layout.size()` must be greater than or equal to `old_layout.size()`"
@@ -312,7 +312,7 @@ pub unsafe trait AllocRef {
312312
ptr: NonNull<u8>,
313313
old_layout: Layout,
314314
new_layout: Layout,
315-
) -> Result<NonNull<[u8]>, AllocErr> {
315+
) -> Result<NonNull<[u8]>, AllocError> {
316316
debug_assert!(
317317
new_layout.size() <= old_layout.size(),
318318
"`new_layout.size()` must be smaller than or equal to `old_layout.size()`"
@@ -348,12 +348,12 @@ where
348348
A: AllocRef + ?Sized,
349349
{
350350
#[inline]
351-
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
351+
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
352352
(**self).alloc(layout)
353353
}
354354

355355
#[inline]
356-
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
356+
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
357357
(**self).alloc_zeroed(layout)
358358
}
359359

@@ -369,7 +369,7 @@ where
369369
ptr: NonNull<u8>,
370370
old_layout: Layout,
371371
new_layout: Layout,
372-
) -> Result<NonNull<[u8]>, AllocErr> {
372+
) -> Result<NonNull<[u8]>, AllocError> {
373373
// SAFETY: the safety contract must be upheld by the caller
374374
unsafe { (**self).grow(ptr, old_layout, new_layout) }
375375
}
@@ -380,7 +380,7 @@ where
380380
ptr: NonNull<u8>,
381381
old_layout: Layout,
382382
new_layout: Layout,
383-
) -> Result<NonNull<[u8]>, AllocErr> {
383+
) -> Result<NonNull<[u8]>, AllocError> {
384384
// SAFETY: the safety contract must be upheld by the caller
385385
unsafe { (**self).grow_zeroed(ptr, old_layout, new_layout) }
386386
}
@@ -391,7 +391,7 @@ where
391391
ptr: NonNull<u8>,
392392
old_layout: Layout,
393393
new_layout: Layout,
394-
) -> Result<NonNull<[u8]>, AllocErr> {
394+
) -> Result<NonNull<[u8]>, AllocError> {
395395
// SAFETY: the safety contract must be upheld by the caller
396396
unsafe { (**self).shrink(ptr, old_layout, new_layout) }
397397
}

library/core/src/ptr/non_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<T> NonNull<[T]> {
448448
/// // Note that calling `memory.as_mut()` is not allowed here as the content may be uninitialized.
449449
/// # #[allow(unused_variables)]
450450
/// let slice: &mut [MaybeUninit<u8>] = unsafe { memory.as_uninit_slice_mut() };
451-
/// # Ok::<_, std::alloc::AllocErr>(())
451+
/// # Ok::<_, std::alloc::AllocError>(())
452452
/// ```
453453
#[inline]
454454
#[unstable(feature = "ptr_as_uninit", issue = "75402")]

library/std/src/alloc.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub struct System;
133133

134134
impl System {
135135
#[inline]
136-
fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocErr> {
136+
fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> {
137137
match layout.size() {
138138
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
139139
// SAFETY: `layout` is non-zero in size,
@@ -143,7 +143,7 @@ impl System {
143143
} else {
144144
GlobalAlloc::alloc(self, layout)
145145
};
146-
let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
146+
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
147147
Ok(NonNull::slice_from_raw_parts(ptr, size))
148148
},
149149
}
@@ -157,7 +157,7 @@ impl System {
157157
old_layout: Layout,
158158
new_layout: Layout,
159159
zeroed: bool,
160-
) -> Result<NonNull<[u8]>, AllocErr> {
160+
) -> Result<NonNull<[u8]>, AllocError> {
161161
debug_assert!(
162162
new_layout.size() >= old_layout.size(),
163163
"`new_layout.size()` must be greater than or equal to `old_layout.size()`"
@@ -175,7 +175,7 @@ impl System {
175175
intrinsics::assume(new_size >= old_layout.size());
176176

177177
let raw_ptr = GlobalAlloc::realloc(self, ptr.as_ptr(), old_layout, new_size);
178-
let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
178+
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
179179
if zeroed {
180180
raw_ptr.add(old_size).write_bytes(0, new_size - old_size);
181181
}
@@ -202,12 +202,12 @@ impl System {
202202
#[unstable(feature = "allocator_api", issue = "32838")]
203203
unsafe impl AllocRef for System {
204204
#[inline]
205-
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
205+
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
206206
self.alloc_impl(layout, false)
207207
}
208208

209209
#[inline]
210-
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
210+
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
211211
self.alloc_impl(layout, true)
212212
}
213213

@@ -226,7 +226,7 @@ unsafe impl AllocRef for System {
226226
ptr: NonNull<u8>,
227227
old_layout: Layout,
228228
new_layout: Layout,
229-
) -> Result<NonNull<[u8]>, AllocErr> {
229+
) -> Result<NonNull<[u8]>, AllocError> {
230230
// SAFETY: all conditions must be upheld by the caller
231231
unsafe { self.grow_impl(ptr, old_layout, new_layout, false) }
232232
}
@@ -237,7 +237,7 @@ unsafe impl AllocRef for System {
237237
ptr: NonNull<u8>,
238238
old_layout: Layout,
239239
new_layout: Layout,
240-
) -> Result<NonNull<[u8]>, AllocErr> {
240+
) -> Result<NonNull<[u8]>, AllocError> {
241241
// SAFETY: all conditions must be upheld by the caller
242242
unsafe { self.grow_impl(ptr, old_layout, new_layout, true) }
243243
}
@@ -248,7 +248,7 @@ unsafe impl AllocRef for System {
248248
ptr: NonNull<u8>,
249249
old_layout: Layout,
250250
new_layout: Layout,
251-
) -> Result<NonNull<[u8]>, AllocErr> {
251+
) -> Result<NonNull<[u8]>, AllocError> {
252252
debug_assert!(
253253
new_layout.size() <= old_layout.size(),
254254
"`new_layout.size()` must be smaller than or equal to `old_layout.size()`"
@@ -267,7 +267,7 @@ unsafe impl AllocRef for System {
267267
intrinsics::assume(new_size <= old_layout.size());
268268

269269
let raw_ptr = GlobalAlloc::realloc(self, ptr.as_ptr(), old_layout, new_size);
270-
let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
270+
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
271271
Ok(NonNull::slice_from_raw_parts(ptr, new_size))
272272
},
273273

library/std/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod tests;
1919
use core::array;
2020
use core::convert::Infallible;
2121

22-
use crate::alloc::{AllocErr, LayoutErr};
22+
use crate::alloc::{AllocError, LayoutErr};
2323
use crate::any::TypeId;
2424
use crate::backtrace::Backtrace;
2525
use crate::borrow::Cow;
@@ -387,7 +387,7 @@ impl Error for ! {}
387387
reason = "the precise API and guarantees it provides may be tweaked.",
388388
issue = "32838"
389389
)]
390-
impl Error for AllocErr {}
390+
impl Error for AllocError {}
391391

392392
#[stable(feature = "alloc_layout", since = "1.28.0")]
393393
impl Error for LayoutErr {}

0 commit comments

Comments
 (0)