Not planned
Description
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.
Activity
scottmcm commentedon 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 commentedon Mar 7, 2022
related:
jyn514 commentedon 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.