Skip to content

The PhantomData section is missing clarification or is wrong! #208

Open
@eloraiby

Description

@eloraiby

In the book:

In order to tell dropck that we do own values of type T, and therefore may drop some T's when we drop, we must add an extra PhantomData saying exactly that

however:

#[repr(C)]
pub struct Unique<T> {
    ptr         : *mut T,
    _marker     : ::core::marker::PhantomData<T>,
}

impl<T> Unique<T> {
    pub fn new(ptr: *mut T) -> Self { Self { ptr : ptr, _marker: ::core::marker::PhantomData } }
    pub fn getMutPtr(&mut self) -> *mut T { self.ptr }
    pub fn getPtr(&self) -> *const T { self.ptr }
}

#[repr(C)]
pub struct Vec<T> {
    elements    : Unique<T>,
    count       : usize,
    capacity    : usize,
}
...

Will compile and Vec<T> can be used and dropped without any problem. So, what's the point of PhantomData there ? unless I implement Drop on Vec the code with or without PhantomData will compile just fine!

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-confusingThe description is confusing or not clear.C-outdatedThe description is outdated.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions