Skip to content

unhelpful error message invoking fn foo<T>() when T is not used within signature #28523

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

Closed
whitequark opened this issue Sep 19, 2015 · 4 comments

Comments

@whitequark
Copy link
Member

Test case:

fn foo<T>() {}
fn main() { foo() }

Error:

t.rs:2:13: 2:16 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
t.rs:2 fn main() { foo() }
                   ^~~

It should, at least, mention T by name, and I think some rewording would also be beneficial.

@ebfull
Copy link
Contributor

ebfull commented Sep 19, 2015

It doesn't matter that T isn't used. This also triggers the error:

fn foo<T>() {
    println!("The size of T is {}", std::mem::size_of::<T>());
}
fn main() { foo() }

At the call site it has to monomorphize foo<T>() but it cannot infer for T. You need to provide foo, at the very least, with a type parameter, like so:

fn foo<T>() {}
fn main() { foo::<usize>() }

@whitequark
Copy link
Member Author

Yes, I understand why this is an error. The point is that the error message is completely unhelpful. I spent at least an hour figuring this out.

@ebfull
Copy link
Contributor

ebfull commented Sep 20, 2015

I agree the error message can be improved. I was talking about your title.

#25633 is another example of this.

@whitequark whitequark changed the title unhelpful error message invoking fn foo<T>() when T is never used unhelpful error message invoking fn foo<T>() when T is not used within signature Sep 20, 2015
@nagisa
Copy link
Member

nagisa commented Sep 20, 2015

Duplicate of #28153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants