Add #[must_use] to Array::map
The output of Array::map is intended to be an array of the same size, and does not modify the original in place nor is it intended for side-effects. Thus, under normal circumstances it should be consumed. See [discussion](https://internals.rust-lang.org/t/array-map-annotate-with-must-use/22813/26). Attaching to tracking issue #75243
This commit is contained in:
parent
8405332bdf
commit
ab1c49a7fa
2 changed files with 2 additions and 1 deletions
|
|
@ -531,6 +531,7 @@ impl<T, const N: usize> [T; N] {
|
|||
/// let y = x.map(|v| v.len());
|
||||
/// assert_eq!(y, [6, 9, 3, 3]);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "array_map", since = "1.55.0")]
|
||||
pub fn map<F, U>(self, f: F) -> [U; N]
|
||||
where
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ fn array_map_drop_safety() {
|
|||
let success = std::panic::catch_unwind(|| {
|
||||
let items = [0; 10];
|
||||
let mut nth = 0;
|
||||
items.map(|_| {
|
||||
let _ = items.map(|_| {
|
||||
assert!(nth < num_to_create);
|
||||
nth += 1;
|
||||
DropCounter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue