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

Type error with cross-crate polymorphism #6899

Closed
honzasp opened this issue Jun 2, 2013 · 1 comment
Closed

Type error with cross-crate polymorphism #6899

honzasp opened this issue Jun 2, 2013 · 1 comment

Comments

@honzasp
Copy link

honzasp commented Jun 2, 2013

Hi,

I have an enum containing some polymorphic structs:

mod picture {
  pub enum Picture {
    Picture8(~Pixels<u8>),
    Picture16(~Pixels<u16>),
  }

  pub struct Pixels<S>(~PixelsInfo<S>, ~[S]);
  pub struct PixelsInfo<S> {
    transparent: Option<S>,
    background: Option<S>,
  }
}

which is used as:

let pixels_info: ~picture::PixelsInfo<u8> = ~picture::PixelsInfo {
      transparent: Some(20),
      background: None,
    };

It works fine when it is in the same file as the code that uses it, but when I place it in a different crate, I got strange type errors (shortened):

error: mismatched types: expected `~picture::PixelsInfo<'a>` but found `~picture::PixelsInfo<u8>` (expected type parameter but found u8)
error: mismatched types: expected `~['a]` but found `~[u8]` (expected type parameter but found u8)
error: mismatched types: expected `~picture::Pixels<u8>` but found `~picture::Pixels<'a>` (expected u8 but found type parameter)

(the full source code is at https://gist.github.com/honzasp/5693895 -- type make to see it in action)

The error message is also confusing a bit, because the 'a ("expected ~picture::Pixels<u8> but found ~picture::Pixels<'a>) looks like a region bound (&'a foo), but seems to be a type metavariable (but I might be wrong, as I don't really understand the details of the compiler).

@huonw
Copy link
Member

huonw commented Jul 19, 2013

This looks like the same bug as #7899; closing in favour of that one as it has the "modern" error message and a smaller testcase.

@huonw huonw closed this as completed Jul 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants