-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Description
Consider the following code:
fn foo<F>(x: i32) -> i32 { x }
fn bar<'a>(x: i32) -> i32 { x }
fn main() {
bar(1);
bar(2);
foo::<f64>(3);
foo(4);
foo(5);
}Currently, this causes a fatal compiler error at the invocation of foo(4) on line 9, of the form:
error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [--explain E0282]
--> <anon>:9:5
|>
9 |> foo(4);
|> ^^^
error: aborting due to previous error
The only way to ever successfully invoke foo is to feed it an explicit type (via the ::<_> syntax as illustrated on line 8).
I suspect in many cases of this error, the actual problem is that the definition of fn foo (and also fn bar) are faulty: since F and 'a are never referenced in the signature nor in the function body, they are irrelevant and should cause a warning via the compiler's linting system.
(A separate issue is that one cannot actually instantiate the 'a parameter to fn bar via the ::<_> syntax, so it seems that its formal lifetime parameter is truly unusable. But things may not remain that way forever, so I think its best to lump both of these cases into the same category.