Skip to content

DispatchFromDyn is not implemented for Box, Rc, Arc, or Weak with custom allocators #135

@matthewpipie

Description

@matthewpipie

The DispatchFromDyn trait allows for a type to "be self" such that a trait can become object safe. For example, since Rc<T> is DispatchFromDyn, you can write code like

trait Foo {
    fn foo(self: Rc<Self>);
}

and have a Box<dyn Foo> be valid. This trait is defined in Rc like:

#[unstable(feature = "dispatch_from_dyn", issue = "none")]
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Rc<U>> for Rc<T> {}

However, this implementation does not apply for custom allocators (e.g. Rc<T, A>). This is the same in Arc and in both Rc and Arc's Weak, too. This means that replacing the above trait function with

fn foo(self: Rc<Self, MyAlloc>)

will not compile if you have a Box<dyn Foo>.

Is this an oversight or is this intentional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions