Skip to content

Commit cdd4857

Browse files
committed
Fix #![no_std] compilation
1 parent 1b3c1e6 commit cdd4857

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

libs/context/src/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use core::fmt::{self, Debug, Formatter};
55
use core::ptr::NonNull;
66
use core::marker::PhantomData;
7+
use core::hash::{Hasher, Hash};
78

89
use alloc::sync::Arc;
910

@@ -16,7 +17,6 @@ use crate::{CollectorContext};
1617
use crate::state::{CollectionManager, RawContext};
1718
use zerogc::vec::GcVec;
1819
use zerogc::vec::repr::GcVecRepr;
19-
use std::hash::{Hasher, Hash};
2020

2121

2222
pub unsafe trait ConstRawCollectorImpl: RawCollectorImpl {
@@ -533,4 +533,4 @@ unsafe impl<C: RawCollectorImpl> GcSystem for CollectorRef<C> {
533533

534534
mod sealed {
535535
pub trait Sealed {}
536-
}
536+
}

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,16 @@ extern crate self as zerogc;
5151
* unless there's good justification to use an unstable feature.
5252
*/
5353
use core::mem::{self};
54-
use core::ops::{Deref, DerefMut};
54+
use core::ops::{Deref, DerefMut, CoerceUnsized};
5555
use core::ptr::{NonNull, Pointee, DynMetadata};
56-
use core::marker::PhantomData;
56+
use core::marker::{PhantomData, Unsize};
5757
use core::hash::{Hash, Hasher};
5858
use core::fmt::{self, Debug, Formatter};
5959

6060
use zerogc_derive::unsafe_gc_impl;
6161

6262
use crate::vec::{GcVec};
6363
pub use crate::array::GcArray;
64-
use std::ops::CoerceUnsized;
65-
use std::marker::Unsize;
6664

6765

6866
#[macro_use] // We have macros in here!
@@ -514,6 +512,7 @@ pub unsafe trait GcSimpleAlloc: GcContext {
514512
/// Allocate an array, taking ownership of the values in
515513
/// the specified vec.
516514
#[inline]
515+
#[cfg(feature = "alloc")]
517516
fn alloc_array_from_vec<'gc, T>(&'gc self, mut src: Vec<T>) -> GcArray<'gc, T, Self::Id>
518517
where T: GcSafe<'gc, Self::Id> + 'gc {
519518
unsafe {

src/vec.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'gc, T: GcSafe<'gc, Ctx::Id>, Ctx: GcSimpleAlloc> GcVec<'gc, T, Ctx> {
5959
match self.raw.try_push(val) {
6060
Ok(()) => {},
6161
Err(InsufficientCapacityError { }) => {
62-
unsafe { std::hint::unreachable_unchecked(); }
62+
unsafe { core::hint::unreachable_unchecked(); }
6363
}
6464
}
6565
}
@@ -87,7 +87,7 @@ impl<'gc, T: GcSafe<'gc, Ctx::Id>, Ctx: GcSimpleAlloc> GcVec<'gc, T, Ctx> {
8787
self.raw.len()
8888
);
8989
new_mem.as_repr_mut().set_len(self.raw.len());
90-
let mut old_mem = std::mem::replace(&mut self.raw, new_mem);
90+
let mut old_mem = core::mem::replace(&mut self.raw, new_mem);
9191
old_mem.as_repr_mut().set_len(0); // We don't want to drop the old elements
9292
}
9393
}
@@ -170,7 +170,7 @@ impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> GcRawVec<'gc, T, Id> {
170170
where Ctx: GcSimpleAlloc<Id=Id>, F: FnOnce(&mut GcVec<'gc, T, Ctx>) -> R {
171171
let vec = ManuallyDrop::new(GcVec {
172172
// NOTE: This is okay, because we will restore any changes via `scopeguard`
173-
raw: unsafe { std::ptr::read(self) },
173+
raw: unsafe { core::ptr::read(self) },
174174
context: ctx
175175
});
176176
let mut guard = scopeguard::guard(vec, |vec| {
@@ -185,10 +185,10 @@ impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> GcRawVec<'gc, T, Id> {
185185
where Ctx: GcSimpleAlloc<Id=Id>, F: FnOnce(&GcVec<'gc, T, Ctx>) -> R {
186186
let vec = ManuallyDrop::new(GcVec {
187187
// NOTE: This is okay, because we will forget it later
188-
raw: unsafe { std::ptr::read(self) },
188+
raw: unsafe { core::ptr::read(self) },
189189
context: ctx
190190
});
191-
let guard = scopeguard::guard(vec, std::mem::forget);
191+
let guard = scopeguard::guard(vec, core::mem::forget);
192192
func(&*guard)
193193
}
194194
/// The length of this vector
@@ -214,7 +214,7 @@ impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> GcRawVec<'gc, T, Id> {
214214
let old_len = self.len();
215215
// Drop after we set the length, in case it panics
216216
self.repr.set_len(0);
217-
std::ptr::drop_in_place::<[T]>(std::ptr::slice_from_raw_parts_mut(
217+
core::ptr::drop_in_place::<[T]>(core::ptr::slice_from_raw_parts_mut(
218218
elements, old_len
219219
));
220220
}
@@ -257,7 +257,7 @@ impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> GcRawVec<'gc, T, Id> {
257257
/// this is bound to the lifetime of the current value.
258258
#[inline]
259259
pub fn as_slice(&self) -> &[T] {
260-
unsafe { std::slice::from_raw_parts(
260+
unsafe { core::slice::from_raw_parts(
261261
self.as_ptr(),
262262
self.len()
263263
) }
@@ -297,4 +297,4 @@ unsafe_gc_impl!(
297297
trace_mut => |self, visitor| {
298298
unsafe { visitor.visit_vec::<T, Id>(self.as_repr_mut()) }
299299
},
300-
);
300+
);

0 commit comments

Comments
 (0)