Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 642cd65

Browse filesBrowse files
authored
Rollup merge of #140957 - JulianKnodt:array_must_use, r=Mark-Simulacrum
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
2 parents 8c14588 + ab1c49a commit 642cd65
Copy full SHA for 642cd65

File tree

2 files changed

+2
-1
lines changed
Filter options

2 files changed

+2
-1
lines changed

‎library/core/src/array/mod.rs

Copy file name to clipboardExpand all lines: library/core/src/array/mod.rs
+1Lines changed: 1 addition & 0 deletions
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

Copy file name to clipboardExpand all lines: library/coretests/tests/array.rs
+1-1Lines changed: 1 addition & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.