Skip to content

error message for uninferrable type #38812

Closed
@dherman

Description

@dherman

The error message when an unused variable leads to an uninferrable type is confusing:

fn main() {
    let v = vec![];
}
// rustc 1.14.0 (e8a012324 2016-12-16)
// error[E0282]: unable to infer enough type information about `_`
//  --> <anon>:2:13
//   |
// 2 |     let v = vec![];
//   |             ^^^^^^ cannot infer type for `_`
//   |
//   = note: type annotations or generic parameter binding required
//   = note: this error originates in a macro outside of the current crate

@nikomatsakis pointed me to #36554. I'm not sure how much that issue was aiming to fix.

If I'm not mistaken, most (all?) of these kinds of situations occur when an expression is flowing into an unannotated local variable binding. It seems like a better error message would highlight the binding as well as the vec![] expression (or whatever the uninferrable expression is), and suggest that the variable should either be used elsewhere in the function or annotated with a type.

/cc @jonathandturner

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions