Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused type params on fn lead to difficult to deciper errors at call site #28153

Closed
pnkfelix opened this issue Sep 1, 2015 · 3 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Sep 1, 2015

Consider code like this (playpen):

fn add3<T>(x: i32) -> i32 { x + 3 }

fn main() {
    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));
                                     ^~~~
  1. This message complains about _, rather than referencing the parameter T of fn add3.
  2. 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.
@arielb1
Copy link
Contributor

arielb1 commented Sep 1, 2015

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).

@sanxiyn
Copy link
Member

sanxiyn commented Oct 26, 2015

See also #25871, which is about a lint for unused type parameters.

@nagisa
Copy link
Member

nagisa commented Jan 19, 2016

Duplicate of #25633

@nagisa nagisa closed this as completed Jan 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

5 participants