Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to latest nightly Rust (AllocRef API change) #3

Merged
merged 3 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [nightly-2020-02-01, nightly-2020-02-03, nightly-2020-03-01, nightly-2020-03-04]
rust:
- nightly-2020-02-01
- nightly-2020-02-03
- nightly-2020-03-01
- nightly-2020-03-04
- nightly-2020-03-10
- nightly-2020-03-11

steps:
- uses: actions/checkout@v2
Expand Down
21 changes: 19 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate alloc;
#[rustversion::before(2020-02-02)]
use alloc::alloc::Alloc;
#[rustversion::since(2020-02-02)]
use alloc::alloc::AllocRef as Alloc;
use alloc::alloc::AllocRef;
use alloc::alloc::{AllocErr, Layout};
use core::alloc::GlobalAlloc;
use core::cmp::{max, min};
Expand Down Expand Up @@ -200,17 +200,34 @@ impl fmt::Debug for Heap {
}
}

#[rustversion::before(2020-02-02)]
unsafe impl Alloc for Heap {
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
self.alloc(layout)
}

unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
self.dealloc(ptr, layout)
}
}

#[rustversion::since(2020-02-02)]
unsafe impl AllocRef for Heap {
#[rustversion::before(2020-03-03)]
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
self.alloc(layout)
}

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

#[rustversion::since(2020-03-10)]
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
self.alloc(layout).map(|p| (p, layout.size()))
}

unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
self.dealloc(ptr, layout)
}
Expand Down