-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Clarify claims about PhantomData<T>. #27524
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This just seems more confusing to me |
This seems like one of those "you gotta let it go" kinda sentences. Where there's something you want to say but it's not worth trying to do it unless you want to commit to a full explanation. |
So maybe @nikomatsakis or @aturon can weigh in here. IIRC, the relationship is that you can use PhantomData to implement phantom types, but not every usage is such. |
(I am willing to commit to a full explanation, it's just that I'm only two pages into TAPL :( ) |
@steveklabnik Yeah, that's the correct relationship. But I agree with @gankro that this is getting into the weeds. |
fwiw I describe PhantomData here: https://doc.rust-lang.org/nightly/adv-book/phantom-data.html |
We originally added this sentence because people were asking about the relationship, and/or there were old blog posts talking about phantom types where you'd upgrade the code to PhantomData. Hm. |
r? @gankro |
Phantom types is a pattern, and strictly speaking doesn't need PhantomData in the usual case. For instance, struct Sanitized;
struct Raw;
struct String<Sanitization> {
data: String,
_sanitization: Sanitization,
} struct Sanitized;
struct Raw;
struct String<Sanitization> {
data: String,
_sanitization: PhantomData<Sanitization>,
} Are semantically and operationally identical, differing only in how they're initialized. |
@gankro try this wording on for size |
@@ -273,7 +273,11 @@ macro_rules! impls{ | |||
/// even though it does not. This allows you to inform the compiler about certain safety properties | |||
/// of your code. | |||
/// | |||
/// Though they both have scary names, `PhantomData<T>` and "phantom types" are unrelated. 👻👻👻 | |||
/// # A ghastly note 👻👻👻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YES
r=me with nit |
@bors: r=gankro |
📌 Commit 340c25a has been approved by |
This wording was too strong. Fixes rust-lang#27523
@bors: rollup |
This wording was too strong. Fixes rust-lang#27523
This wording was too strong.
Fixes #27523