• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by John Dev


30 Nov, 2024

Updated at 02 Dec, 2024

Why this specialization doesn't compile?

Hi,
I don't get why the compiler cannot compile that code.
I read https://github.com/rust-lang/rfcs/blob/master/text/1210-impl-specialization.md, especially
https://github.com/rust-lang/rfcs/blob/master/text/1210-impl-specialization.md#the-algorithmic-version for trait1 and trait2, but I am still confused.

Shouldn't negative bounds help to distinguish the impls? and make sure no overlaps occur?

I tried to throw everything I could.

Note: that code is just for playing around.

#![feature(min_specialization)]
#![feature(rustc_attrs)]
#![feature(negative_bounds)]

struct A(u32);

#[rustc_specialization_trait]
trait Trait1 {}

#[rustc_specialization_trait]
trait Trait2 {}

impl<T> From<T> for A
where
    T: Trait2 + !Trait1,
{
    fn from(item: T) -> Self {
        A(3)
    }
}

impl<T> From<T> for A
where
    T: Trait1 + !Trait2,
{
    fn from(item: T) -> Self {
        A(2)
    }
}

(Playground)

thanks

1 post - 1 participant

Read full topic