Clarify claims about PhantomData<T>.#27524
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 |
|
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