Closed
Description
Location
https://doc.rust-lang.org/nightly/std/array/fn.from_fn.html
Summary
Currently the documentation surrounding array::from_fn
does not guarantee the order in which the array items are generated. Given that it accepts an FnMut
this seems dangerous. For example, code such as:
let mut iter = 0..5;
let arr = core::array::from_fn(|_| iter.next().unwrap());
assert_eq!(arr, [0, 1, 2, 3, 4]);
currently compiles as expected but would fail if array::from_fn
constructed the array out of order.
The documentation should be updated to either confirm that the code above is a valid use of array::from_fn
or to warn users that elements may be generated out of order.
This was previously mentioned in the discussion around #102609 but didn't end up getting fixed.