Skip to content

Commit ea89051

Browse files
committed
Fix tests
1 parent 29e3fbc commit ea89051

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

src/test/run-make-fulldeps/std-core-cycle/bar.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
#![crate_type = "rlib"]
1313

1414
use std::alloc::*;
15+
use std::ptr::NonNull;
1516

1617
pub struct A;
1718

1819
unsafe impl GlobalAlloc for A {
19-
unsafe fn alloc(&self, _: Layout) -> *mut Opaque {
20+
unsafe fn alloc(&self, _: Layout) -> Result<NonNull<Opaque>, AllocErr> {
2021
loop {}
2122
}
2223

23-
unsafe fn dealloc(&self, _ptr: *mut Opaque, _: Layout) {
24+
unsafe fn dealloc(&self, _ptr: NonNull<Opaque>, _: Layout) {
2425
loop {}
2526
}
2627
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
#![feature(heap_api, allocator_api)]
1414
#![crate_type = "rlib"]
1515

16-
use std::alloc::{GlobalAlloc, System, Layout, Opaque};
16+
use std::alloc::{AllocErr, GlobalAlloc, System, Layout, Opaque};
17+
use std::ptr::NonNull;
1718
use std::sync::atomic::{AtomicUsize, Ordering};
1819

1920
pub struct A(pub AtomicUsize);
2021

2122
unsafe impl GlobalAlloc for A {
22-
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
23+
unsafe fn alloc(&self, layout: Layout) -> Result<NonNull<Opaque>, AllocErr> {
2324
self.0.fetch_add(1, Ordering::SeqCst);
2425
System.alloc(layout)
2526
}
2627

27-
unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {
28+
unsafe fn dealloc(&self, ptr: NonNull<Opaque>, layout: Layout) {
2829
self.0.fetch_add(1, Ordering::SeqCst);
2930
System.dealloc(ptr, layout)
3031
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515

1616
extern crate helper;
1717

18-
use std::alloc::{self, Global, Alloc, System, Layout, Opaque};
18+
use std::alloc::{self, Global, Alloc, AllocErr, System, Layout, Opaque};
1919
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
20+
use std::ptr::NonNull;
2021

2122
static HITS: AtomicUsize = ATOMIC_USIZE_INIT;
2223

2324
struct A;
2425

2526
unsafe impl alloc::GlobalAlloc for A {
26-
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
27+
unsafe fn alloc(&self, layout: Layout) -> Result<NonNull<Opaque>, AllocErr> {
2728
HITS.fetch_add(1, Ordering::SeqCst);
2829
System.alloc(layout)
2930
}
3031

31-
unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {
32+
unsafe fn dealloc(&self, ptr: NonNull<Opaque>, layout: Layout) {
3233
HITS.fetch_add(1, Ordering::SeqCst);
3334
System.dealloc(ptr, layout)
3435
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ fn main() {
3030
let layout = Layout::from_size_align(4, 2).unwrap();
3131

3232
// Global allocator routes to the `custom_as_global` global
33-
let ptr = Global.alloc(layout.clone());
33+
let ptr = Global.alloc(layout.clone()).unwrap();
3434
helper::work_with(&ptr);
3535
assert_eq!(custom_as_global::get(), n + 1);
3636
Global.dealloc(ptr, layout.clone());
3737
assert_eq!(custom_as_global::get(), n + 2);
3838

3939
// Usage of the system allocator avoids all globals
40-
let ptr = System.alloc(layout.clone());
40+
let ptr = System.alloc(layout.clone()).unwrap();
4141
helper::work_with(&ptr);
4242
assert_eq!(custom_as_global::get(), n + 2);
4343
System.dealloc(ptr, layout.clone());
4444
assert_eq!(custom_as_global::get(), n + 2);
4545

4646
// Usage of our personal allocator doesn't affect other instances
47-
let ptr = GLOBAL.alloc(layout.clone());
47+
let ptr = GLOBAL.alloc(layout.clone()).unwrap();
4848
helper::work_with(&ptr);
4949
assert_eq!(custom_as_global::get(), n + 2);
5050
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 1);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ unsafe fn test_triangle() -> bool {
6464
println!("deallocate({:?}, {:?}", ptr, layout);
6565
}
6666

67-
Global.dealloc(NonNull::new_unchecked(ptr).as_opaque(), layout);
67+
Global.dealloc(NonNull::new_unchecked(ptr).cast(), layout);
6868
}
6969

7070
unsafe fn reallocate(ptr: *mut u8, old: Layout, new: Layout) -> *mut u8 {
7171
if PRINT {
7272
println!("reallocate({:?}, old={:?}, new={:?})", ptr, old, new);
7373
}
7474

75-
let ret = Global.realloc(NonNull::new_unchecked(ptr).as_opaque(), old, new.size())
75+
let ret = Global.realloc(NonNull::new_unchecked(ptr).cast(), old, new.size())
7676
.unwrap_or_else(|_| oom(Layout::from_size_align_unchecked(new.size(), old.align())));
7777

7878
if PRINT {

0 commit comments

Comments
 (0)