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

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

Closed
oli-obk opened this issue Jan 17, 2017 · 3 comments
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jan 17, 2017

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

@brson brson added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@istankovic
Copy link
Contributor

With rustc 1.26.0-nightly (adf2135ad 2018-03-17) this is not an ICE, I get this:

error[E0308]: mismatched types
  --> a.rs:27:9
   |
26 |     fn deserialize_bytes<V: Visitor>(self, visitor: V) -> Result<V::Value, Self::Error> {
   |                                                           ----------------------------- expected `std::result::Result<<V as Visitor>::Value, ()>` because of return type
27 |         visitor.visit_bytes(self)
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type
   |
   = note: expected type `std::result::Result<_, ()>`
              found type `std::result::Result<_, <V as Visitor>::Error>`

error: aborting due to previous error

@pnkfelix
Copy link
Member

@oli-obk this does not seem like a bug anymore. Or at least, the behavior reported by @istankovic sounds plausibly correct?

Shall we close this?

@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 20, 2019

Jup, looks fixed to me, too

@oli-obk oli-obk closed this as completed Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants