Skip to content

Commit cad92e5

Browse files
committed
Rename the Alloc trait to AllocHandle
This is a breaking change to an unstable API. Fixes rust-lang/wg-allocators#8 This change has some consensus. Landing it now will hopefully help clarify the vocabulary, including for discussion within the Allocators WG itself.
1 parent a19cf18 commit cad92e5

File tree

13 files changed

+33
-33
lines changed

13 files changed

+33
-33
lines changed

src/liballoc/alloc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern "Rust" {
3131

3232
/// The global memory allocator.
3333
///
34-
/// This type implements the [`Alloc`] trait by forwarding calls
34+
/// This type implements the [`AllocHandle`] trait by forwarding calls
3535
/// to the allocator registered with the `#[global_allocator]` attribute
3636
/// if there is one, or the `std` crate’s default.
3737
///
@@ -48,7 +48,7 @@ pub struct Global;
4848
/// if there is one, or the `std` crate’s default.
4949
///
5050
/// This function is expected to be deprecated in favor of the `alloc` method
51-
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
51+
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
5252
///
5353
/// # Safety
5454
///
@@ -82,7 +82,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
8282
/// if there is one, or the `std` crate’s default.
8383
///
8484
/// This function is expected to be deprecated in favor of the `dealloc` method
85-
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
85+
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
8686
///
8787
/// # Safety
8888
///
@@ -100,7 +100,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
100100
/// if there is one, or the `std` crate’s default.
101101
///
102102
/// This function is expected to be deprecated in favor of the `realloc` method
103-
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
103+
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
104104
///
105105
/// # Safety
106106
///
@@ -118,7 +118,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
118118
/// if there is one, or the `std` crate’s default.
119119
///
120120
/// This function is expected to be deprecated in favor of the `alloc_zeroed` method
121-
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
121+
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
122122
///
123123
/// # Safety
124124
///
@@ -145,7 +145,7 @@ pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
145145
}
146146

147147
#[unstable(feature = "allocator_api", issue = "32838")]
148-
unsafe impl Alloc for Global {
148+
unsafe impl AllocHandle for Global {
149149
#[inline]
150150
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
151151
NonNull::new(alloc(layout)).ok_or(AllocErr)
@@ -232,7 +232,7 @@ mod tests {
232232
extern crate test;
233233
use test::Bencher;
234234
use crate::boxed::Box;
235-
use crate::alloc::{Global, Alloc, Layout, handle_alloc_error};
235+
use crate::alloc::{Global, AllocHandle, Layout, handle_alloc_error};
236236

237237
#[test]
238238
fn allocate_zeroed() {

src/liballoc/collections/btree/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use core::mem::{self, MaybeUninit};
3636
use core::ptr::{self, Unique, NonNull};
3737
use core::slice;
3838

39-
use crate::alloc::{Global, Alloc, Layout};
39+
use crate::alloc::{Global, AllocHandle, Layout};
4040
use crate::boxed::Box;
4141

4242
const B: usize = 6;

src/liballoc/raw_vec.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::ops::Drop;
77
use core::ptr::{self, NonNull, Unique};
88
use core::slice;
99

10-
use crate::alloc::{Alloc, Layout, Global, handle_alloc_error};
10+
use crate::alloc::{AllocHandle, Layout, Global, handle_alloc_error};
1111
use crate::collections::CollectionAllocErr::{self, *};
1212
use crate::boxed::Box;
1313

@@ -39,13 +39,13 @@ use crate::boxed::Box;
3939
/// field. This allows zero-sized types to not be special-cased by consumers of
4040
/// this type.
4141
#[allow(missing_debug_implementations)]
42-
pub struct RawVec<T, A: Alloc = Global> {
42+
pub struct RawVec<T, A: AllocHandle = Global> {
4343
ptr: Unique<T>,
4444
cap: usize,
4545
a: A,
4646
}
4747

48-
impl<T, A: Alloc> RawVec<T, A> {
48+
impl<T, A: AllocHandle> RawVec<T, A> {
4949
/// Like `new` but parameterized over the choice of allocator for
5050
/// the returned RawVec.
5151
pub const fn new_in(a: A) -> Self {
@@ -146,7 +146,7 @@ impl<T> RawVec<T, Global> {
146146
}
147147
}
148148

149-
impl<T, A: Alloc> RawVec<T, A> {
149+
impl<T, A: AllocHandle> RawVec<T, A> {
150150
/// Reconstitutes a RawVec from a pointer, capacity, and allocator.
151151
///
152152
/// # Undefined Behavior
@@ -189,7 +189,7 @@ impl<T> RawVec<T, Global> {
189189
}
190190
}
191191

192-
impl<T, A: Alloc> RawVec<T, A> {
192+
impl<T, A: AllocHandle> RawVec<T, A> {
193193
/// Gets a raw pointer to the start of the allocation. Note that this is
194194
/// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must
195195
/// be careful.
@@ -629,7 +629,7 @@ enum ReserveStrategy {
629629

630630
use ReserveStrategy::*;
631631

632-
impl<T, A: Alloc> RawVec<T, A> {
632+
impl<T, A: AllocHandle> RawVec<T, A> {
633633
fn reserve_internal(
634634
&mut self,
635635
used_cap: usize,
@@ -700,7 +700,7 @@ impl<T> RawVec<T, Global> {
700700
}
701701
}
702702

703-
impl<T, A: Alloc> RawVec<T, A> {
703+
impl<T, A: AllocHandle> RawVec<T, A> {
704704
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
705705
pub unsafe fn dealloc_buffer(&mut self) {
706706
let elem_size = mem::size_of::<T>();
@@ -712,7 +712,7 @@ impl<T, A: Alloc> RawVec<T, A> {
712712
}
713713
}
714714

715-
unsafe impl<#[may_dangle] T, A: Alloc> Drop for RawVec<T, A> {
715+
unsafe impl<#[may_dangle] T, A: AllocHandle> Drop for RawVec<T, A> {
716716
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
717717
fn drop(&mut self) {
718718
unsafe { self.dealloc_buffer(); }
@@ -767,7 +767,7 @@ mod tests {
767767
// A dumb allocator that consumes a fixed amount of fuel
768768
// before allocation attempts start failing.
769769
struct BoundedAlloc { fuel: usize }
770-
unsafe impl Alloc for BoundedAlloc {
770+
unsafe impl AllocHandle for BoundedAlloc {
771771
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
772772
let size = layout.size();
773773
if size > self.fuel {

src/liballoc/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ use core::slice::from_raw_parts_mut;
247247
use core::convert::From;
248248
use core::usize;
249249

250-
use crate::alloc::{Global, Alloc, Layout, box_free, handle_alloc_error};
250+
use crate::alloc::{Global, AllocHandle, Layout, box_free, handle_alloc_error};
251251
use crate::string::String;
252252
use crate::vec::Vec;
253253

src/liballoc/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use core::{isize, usize};
2323
use core::convert::From;
2424
use core::slice::from_raw_parts_mut;
2525

26-
use crate::alloc::{Global, Alloc, Layout, box_free, handle_alloc_error};
26+
use crate::alloc::{Global, AllocHandle, Layout, box_free, handle_alloc_error};
2727
use crate::boxed::Box;
2828
use crate::rc::is_dangling;
2929
use crate::string::String;

src/liballoc/tests/heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::alloc::{Global, Alloc, Layout, System};
1+
use std::alloc::{Global, AllocHandle, Layout, System};
22

33
/// Issue #45955.
44
#[test]
@@ -11,7 +11,7 @@ fn std_heap_overaligned_request() {
1111
check_overalign_requests(Global)
1212
}
1313

14-
fn check_overalign_requests<T: Alloc>(mut allocator: T) {
14+
fn check_overalign_requests<T: AllocHandle>(mut allocator: T) {
1515
let size = 8;
1616
let align = 16; // greater than size
1717
let iterations = 100;

src/libcore/alloc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ pub unsafe trait GlobalAlloc {
579579
}
580580
}
581581

582-
/// An implementation of `Alloc` can allocate, reallocate, and
582+
/// A handle to a memory allocator that can allocate, reallocate, and
583583
/// deallocate arbitrary blocks of data described via `Layout`.
584584
///
585585
/// Some of the methods require that a memory block be *currently
@@ -645,11 +645,11 @@ pub unsafe trait GlobalAlloc {
645645
///
646646
/// # Safety
647647
///
648-
/// The `Alloc` trait is an `unsafe` trait for a number of reasons, and
648+
/// The `AllocHandle` trait is an `unsafe` trait for a number of reasons, and
649649
/// implementors must ensure that they adhere to these contracts:
650650
///
651651
/// * Pointers returned from allocation functions must point to valid memory and
652-
/// retain their validity until at least the instance of `Alloc` is dropped
652+
/// retain their validity until at least the instance of `AllocHandle` is dropped
653653
/// itself.
654654
///
655655
/// * `Layout` queries and calculations in general must be correct. Callers of
@@ -659,7 +659,7 @@ pub unsafe trait GlobalAlloc {
659659
/// Note that this list may get tweaked over time as clarifications are made in
660660
/// the future.
661661
#[unstable(feature = "allocator_api", issue = "32838")]
662-
pub unsafe trait Alloc {
662+
pub unsafe trait AllocHandle {
663663

664664
// (Note: some existing allocators have unspecified but well-defined
665665
// behavior in response to a zero size allocation request ;
@@ -1046,7 +1046,7 @@ pub unsafe trait Alloc {
10461046
/// must be considered "currently allocated" and must be
10471047
/// acceptable input to methods such as `realloc` or `dealloc`,
10481048
/// *even if* `T` is a zero-sized type. In other words, if your
1049-
/// `Alloc` implementation overrides this method in a manner
1049+
/// `AllocHandle` implementation overrides this method in a manner
10501050
/// that can return a zero-sized `ptr`, then all reallocation and
10511051
/// deallocation methods need to be similarly overridden to accept
10521052
/// such values as input.
@@ -1112,7 +1112,7 @@ pub unsafe trait Alloc {
11121112
/// must be considered "currently allocated" and must be
11131113
/// acceptable input to methods such as `realloc` or `dealloc`,
11141114
/// *even if* `T` is a zero-sized type. In other words, if your
1115-
/// `Alloc` implementation overrides this method in a manner
1115+
/// `AllocHandle` implementation overrides this method in a manner
11161116
/// that can return a zero-sized `ptr`, then all reallocation and
11171117
/// deallocation methods need to be similarly overridden to accept
11181118
/// such values as input.

src/libstd/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub struct System;
135135

136136
// The Alloc impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`.
137137
#[unstable(feature = "allocator_api", issue = "32838")]
138-
unsafe impl Alloc for System {
138+
unsafe impl AllocHandle for System {
139139
#[inline]
140140
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
141141
NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr)

src/test/run-pass/allocator-alloc-one.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![feature(allocator_api, nonnull)]
44

5-
use std::alloc::{Alloc, Global, Layout, handle_alloc_error};
5+
use std::alloc::{AllocHandle, Global, Layout, handle_alloc_error};
66

77
fn main() {
88
unsafe {

src/test/run-pass/allocator/custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
extern crate helper;
99

10-
use std::alloc::{self, Global, Alloc, System, Layout};
10+
use std::alloc::{self, Global, AllocHandle, System, Layout};
1111
use std::sync::atomic::{AtomicUsize, Ordering};
1212

1313
static HITS: AtomicUsize = AtomicUsize::new(0);

src/test/run-pass/allocator/xcrate-use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
extern crate custom;
1010
extern crate helper;
1111

12-
use std::alloc::{Global, Alloc, System, Layout};
12+
use std::alloc::{Global, AllocHandle, System, Layout};
1313
use std::sync::atomic::{Ordering, AtomicUsize};
1414

1515
#[global_allocator]

src/test/run-pass/realloc-16687.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#![feature(allocator_api)]
77

8-
use std::alloc::{Global, Alloc, Layout, handle_alloc_error};
8+
use std::alloc::{Global, AllocHandle, Layout, handle_alloc_error};
99
use std::ptr::{self, NonNull};
1010

1111
fn main() {

src/test/run-pass/regions/regions-mock-codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#![feature(allocator_api)]
88

9-
use std::alloc::{Alloc, Global, Layout, handle_alloc_error};
9+
use std::alloc::{AllocHandle, Global, Layout, handle_alloc_error};
1010
use std::ptr::NonNull;
1111

1212
struct arena(());

0 commit comments

Comments
 (0)