Endel Dreyer
Endel Dreyer

Reputation: 1654

Unable to infer enough type information about `_`; type annotations or generic parameter binding required

I'm trying to return an error Result with a &'static str.

impl Worker {
    fn get_task_by_name(&self, name: String) -> Result<Box<Task>, &'static str> {
        Err("Task not found!");
    }
}

It outputs the following error:

src/lib.rs:84:5: 84:8 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
src/lib.rs:84     Err("Task not found!");
                  ^~~

What could be the problem here?

Upvotes: 5

Views: 1864

Answers (1)

DK.
DK.

Reputation: 59115

You have a spurious semicolon after the Err(...). You're telling the compiler to throw away the value you construct and return () instead. Of course, it doesn't get as far as telling you the return type is wrong: it's more immediately confused by the fact that you've constructed a Result<T, E>::Err(E) without telling it what T is.

Upvotes: 11

Related Questions