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

How much would (stable) specialization help? #6

Open
Ixrec opened this issue Jul 7, 2018 · 3 comments
Open

How much would (stable) specialization help? #6

Ixrec opened this issue Jul 7, 2018 · 3 comments

Comments

@Ixrec
Copy link
Owner

Ixrec commented Jul 7, 2018

See #1 for more history, but the basic links are:

Specialization RFC: rust-lang/rfcs#1210
Most recent blog post on making specialization sound: http://aturon.github.io/2018/04/05/sound-specialization/

This issue is for gathering feedback on whether or not stabilizing specialization actually solves use cases that are forbidden by the orphan rules today (since the orphan and overlap rules are intertwined). Since specialization is implemented on nightly, it should be possible to test and verify that it really does help, even if you can't use it for real yet.

@dhardy
Copy link

dhardy commented Nov 11, 2019

Play. With the current implementation of specialisation, I cannot write:

struct Wrap<X>(X);

impl<S, T: From<S>> From<Wrap<S>> for Wrap<T> {
    fn from(w: Wrap<S>) -> Self {
        Wrap(T::from(w.0))
    }
}

I suspect this is simply a case of lacking the commonly-referred to "lattice rules" (see here).

Edit: an even simpler example fails. I am forced to conclude that the current implementation of Specialization is too limited to be of much use in testing which situations specialisation would solve.

@jyn514
Copy link

jyn514 commented Feb 3, 2020

Play. With the current rules, I cannot write impl TryFrom<T> for MyStruct for a generic T.

use std::convert::TryFrom;
trait MyTrait {}
struct MyStruct;

impl<T> TryFrom<T> for MyStruct where T: MyTrait {
    type Error = ();
    fn try_from(t: T) -> Result<Self, Self::Error> {
        unimplemented!()
    }
}

@jyn514
Copy link

jyn514 commented Feb 3, 2020

Err hold on, that doesn't compile on nightly either. Ignore me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants