Skip to content

"Unable to infer enough type information" when spawning thread and looping. #20454

Closed
@jfager

Description

@jfager
use std::thread;

fn main() {
    thread::Thread::spawn(move || {
        loop { // Remove the loop and everything works fine.
            println!("hello");
        }
        // This gives you:
        //
        // type_inf.rs:4:5: 4:26 error: unable to infer enough type information about `_`; type annotations required
        // type_inf.rs:4     thread::Thread::spawn(move || {
        //                   ^~~~~~~~~~~~~~~~~~~~~
        // error: aborting due to previous error


        // Uncomment the `()` below, and the error changes to a warning:
        //
        // type_inf.rs:8:9: 9:6 warning: unreachable expression, #[warn(unreachable_code)] on by default
        // type_inf.rs:8         ()
        // type_inf.rs:9     }).detach();

        // ()
    }).detach();
}

$ rustc --version
rustc 0.13.0-nightly (39d7402 2015-01-01 15:51:08 +0000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions