Skip to content

detect when unconstrained type parameters could be resolved by a closure return type #40014

Closed
@nikomatsakis

Description

@nikomatsakis

Building on the changes in #39361, it'd be nice to suggest when the user ought to annotate a closure return type, as I think many users are not even aware this is possible. Example:

fn main() {
    let _v = || [];
}

I'd like to suggest something like :

error[E0101]: cannot determine a type for this expression: unconstrained type
 --> <anon>:2:17
  |
2 |     let _v = || [];
  |              -- ^^ cannot resolve type of expression
                 |
                 consider annotating the return type of this closure like so `|| -> TYPE { [] }`

Not sure the best way to phrase that yet. =)

cc @cengizio -- interested in following up on this? I can help mentor it.

cc @estebank @jonathandturner -- any thoughts on how to phrase the suggestion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions