Skip to content

Commit 07a364e

Browse files
committed
Remove the impl Alloc for System
See rust-lang/wg-allocators#2
1 parent 1891bfa commit 07a364e

File tree

4 files changed

+9
-42
lines changed

4 files changed

+9
-42
lines changed

src/liballoc/tests/heap.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
use std::alloc::{Global, Alloc, Layout, System};
1+
use std::alloc::{GlobalAlloc, Layout, System};
22

33
/// Issue #45955.
44
#[test]
55
fn alloc_system_overaligned_request() {
66
check_overalign_requests(System)
77
}
88

9-
#[test]
10-
fn std_heap_overaligned_request() {
11-
check_overalign_requests(Global)
12-
}
13-
14-
fn check_overalign_requests<T: Alloc>(mut allocator: T) {
9+
fn check_overalign_requests<T: GlobalAlloc>(allocator: T) {
1510
let size = 8;
1611
let align = 16; // greater than size
1712
let iterations = 100;
1813
unsafe {
1914
let pointers: Vec<_> = (0..iterations).map(|_| {
20-
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
15+
allocator.alloc(Layout::from_size_align(size, align).unwrap())
2116
}).collect();
2217
for &ptr in &pointers {
23-
assert_eq!((ptr.as_ptr() as usize) % align, 0,
18+
assert_eq!((ptr as usize) % align, 0,
2419
"Got a pointer less aligned than requested")
2520
}
2621

src/libstd/alloc.rs

-28
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363

6464
use core::sync::atomic::{AtomicPtr, Ordering};
6565
use core::{mem, ptr};
66-
use core::ptr::NonNull;
6766

6867
use crate::sys_common::util::dumb_print;
6968

@@ -133,33 +132,6 @@ pub use alloc_crate::alloc::*;
133132
#[derive(Debug, Default, Copy, Clone)]
134133
pub struct System;
135134

136-
// The Alloc impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`.
137-
#[unstable(feature = "allocator_api", issue = "32838")]
138-
unsafe impl Alloc for System {
139-
#[inline]
140-
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
141-
NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr)
142-
}
143-
144-
#[inline]
145-
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
146-
NonNull::new(GlobalAlloc::alloc_zeroed(self, layout)).ok_or(AllocErr)
147-
}
148-
149-
#[inline]
150-
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
151-
GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
152-
}
153-
154-
#[inline]
155-
unsafe fn realloc(&mut self,
156-
ptr: NonNull<u8>,
157-
layout: Layout,
158-
new_size: usize) -> Result<NonNull<u8>, AllocErr> {
159-
NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
160-
}
161-
}
162-
163135
static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
164136

165137
/// Registers a custom allocation error hook, replacing any that was previously registered.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
extern crate helper;
99

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

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

1515
struct A;
1616

17-
unsafe impl alloc::GlobalAlloc for A {
17+
unsafe impl GlobalAlloc for A {
1818
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
1919
HITS.fetch_add(1, Ordering::SeqCst);
2020
System.alloc(layout)
@@ -49,7 +49,7 @@ fn main() {
4949
drop(s);
5050
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
5151

52-
let ptr = System.alloc(layout.clone()).unwrap();
52+
let ptr = System.alloc(layout.clone());
5353
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
5454
helper::work_with(&ptr);
5555
System.dealloc(ptr, layout);

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

+2-2
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, Alloc, GlobalAlloc, System, Layout};
1313
use std::sync::atomic::{Ordering, AtomicUsize};
1414

1515
#[global_allocator]
@@ -26,7 +26,7 @@ fn main() {
2626
Global.dealloc(ptr, layout.clone());
2727
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
2828

29-
let ptr = System.alloc(layout.clone()).unwrap();
29+
let ptr = System.alloc(layout.clone());
3030
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
3131
helper::work_with(&ptr);
3232
System.dealloc(ptr, layout);

0 commit comments

Comments
 (0)