Skip to content

Document the consequences of various PhantomData forms #30069

Closed
@elinorbgr

Description

@elinorbgr

To work around the parameter T is never used [E0392] error, one if often suggested to use PhantomData.

However, the documentation of PhantomData explains that various forms are possible, but is quite vague about the consequences of the choice of a form (and also only handles a small subset of the possible forms).

From my understanding given this reddit thread I opened these various forms can have different consequences (regarding dopck and/or lifetime variance ?):

  • PhantomData<T>
  • PhantomData<&'a T>
  • PhantomData<&'a mut T>
  • PhantomData<*const T>
  • PhantomData<*mut T>
  • PhantomData<fn(T) -> ()>
  • PhantomData<fn() -> T>
  • PhantomData<fn(T) -> T>

But I have no real idea about what using one or another changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions