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

First example does not demonstrate covariance #10

Open
dtolnay opened this issue Jan 27, 2019 · 0 comments
Open

First example does not demonstrate covariance #10

dtolnay opened this issue Jan 27, 2019 · 0 comments

Comments

@dtolnay
Copy link

dtolnay commented Jan 27, 2019

The example says:

Here you can see that a non-send/sync inner type doesn't affect the wrapper type, and that the 'static lifetime gets cast into a 'a lifetime.

fn main2() {
    let x: PhantomCovariantAlwaysSendSync<&'static *const ()> = PhantomData;
    fn f<'a>(_: PhantomCovariantAlwaysSendSync<&'a *const ()>) {}
    f(x);
    let _y: &(dyn Send + Sync) = &x;
}

I don't think "'static lifetime gets cast into a 'a lifetime" is accurate. All that's happening is that 'a is being instantiated with 'a = 'static. There is no subtyping or variance at play. The same code works if you write it with PhantomContravariantAlwaysSendSync.

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

1 participant