Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array type inference not as good as Tuple? #81667

Open
tiby312 opened this issue Feb 2, 2021 · 0 comments
Open

Array type inference not as good as Tuple? #81667

tiby312 opened this issue Feb 2, 2021 · 0 comments
Labels
A-array Area: [T; N] A-inference Area: Type inference C-bug Category: This is a bug.

Comments

@tiby312
Copy link

tiby312 commented Feb 2, 2021

Array type inference not as good as Tuple?

I tried this code:

//No error
fn test_tuple() {
 
    let arr=[(0u32,0);2];
    let mut last=None;
    for &(x,y) in arr.iter(){
        if let Some((x,y))=last{
            dbg!(x,y);   
        }
        last=Some((x,y))
    }
}

//Compile time error
fn test_arr() {
 
    let arr=[[0u32,0];2];
    let mut last=None;
    for &[x,y] in arr.iter(){
        if let Some([x,y])=last{
            dbg!(x,y);   
        }
        last=Some([x,y])
    }
}


fn main(){
    test_tuple();
    test_arr();
}

I expected to see this happen: It to compile

Instead, this happened: It didnt compile

Same behavior on stable and nghtly

@tiby312 tiby312 added the C-bug Category: This is a bug. label Feb 2, 2021
@jonas-schievink jonas-schievink added the A-inference Area: Type inference label Feb 2, 2021
@workingjubilee workingjubilee added the A-array Area: [T; N] label Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: [T; N] A-inference Area: Type inference C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants