Skip to content

ICE with specialization + associated types: &[T] was a subtype of &[u8] but now is not? #39124

Closed
@oli-obk

Description

@oli-obk

A combination of specialization and an associated type yields this error. Removing the Error associated type and replacing all uses with a concrete type removes the error:

#![feature(specialization)]

trait Deserializer {
    type Error;
    fn deserialize_bytes<V: Visitor>(self, visitor: V) -> Result<V::Value, Self::Error>;
    fn deserialize<V: Visitor>(self, visitor: V) -> Result<V::Value, Self::Error>;
}

trait Visitor {
    type Value;
    type Error;
    fn visit_bytes(self, &[u8]) -> Result<Self::Value, Self::Error>;
}

impl<'a, T> Deserializer for &'a [T] {
    type Error = ();
    default fn deserialize_bytes<V: Visitor>(self, visitor: V) -> Result<V::Value, Self::Error> {
        self.deserialize(visitor)
    }
    fn deserialize<V: Visitor>(self, visitor: V) -> Result<V::Value, Self::Error> {
        unimplemented!()
    }
}

impl<'a> Deserializer for &'a [u8] {
    fn deserialize_bytes<V: Visitor>(self, visitor: V) -> Result<V::Value, Self::Error> {
        visitor.visit_bytes(self)
    }
}

fn main() {}

this occurs on the playground nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions