Skip to content

Commit ab1c49a

Browse files
committed
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
1 parent 8405332 commit ab1c49a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

library/core/src/array/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ impl<T, const N: usize> [T; N] {
531531
/// let y = x.map(|v| v.len());
532532
/// assert_eq!(y, [6, 9, 3, 3]);
533533
/// ```
534+
#[must_use]
534535
#[stable(feature = "array_map", since = "1.55.0")]
535536
pub fn map<F, U>(self, f: F) -> [U; N]
536537
where

library/coretests/tests/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn array_map_drop_safety() {
325325
let success = std::panic::catch_unwind(|| {
326326
let items = [0; 10];
327327
let mut nth = 0;
328-
items.map(|_| {
328+
let _ = items.map(|_| {
329329
assert!(nth < num_to_create);
330330
nth += 1;
331331
DropCounter

0 commit comments

Comments
 (0)