Skip to content

Add Gankro's table to nomicon/src/phantom-data.md#40069

Merged
bors merged 1 commit into
rust-lang:masterfrom
Rufflewind:master
Feb 25, 2017
Merged

Add Gankro's table to nomicon/src/phantom-data.md#40069
bors merged 1 commit into
rust-lang:masterfrom
Rufflewind:master

Conversation

@Rufflewind

@Rufflewind Rufflewind commented Feb 24, 2017

Copy link
Copy Markdown
Contributor

Original: #30069 (comment)

Testing confirms that:

  • PhantomData<fn() -> T> does not actually enable drop checking.
  • PhantomData<fn(T) -> T> is neither variant nor contravariant.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @steveklabnik

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

@steveklabnik

Copy link
Copy Markdown
Contributor

@bors: r+

neat, thank you! ❤️

@bors

bors commented Feb 24, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 49fa66c has been approved by steveklabnik

@bluss

bluss commented Feb 24, 2017

Copy link
Copy Markdown
Contributor

@pnkfelix Does PhantomData<T> have a special role in drop checking now? If we compare with PhantomData<*const T>, don't both those have the same drop check implications nowadays?

@Rufflewind

Copy link
Copy Markdown
Contributor Author

This is what I used to test whether the drop checker is active:

use std::marker::PhantomData;

struct Inspector<'a>(&'a ());

impl<'a> Drop for Inspector<'a> {
    fn drop(&mut self) {}
}

fn wrap<T>(_: T) -> PhantomData<T> { PhantomData }

fn main() {
    let (i, inspector);
    i = ();
    inspector = wrap(Inspector(&i));
}

Right now this fails to compile. But if I use PhantomData<*const T> then it compiles successfully.

@bluss

bluss commented Feb 25, 2017

Copy link
Copy Markdown
Contributor

Nice!

You said:

PhantomData<fn() -> T> does enable drop checking.

The code doesn't demonstrate this, did you mean the opposite?

@Rufflewind

Copy link
Copy Markdown
Contributor Author

The code doesn't demonstrate this, did you mean the opposite?

Yeah, I meant the opposite. The documentation is correct, but I messed up the commit message / pull request -.-

Rebasing…

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.
@steveklabnik

Copy link
Copy Markdown
Contributor

@bors: r+ rollup

nice catch all, sorry I missed it! 😓

@bors

bors commented Feb 25, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 1f75085 has been approved by steveklabnik

eddyb added a commit to eddyb/rust that referenced this pull request Feb 25, 2017
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.
@bluss

bluss commented Feb 25, 2017

Copy link
Copy Markdown
Contributor

Thanks for the clarification and the new and better docs!

eddyb added a commit to eddyb/rust that referenced this pull request Feb 25, 2017
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.
bors added a commit that referenced this pull request Feb 25, 2017
@bors bors merged commit 1f75085 into rust-lang:master Feb 25, 2017
@Rufflewind Rufflewind deleted the master branch March 19, 2017 20:55
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.

5 participants