Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rust

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?

like image 601
Endel Dreyer Avatar asked Aug 23 '15 10:08

Endel Dreyer


1 Answers

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.

like image 151
DK. Avatar answered Oct 05 '22 04:10

DK.