Skip to content
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

PhantomData not behaving as advertised #22579

Closed
dylanede opened this issue Feb 20, 2015 · 5 comments
Closed

PhantomData not behaving as advertised #22579

dylanede opened this issue Feb 20, 2015 · 5 comments

Comments

@dylanede
Copy link
Contributor

As far as I can tell, from the point of view of lifetimes, PhantomData<T> should behave identically to T. This is unfortunately not the case in practice.

This function causes a mismatched type error on x:

fn cast_phantom<'a, 'b, T>(x: PhantomData<&'a T>) -> PhantomData<&'b T> where 'a : 'b {
    x
}

Whereas this similar function does not:

fn cast_actual<'a, 'b, T>(x: &'a T) -> &'b T where 'a : 'b {
    x
}

The variance rules of lifetimes should make both functions valid.

@pnkfelix
Copy link
Member

cc @nikomatsakis

@japaric
Copy link
Member

japaric commented Feb 20, 2015

Have you tried with master? AFAIK the current nightly (dfc5c0f Wed Feb 18 07:50:21 2015) doesn't include the variance PR (#22541 look for the roll-up merge of #22286) which landed on 522d09d Thu Feb 19 13:36:59 2015

@japaric
Copy link
Member

japaric commented Feb 20, 2015

I can confirm cast_phantom compiles with rustc 1.0.0-dev (522d09dfe 2015-02-19) (built 2015-02-20) (on my ARM board).

@dylanede
Copy link
Contributor Author

@japaric Ah, I was using the playpen to check that it still behaved the same on master. I guess next time I have an issue I better actually compile from master instead. It just takes so long though.

@japaric
Copy link
Member

japaric commented Feb 20, 2015

FWIW, multirust is now providing nightlies (built 2015-02-20). It seems the playpen/playbot is still using (built 2015-02-18). From what I've seen multirust always provides the newest nightlies first, whereas travis-ci and the playpen tend to lag a little behind (1-2 days).

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

No branches or pull requests

3 participants