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: "unable to infer enough type information to locate the impl of the trait core::kinds::Sized" #18429

Closed
carllerche opened this issue Oct 29, 2014 · 2 comments

Comments

@carllerche
Copy link
Member

With the following rust snippet, I get the error message:

$ rustc msg.rs
msg.rs:13:9: 13:12 error: unable to infer enough type information to locate the impl of the trait `core::kinds::Sized` for the type `Foo<<generic integer #0>>`; type annotations required
msg.rs:13     let foo = Foo::new(1);
                  ^~~
msg.rs:13:9: 13:12 note: all local variables must have a statically known size
msg.rs:13     let foo = Foo::new(1);
                  ^~~
error: aborting due to previous error

The issue is caused by having an extra semicolon at the last line of the new fn, but the error message was very confusing and it took me a while to realize that this was the problem.

#[deriving(Show)]
pub struct Foo<T> {
    foo: T
}

impl<T> Foo<T> {
    fn new(foo: T) -> Foo<T> {
        Foo { foo: foo };
    }
}

pub fn main() {
    let foo = Foo::new(1);
    println!("foo = {}", foo);
}
@ghost
Copy link

ghost commented Oct 29, 2014

Related to #18159 but not quite. It'd be much better it the message focused on 1 being an unconstrained integer variable (although that will be fixed separately by #16968).

@ghost
Copy link

ghost commented Nov 9, 2014

After ftxqxd@3f59939, the message is now:

x.rs:13:9: 13:12 error: unable to infer enough type information about `Foo<_>`; type annotations required
x.rs:13     let foo = Foo::new(1);

It's still not making it obvious that the lack of an integer suffix is the problem. That is going to be addressed by reintroducing integer fallback, though. Closing.

@ghost ghost closed this as completed Nov 9, 2014
This issue was closed.
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

1 participant