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

[ER] A simple case of missed type inference #94519

Closed
leonardo-m opened this issue Mar 2, 2022 · 3 comments
Closed

[ER] A simple case of missed type inference #94519

leonardo-m opened this issue Mar 2, 2022 · 3 comments

Comments

@leonardo-m
Copy link

A type inference problem:

#![feature(generic_arg_infer)]
fn main() {
    let foo = |x| x + x; // OK
    let _a = foo(10_u8);

    let bar = |[a,b,c,d,e,f,g,h,i]: [_; _]| [c,f,i,b,e,h,a,d,g]; // OK
    let _b = bar([0_u8; 9]);

    let spam = |[a,b,c,d,e,f,g,h,i]| [c,f,i,b,e,h,a,d,g]; // error[E0282]: type annotations needed
    let _c = spam([0_u8; 9]);
}

In the second case the added : [_; _] adds very little information, at best it just states it's an array. I think Rustc could perform this little step and accept the "spam" case too.

@scottmcm
Copy link
Member

scottmcm commented Mar 5, 2022

Possible dup of #76342 where it was pointed out that references are also possible: the spam closure could also validly type as &[T; 9] -> [&T; 9]. It's always unclear to me when closures can care about things after themselves, to pick up call here that would disambiguate the rest of the way.

@leonardo-m
Copy link
Author

related:

let test = |[[a,b,c], [d,e,f], [g,h,i]]: [[_; _]; _]| [[g,d,a], [h,e,b], [i,f,c]];

@jyn514
Copy link
Member

jyn514 commented Apr 26, 2023

I'm going to close this as a duplicate of #76342; I think they have the same cause, that [a,b,c,d,e,f,g,h,i] could be inferred as either an array or a slice.

@jyn514 jyn514 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants