Skip to content

When type inference depends on the content of a closure, earlier statements do not make use of this information #51273

Closed
@dylanede

Description

@dylanede

Minimal example:

fn main() {
    // Behaviour does not appear linked to the use of unimplemented!()
    let x = unimplemented!();

    // Move the definition of g above this line to get this to compile
    x.0; // E0282: cannot infer type for `_`
    let g = || {
        let x: (i32, i32) = x;
    };
}

playground

This appears in stable, beta and nightly.

This appears to be a case where type inference should not depend on the order of these statements in the function.

This problem can be a deal-breaker when unnameable types are involved and reordering the statements isn't possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions