You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnadd3<T>(x:i32) -> i32{ x + 3}fnmain(){println!("add3(4): {}", add3(4));}
The Rust compiler currently rejects the above, because it cannot infer what type to assign to the type parameter T in the above invocation add3(4).
The problematic thing is the message:
<anon>:4:29: 4:33 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
<anon>:4 println!("add3(4): {}", add3(4));
^~~~
This message complains about _, rather than referencing the parameter T of fn add3.
It might be nice if, when we encounter this error, if we also did an additional check for the function itself and see if the type parameter in question is unused in the signature of fn add (since in such a situation, there is no way that the callsite will be able to supply the information via type annotation -- the only option is the generic parameter binding form like add3::<(f64,i8)>(4), and it is likely (though not assured) that the actual bug is in the definition of fn add3 itself, rather than at the call site.
The text was updated successfully, but these errors were encountered:
Tracking the origin of type-variables to improve the "unable to infer enough type information about _" message would certainly we nice (we do it for defaults today).
Consider code like this (playpen):
The Rust compiler currently rejects the above, because it cannot infer what type to assign to the type parameter
T
in the above invocationadd3(4)
.The problematic thing is the message:
_
, rather than referencing the parameterT
offn add3
.fn add
(since in such a situation, there is no way that the callsite will be able to supply the information via type annotation -- the only option is the generic parameter binding form likeadd3::<(f64,i8)>(4)
, and it is likely (though not assured) that the actual bug is in the definition offn add3
itself, rather than at the call site.The text was updated successfully, but these errors were encountered: