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

Confusing error message with boxed unsized types #17122

Closed
ftxqxd opened this issue Sep 9, 2014 · 5 comments
Closed

Confusing error message with boxed unsized types #17122

ftxqxd opened this issue Sep 9, 2014 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-DSTs Area: Dynamically-sized types (DSTs)

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Sep 9, 2014

struct Foo<Sized? T>;

impl<Sized? T> Foo<T> {
    fn frob(self, bar: Box<T>) {}
}

fn main() {
    let foo: Foo<Num> = Foo;
    foo.frob(box 1i as Box<Num>);
}

yields the error

dstbug.rs:9:14: 9:32 error: mismatched types: expected `Box<core::num::Num>`, found `Box<core::num::Num>` (expected box, found box)
dstbug.rs:9     foo.frob(box 1i as Box<Num>);
                         ^~~~~~~~~~~~~~~~~~
error: aborting due to previous error

cc @nick29581

@huonw huonw added A-DSTs Area: Dynamically-sized types (DSTs) A-diagnostics Area: Messages for errors, warnings, and lints labels Sep 9, 2014
@nrc
Copy link
Member

nrc commented Sep 9, 2014

Hmm, this shouldn't be an error at all, let alone a confusing one. I expect this is due to us not unifying unsized types with an inference variable. I would expect a trait to unify to itself though. I'll have a poke around with this.

@nrc
Copy link
Member

nrc commented Sep 9, 2014

See also #16918 which has a related problem with unifying unsized type variables

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Oct 28, 2014

Hmm. #17178 has been closed, but this still isn’t fixed, so perhaps it’s not related to unifying unsized types in type inference. An interesting thing is that the error message (expected box, found box) seems to suggest that it’s not the traits that differ, but the box: replacing as Box<Num> with as Box<Float> gives a message that correctly states that the traits differ.

@bkoropoff
Copy link
Contributor

The example builds for me with the latest master.

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Oct 28, 2014

Ah, it does too. It looks like the playpen is running a very outdated version of rustc…

I guess this is fixed, then! Closing.

@ftxqxd ftxqxd closed this as completed Oct 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-DSTs Area: Dynamically-sized types (DSTs)
Projects
None yet
Development

No branches or pull requests

4 participants