Skip to content

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

Merged
merged 1 commit into from
Aug 5, 2015
Merged

Conversation

steveklabnik
Copy link
Member

This wording was too strong.

Fixes #27523

@rust-highfive
Copy link
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@Gankra
Copy link
Contributor

Gankra commented Aug 4, 2015

This just seems more confusing to me

@Gankra
Copy link
Contributor

Gankra commented Aug 4, 2015

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.

@steveklabnik
Copy link
Member Author

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.

@steveklabnik
Copy link
Member Author

(I am willing to commit to a full explanation, it's just that I'm only two pages into TAPL :( )

@aturon
Copy link
Member

aturon commented Aug 4, 2015

@steveklabnik Yeah, that's the correct relationship. But I agree with @gankro that this is getting into the weeds.

@Gankra
Copy link
Contributor

Gankra commented Aug 4, 2015

fwiw I describe PhantomData here: https://doc.rust-lang.org/nightly/adv-book/phantom-data.html

@steveklabnik
Copy link
Member Author

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.

@alexcrichton
Copy link
Member

r? @gankro

@rust-highfive rust-highfive assigned Gankra and unassigned alexcrichton Aug 4, 2015
@Gankra
Copy link
Contributor

Gankra commented Aug 4, 2015

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.

@steveklabnik
Copy link
Member Author

@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 👻👻👻
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES

@Gankra
Copy link
Contributor

Gankra commented Aug 5, 2015

r=me with nit

@steveklabnik
Copy link
Member Author

@bors: r=gankro

@bors
Copy link
Collaborator

bors commented Aug 5, 2015

📌 Commit 340c25a has been approved by gankro

This wording was too strong.

Fixes rust-lang#27523
@steveklabnik
Copy link
Member Author

@bors: rollup

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Aug 5, 2015
bors added a commit that referenced this pull request Aug 5, 2015
@bors bors merged commit 340c25a into rust-lang:master Aug 5, 2015
@steveklabnik steveklabnik deleted the gh27523 branch June 19, 2016 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants