Skip to content

Commit 626bccb

Browse files
committed
Adapt to latest nightly Rust (AllocRef API change)
1 parent d73ed7f commit 626bccb

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern crate alloc;
1515
#[rustversion::before(2020-02-02)]
1616
use alloc::alloc::Alloc;
1717
#[rustversion::since(2020-02-02)]
18-
use alloc::alloc::AllocRef as Alloc;
18+
use alloc::alloc::AllocRef;
1919
use alloc::alloc::{AllocErr, Layout};
2020
use core::alloc::GlobalAlloc;
2121
use core::cmp::{max, min};
@@ -200,17 +200,34 @@ impl fmt::Debug for Heap {
200200
}
201201
}
202202

203+
#[rustversion::before(2020-02-02)]
203204
unsafe impl Alloc for Heap {
205+
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
206+
self.alloc(layout)
207+
}
208+
209+
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
210+
self.dealloc(ptr, layout)
211+
}
212+
}
213+
214+
#[rustversion::since(2020-02-02)]
215+
unsafe impl AllocRef for Heap {
204216
#[rustversion::before(2020-03-03)]
205217
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
206218
self.alloc(layout)
207219
}
208220

209-
#[rustversion::since(2020-03-03)]
221+
#[rustversion::all(since(2020-03-03), before(2020-03-08))]
210222
unsafe fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
211223
self.alloc(layout).map(|p| (p, layout.size()))
212224
}
213225

226+
#[rustversion::since(2020-03-08)]
227+
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
228+
self.alloc(layout).map(|p| (p, layout.size()))
229+
}
230+
214231
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
215232
self.dealloc(ptr, layout)
216233
}

0 commit comments

Comments
 (0)