about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJulian Knodt <julianknodt@gmail.com>2025-05-13 11:17:09 +0900
committerJulian Knodt <julianknodt@gmail.com>2025-05-13 12:34:53 +0900
commitab1c49a7facad5083c20407a2b1fd0b2104e174e (patch)
treea1a87ad5180e6c482faad0e9f7a0ac7348e65e7a
parent8405332bdf09b153e475f83b8b8ebf8d4e8eb81f (diff)
downloadrust-ab1c49a7facad5083c20407a2b1fd0b2104e174e.tar.gz
rust-ab1c49a7facad5083c20407a2b1fd0b2104e174e.zip
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
-rw-r--r--library/core/src/array/mod.rs1
-rw-r--r--library/coretests/tests/array.rs2
2 files changed, 2 insertions, 1 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs
index efa7bed7c8e..4476e3f7923 100644
--- a/library/core/src/array/mod.rs
+++ b/library/core/src/array/mod.rs
@@ -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
diff --git a/library/coretests/tests/array.rs b/library/coretests/tests/array.rs
index b6d18f1ec38..30ccbbc3203 100644
--- a/library/coretests/tests/array.rs
+++ b/library/coretests/tests/array.rs
@@ -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