-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Document the consequences of various PhantomData forms #30069
Comments
cc @Manishearth |
cc @gankro |
I had forgotten to check the rustonomicon, and this page seems relevant. Could be worth explaining the relation of |
The standard widget for "invariant over 'a" is |
I wonder if there is already a crate that provides aliases to those various forms of PhantomData, appropriately named for a bit more self-documentation. If not I have a sudden desire to publish one :) |
I wouldn't recommend it -- it's what we used to have, but it was really confusing and no one could remember. The current system of "use what you semantically have" works a lot better. |
According to the dropck rfc, |
Yeah, so I'm not sure what the best way is to expand this. The first sentence is
Which does cover all of these forms. It's just that. |
Yeah, but it doesn't explain why you would use it, or what features can be inherited from those types. There's some dropck and variance stuff, but there's nowhere that people can go to to read about it. |
Well, there's stuff in the nomicon. |
We should link to it from the phantomdata docs then |
It’d be nice if the nomicon had Gankro’s neat table though! |
Original: rust-lang#30069 (comment) Testing confirms that: - PhantomData<fn() -> T> does not actually enable drop checking. - PhantomData<fn(T) -> T> is neither variant nor contravariant.
Add Gankro's table to nomicon/src/phantom-data.md Original: rust-lang#30069 (comment) Testing confirms that: - `PhantomData<fn() -> T>` does not actually enable drop checking. - `PhantomData<fn(T) -> T>` is neither variant nor contravariant.
Add Gankro's table to nomicon/src/phantom-data.md Original: rust-lang#30069 (comment) Testing confirms that: - `PhantomData<fn() -> T>` does not actually enable drop checking. - `PhantomData<fn(T) -> T>` is neither variant nor contravariant.
To work around the
parameter
Tis 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.
The text was updated successfully, but these errors were encountered: