Skip to content

Commit e521b8b

Browse files
committed
Actually deprecate the Heap type
1 parent 88ebd2d commit e521b8b

File tree

9 files changed

+47
-46
lines changed

9 files changed

+47
-46
lines changed

src/liballoc/alloc.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ pub struct Global;
8181

8282
#[unstable(feature = "allocator_api", issue = "32838")]
8383
#[rustc_deprecated(since = "1.27.0", reason = "type renamed to `Global`")]
84-
pub use self::Global as Heap;
84+
pub type Heap = Global;
8585

86+
#[unstable(feature = "allocator_api", issue = "32838")]
87+
#[rustc_deprecated(since = "1.27.0", reason = "type renamed to `Global`")]
88+
#[allow(non_upper_case_globals)]
89+
pub const Heap: Global = Global;
8690

8791
unsafe impl Alloc for Global {
8892
#[inline]
@@ -268,7 +272,7 @@ mod tests {
268272
extern crate test;
269273
use self::test::Bencher;
270274
use boxed::Box;
271-
use heap::{Global, Alloc, Layout};
275+
use alloc::{Global, Alloc, Layout};
272276

273277
#[test]
274278
fn allocate_zeroed() {

src/liballoc/arc.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst};
2121
use core::borrow;
2222
use core::fmt;
2323
use core::cmp::Ordering;
24-
use core::heap::{Alloc, Layout};
2524
use core::intrinsics::abort;
2625
use core::mem::{self, align_of_val, size_of_val, uninitialized};
2726
use core::ops::Deref;
@@ -32,7 +31,7 @@ use core::hash::{Hash, Hasher};
3231
use core::{isize, usize};
3332
use core::convert::From;
3433

35-
use heap::{Heap, box_free};
34+
use alloc::{Global, Alloc, Layout, box_free};
3635
use boxed::Box;
3736
use string::String;
3837
use vec::Vec;
@@ -521,7 +520,7 @@ impl<T: ?Sized> Arc<T> {
521520

522521
if self.inner().weak.fetch_sub(1, Release) == 1 {
523522
atomic::fence(Acquire);
524-
Heap.dealloc(ptr as *mut u8, Layout::for_value(&*ptr))
523+
Global.dealloc(ptr as *mut u8, Layout::for_value(&*ptr))
525524
}
526525
}
527526

@@ -555,8 +554,8 @@ impl<T: ?Sized> Arc<T> {
555554

556555
let layout = Layout::for_value(&*fake_ptr);
557556

558-
let mem = Heap.alloc(layout)
559-
.unwrap_or_else(|e| Heap.oom(e));
557+
let mem = Global.alloc(layout)
558+
.unwrap_or_else(|e| Global.oom(e));
560559

561560
// Initialize the real ArcInner
562561
let inner = set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>;
@@ -640,7 +639,7 @@ impl<T: Clone> ArcFromSlice<T> for Arc<[T]> {
640639
let slice = from_raw_parts_mut(self.elems, self.n_elems);
641640
ptr::drop_in_place(slice);
642641

643-
Heap.dealloc(self.mem, self.layout.clone());
642+
Global.dealloc(self.mem, self.layout.clone());
644643
}
645644
}
646645
}
@@ -1161,7 +1160,7 @@ impl<T: ?Sized> Drop for Weak<T> {
11611160
if self.inner().weak.fetch_sub(1, Release) == 1 {
11621161
atomic::fence(Acquire);
11631162
unsafe {
1164-
Heap.dealloc(ptr as *mut u8, Layout::for_value(&*ptr))
1163+
Global.dealloc(ptr as *mut u8, Layout::for_value(&*ptr))
11651164
}
11661165
}
11671166
}

src/liballoc/btree/node.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@
4141
// - A node of length `n` has `n` keys, `n` values, and (in an internal node) `n + 1` edges.
4242
// This implies that even an empty internal node has at least one edge.
4343

44-
use core::heap::{Alloc, Layout};
4544
use core::marker::PhantomData;
4645
use core::mem;
4746
use core::ptr::{self, Unique, NonNull};
4847
use core::slice;
4948

49+
use alloc::{Global, Alloc, Layout};
5050
use boxed::Box;
51-
use heap::Heap;
5251

5352
const B: usize = 6;
5453
pub const MIN_LEN: usize = B - 1;
@@ -250,7 +249,7 @@ impl<K, V> Root<K, V> {
250249
self.as_mut().as_leaf_mut().parent = ptr::null();
251250

252251
unsafe {
253-
Heap.dealloc(top, Layout::new::<InternalNode<K, V>>());
252+
Global.dealloc(top, Layout::new::<InternalNode<K, V>>());
254253
}
255254
}
256255
}
@@ -436,7 +435,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::Leaf> {
436435
> {
437436
let ptr = self.as_leaf() as *const LeafNode<K, V> as *const u8 as *mut u8;
438437
let ret = self.ascend().ok();
439-
Heap.dealloc(ptr, Layout::new::<LeafNode<K, V>>());
438+
Global.dealloc(ptr, Layout::new::<LeafNode<K, V>>());
440439
ret
441440
}
442441
}
@@ -457,7 +456,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::Internal> {
457456
> {
458457
let ptr = self.as_internal() as *const InternalNode<K, V> as *const u8 as *mut u8;
459458
let ret = self.ascend().ok();
460-
Heap.dealloc(ptr, Layout::new::<InternalNode<K, V>>());
459+
Global.dealloc(ptr, Layout::new::<InternalNode<K, V>>());
461460
ret
462461
}
463462
}
@@ -1239,12 +1238,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
12391238
).correct_parent_link();
12401239
}
12411240

1242-
Heap.dealloc(
1241+
Global.dealloc(
12431242
right_node.node.as_ptr() as *mut u8,
12441243
Layout::new::<InternalNode<K, V>>(),
12451244
);
12461245
} else {
1247-
Heap.dealloc(
1246+
Global.dealloc(
12481247
right_node.node.as_ptr() as *mut u8,
12491248
Layout::new::<LeafNode<K, V>>(),
12501249
);

src/liballoc/raw_vec.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use alloc::{Alloc, Layout, Global};
1112
use core::cmp;
12-
use core::heap::{Alloc, Layout};
1313
use core::mem;
1414
use core::ops::Drop;
1515
use core::ptr::{self, Unique};
1616
use core::slice;
17-
use heap::Heap;
1817
use super::boxed::Box;
1918
use super::allocator::CollectionAllocErr;
2019
use super::allocator::CollectionAllocErr::*;
@@ -47,7 +46,7 @@ use super::allocator::CollectionAllocErr::*;
4746
/// field. This allows zero-sized types to not be special-cased by consumers of
4847
/// this type.
4948
#[allow(missing_debug_implementations)]
50-
pub struct RawVec<T, A: Alloc = Heap> {
49+
pub struct RawVec<T, A: Alloc = Global> {
5150
ptr: Unique<T>,
5251
cap: usize,
5352
a: A,
@@ -114,14 +113,14 @@ impl<T, A: Alloc> RawVec<T, A> {
114113
}
115114
}
116115

117-
impl<T> RawVec<T, Heap> {
116+
impl<T> RawVec<T, Global> {
118117
/// Creates the biggest possible RawVec (on the system heap)
119118
/// without allocating. If T has positive size, then this makes a
120119
/// RawVec with capacity 0. If T has 0 size, then it makes a
121120
/// RawVec with capacity `usize::MAX`. Useful for implementing
122121
/// delayed allocation.
123122
pub fn new() -> Self {
124-
Self::new_in(Heap)
123+
Self::new_in(Global)
125124
}
126125

127126
/// Creates a RawVec (on the system heap) with exactly the
@@ -141,13 +140,13 @@ impl<T> RawVec<T, Heap> {
141140
/// Aborts on OOM
142141
#[inline]
143142
pub fn with_capacity(cap: usize) -> Self {
144-
RawVec::allocate_in(cap, false, Heap)
143+
RawVec::allocate_in(cap, false, Global)
145144
}
146145

147146
/// Like `with_capacity` but guarantees the buffer is zeroed.
148147
#[inline]
149148
pub fn with_capacity_zeroed(cap: usize) -> Self {
150-
RawVec::allocate_in(cap, true, Heap)
149+
RawVec::allocate_in(cap, true, Global)
151150
}
152151
}
153152

@@ -168,7 +167,7 @@ impl<T, A: Alloc> RawVec<T, A> {
168167
}
169168
}
170169

171-
impl<T> RawVec<T, Heap> {
170+
impl<T> RawVec<T, Global> {
172171
/// Reconstitutes a RawVec from a pointer, capacity.
173172
///
174173
/// # Undefined Behavior
@@ -180,7 +179,7 @@ impl<T> RawVec<T, Heap> {
180179
RawVec {
181180
ptr: Unique::new_unchecked(ptr),
182181
cap,
183-
a: Heap,
182+
a: Global,
184183
}
185184
}
186185

@@ -678,7 +677,7 @@ impl<T, A: Alloc> RawVec<T, A> {
678677
}
679678
}
680679

681-
impl<T> RawVec<T, Heap> {
680+
impl<T> RawVec<T, Global> {
682681
/// Converts the entire buffer into `Box<[T]>`.
683682
///
684683
/// While it is not *strictly* Undefined Behavior to call
@@ -763,13 +762,13 @@ mod tests {
763762
if size > self.fuel {
764763
return Err(AllocErr::Unsupported { details: "fuel exhausted" });
765764
}
766-
match Heap.alloc(layout) {
765+
match Global.alloc(layout) {
767766
ok @ Ok(_) => { self.fuel -= size; ok }
768767
err @ Err(_) => err,
769768
}
770769
}
771770
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
772-
Heap.dealloc(ptr, layout)
771+
Global.dealloc(ptr, layout)
773772
}
774773
}
775774

src/liballoc/rc.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ use core::cell::Cell;
250250
use core::cmp::Ordering;
251251
use core::fmt;
252252
use core::hash::{Hash, Hasher};
253-
use core::heap::{Alloc, Layout};
254253
use core::intrinsics::abort;
255254
use core::marker;
256255
use core::marker::{Unsize, PhantomData};
@@ -260,7 +259,7 @@ use core::ops::CoerceUnsized;
260259
use core::ptr::{self, NonNull};
261260
use core::convert::From;
262261

263-
use heap::{Heap, box_free};
262+
use alloc::{Global, Alloc, Layout, box_free};
264263
use string::String;
265264
use vec::Vec;
266265

@@ -668,8 +667,8 @@ impl<T: ?Sized> Rc<T> {
668667

669668
let layout = Layout::for_value(&*fake_ptr);
670669

671-
let mem = Heap.alloc(layout)
672-
.unwrap_or_else(|e| Heap.oom(e));
670+
let mem = Global.alloc(layout)
671+
.unwrap_or_else(|e| Global.oom(e));
673672

674673
// Initialize the real RcBox
675674
let inner = set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>;
@@ -752,7 +751,7 @@ impl<T: Clone> RcFromSlice<T> for Rc<[T]> {
752751
let slice = from_raw_parts_mut(self.elems, self.n_elems);
753752
ptr::drop_in_place(slice);
754753

755-
Heap.dealloc(self.mem, self.layout.clone());
754+
Global.dealloc(self.mem, self.layout.clone());
756755
}
757756
}
758757
}
@@ -847,7 +846,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
847846
self.dec_weak();
848847

849848
if self.weak() == 0 {
850-
Heap.dealloc(ptr as *mut u8, Layout::for_value(&*ptr));
849+
Global.dealloc(ptr as *mut u8, Layout::for_value(&*ptr));
851850
}
852851
}
853852
}
@@ -1273,7 +1272,7 @@ impl<T: ?Sized> Drop for Weak<T> {
12731272
// the weak count starts at 1, and will only go to zero if all
12741273
// the strong pointers have disappeared.
12751274
if self.weak() == 0 {
1276-
Heap.dealloc(ptr as *mut u8, Layout::for_value(&*ptr));
1275+
Global.dealloc(ptr as *mut u8, Layout::for_value(&*ptr));
12771276
}
12781277
}
12791278
}

src/liballoc/tests/heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use alloc_system::System;
12-
use std::heap::{Heap, Alloc, Layout};
12+
use std::alloc::{Global, Alloc, Layout};
1313

1414
/// https://github.com/rust-lang/rust/issues/45955
1515
///
@@ -22,7 +22,7 @@ fn alloc_system_overaligned_request() {
2222

2323
#[test]
2424
fn std_heap_overaligned_request() {
25-
check_overalign_requests(Heap)
25+
check_overalign_requests(Global)
2626
}
2727

2828
fn check_overalign_requests<T: Alloc>(mut allocator: T) {

src/libstd/alloc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
1313
#![unstable(issue = "32838", feature = "allocator_api")]
1414

15-
#[doc(inline)] pub use alloc_crate::alloc::Heap;
15+
#[doc(inline)] #[allow(deprecated)] pub use alloc_crate::alloc::Heap;
16+
#[doc(inline)] pub use alloc_crate::alloc::Global;
1617
#[doc(inline)] pub use alloc_system::System;
1718
#[doc(inline)] pub use core::alloc::*;
1819

src/libstd/collections/hash/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
use self::Entry::*;
1212
use self::VacantEntryState::*;
1313

14+
use alloc::{Global, Alloc, CollectionAllocErr};
1415
use cell::Cell;
1516
use borrow::Borrow;
1617
use cmp::max;
1718
use fmt::{self, Debug};
1819
#[allow(deprecated)]
1920
use hash::{Hash, Hasher, BuildHasher, SipHasher13};
20-
use heap::{Heap, Alloc, CollectionAllocErr};
2121
use iter::{FromIterator, FusedIterator};
2222
use mem::{self, replace};
2323
use ops::{Deref, Index};
@@ -784,7 +784,7 @@ impl<K, V, S> HashMap<K, V, S>
784784
pub fn reserve(&mut self, additional: usize) {
785785
match self.try_reserve(additional) {
786786
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
787-
Err(CollectionAllocErr::AllocErr(e)) => Heap.oom(e),
787+
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
788788
Ok(()) => { /* yay */ }
789789
}
790790
}

src/libstd/collections/hash/table.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use alloc::{Global, Alloc, Layout, CollectionAllocErr};
1112
use cmp;
1213
use hash::{BuildHasher, Hash, Hasher};
13-
use heap::{Heap, Alloc, Layout, CollectionAllocErr};
1414
use marker;
1515
use mem::{align_of, size_of, needs_drop};
1616
use mem;
@@ -754,7 +754,7 @@ impl<K, V> RawTable<K, V> {
754754
return Err(CollectionAllocErr::CapacityOverflow);
755755
}
756756

757-
let buffer = Heap.alloc(Layout::from_size_align(size, alignment)
757+
let buffer = Global.alloc(Layout::from_size_align(size, alignment)
758758
.ok_or(CollectionAllocErr::CapacityOverflow)?)?;
759759

760760
let hashes = buffer as *mut HashUint;
@@ -772,7 +772,7 @@ impl<K, V> RawTable<K, V> {
772772
unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> {
773773
match Self::try_new_uninitialized(capacity) {
774774
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
775-
Err(CollectionAllocErr::AllocErr(e)) => Heap.oom(e),
775+
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
776776
Ok(table) => { table }
777777
}
778778
}
@@ -811,7 +811,7 @@ impl<K, V> RawTable<K, V> {
811811
pub fn new(capacity: usize) -> RawTable<K, V> {
812812
match Self::try_new(capacity) {
813813
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
814-
Err(CollectionAllocErr::AllocErr(e)) => Heap.oom(e),
814+
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
815815
Ok(table) => { table }
816816
}
817817
}
@@ -1185,8 +1185,8 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable<K, V> {
11851185
debug_assert!(!oflo, "should be impossible");
11861186

11871187
unsafe {
1188-
Heap.dealloc(self.hashes.ptr() as *mut u8,
1189-
Layout::from_size_align(size, align).unwrap());
1188+
Global.dealloc(self.hashes.ptr() as *mut u8,
1189+
Layout::from_size_align(size, align).unwrap());
11901190
// Remember how everything was allocated out of one buffer
11911191
// during initialization? We only need one call to free here.
11921192
}

0 commit comments

Comments
 (0)