Is Box special with respect to the orphan rule?

I seem to be able to do

pub trait My {
    fn hello(&self) -> Self;
}

impl PartialEq for Box<dyn My> {
    fn eq(&self, other: &Self) -> bool {
        todo!()
    }
}

But I can't seem to do

pub trait My {
    fn hello(&self) -> Self;
}

impl PartialEq for Rc<dyn My> {
    fn eq(&self, other: &Self) -> bool {
        todo!()
    }
}

Only traits defined in the current crate can be implemented for arbitrary types [E0117]

I know that Box is special, and I assume that's why that happens. But can I rely on that staying this way? Presumably, Rust will want to eventually treat Box non-specially, and thus, would the first example eventually stop working too?

Box is part of a special class of generic types that are special with respect to the orphan rule. they are called fundamental type constructors, or just fundamental types.

the only thing that may change with regards to fundamental types is the addition of new fundamental types.

I see, so when it is codified like that, I can assume that it will not change any time soon, thanks!

Removing or adding fundamental-ness to a type is a breaking change, so yes.

2 Likes