Skip to content

Commit e6a8317

Browse files
authored
Merge pull request #3 from luojia65/master
Adapt to latest nightly Rust (AllocRef API change)
2 parents d73ed7f + 87de860 commit e6a8317

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

.github/workflows/rust.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
rust: [nightly-2020-02-01, nightly-2020-02-03, nightly-2020-03-01, nightly-2020-03-04]
15+
rust:
16+
- nightly-2020-02-01
17+
- nightly-2020-02-03
18+
- nightly-2020-03-01
19+
- nightly-2020-03-04
20+
- nightly-2020-03-10
21+
- nightly-2020-03-11
1622

1723
steps:
1824
- uses: actions/checkout@v2

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-10))]
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-10)]
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)