3 ms·
It does seem to be choosing [usize; 5] in this case though. https://rust.godbolt.org/z/qasxnrTf9 https://rust.godbolt.org/z/qasxnrTf9
by aendruk 4y ago
It does seem to be choosing [usize; 5] in this case though.
https://rust.godbolt.org/z/qasxnrTf9 https://rust.godbolt.org/z/qasxnrTf9
- steveklabnik 4y agoYes, that is true. If you use a literal array, you get i32 for the element type. I believe this is because of the signature: pub fn from_fn<T, const N: usize, F>(cb: F) -> [T; N] where F: FnMut(usize) -> T, While T is unconstrained, N is a usize, which is used in the closure, which we then re-use as the element.
- sophacles 4y agoOK this is just kinda funny - I was right, but only by accident. For some reason I thought that the literal defaulted to usize not i32. The fact that this path makes my assertion of usize correct is pretty cool though. Thanks for diving into it!