-
Notifications
You must be signed in to change notification settings - Fork 503
Open
Description
crossbeam-epoch
supports unsized types through the Pointable
trait. This allows for the creation of pointers to dynamically sized types, e.g., Shared<[MaybeUninit<T>]>
.
However, it's not possible to pass these Shared
pointers of unsized types to Guard::defer_destroy
, as the function is missing a ?Sized
bound on its generic type T
. For example:
use std::mem::MaybeUninit;
use crossbeam::epoch::{Owned, pin};
fn main() {
let guard = &pin();
let ptr = Owned::<[MaybeUninit<usize>]>::init(42).into_shared(guard);
unsafe {
guard.defer_destroy(ptr); // compile error
guard.defer_unchecked(|| ptr.into_owned()); // OK
}
}
guard.defer_destroy
generates a compile error:
error[E0277]: the size for values of type `[MaybeUninit<usize>]` cannot be known at compilation time
--> src/main.rs:9:29
|
9 | guard.defer_destroy(ptr); // compile error
| ------------- ^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `[MaybeUninit<usize>]`
note: required by an implicit `Sized` bound in `Guard::defer_destroy`
--> /home/hyeon/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/guard.rs:268:33
|
268 | pub unsafe fn defer_destroy<T>(&self, ptr: Shared<'_, T>) {
| ^ required by the implicit `Sized` requirement on this type parameter in `Guard::defer_destroy`
This is because the signature for defer_destroy
does not include T: ?Sized
, causing Rust to add an implicit T: Sized
bound by default.
This seems like a mistake, as the deallocation for Shared
pointers is handled by the Pointable::into_owned
, which does not depends on whether they are sized or not.
Metadata
Metadata
Assignees
Labels
No labels