Skip to content

Can't infer the type of index #26735

Description

@yongqli

This doesn't type-check

fn main() {
    let m = [[0.; 2]; 2];
    println!("{}", (|i, j| m[i][j])(0, 1));
}

failing with

error[E0282]: type annotations needed
 --> inf.rs:3:28
  |
3 |     println!("{}", (|i, j| m[i][j])(0, 1));
  |                            ^^^^ cannot infer type

Annotating as usize fixes it, but I would expect the compiler to be able to infer the type. Is there a reason why it can't?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions