Skip to content

Confusing error message: "unable to infer enough type information to locate the impl of the trait core::kinds::Sized" #18429

Closed
@carllerche

Description

@carllerche

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions