Skip to content

Unnecessarily order dependent type inference #108204

@crlf0710

Description

@crlf0710
fn main1() {
    let vec1 = [1,2,3,4,5].into_iter().collect();
    let _vec2 : &Vec<usize> = &vec1;
    // this compiles
    println!("{}", vec1[0]);
}

fn main2() {
    let vec1 = [1,2,3,4,5].into_iter().collect();
    // this doesn't compile
    println!("{}", vec1[0]);
    let _vec2 : &Vec<usize> = &vec1;
}

I wonder if it is possible to make the two code snippets act the same?

Metadata

Metadata

Assignees

No one assigned

    Labels

    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