Skip to content

Commit cdf22c3

Browse files
committed
add #[must_use] to functions of slice and its iterators.
1 parent 67c9ef2 commit cdf22c3

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

library/core/src/slice/index.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -498,23 +498,23 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {
498498
///
499499
/// use std::slice;
500500
///
501-
/// slice::range(2..1, ..3);
501+
/// let _ = slice::range(2..1, ..3);
502502
/// ```
503503
///
504504
/// ```should_panic
505505
/// #![feature(slice_range)]
506506
///
507507
/// use std::slice;
508508
///
509-
/// slice::range(1..4, ..3);
509+
/// let _ = slice::range(1..4, ..3);
510510
/// ```
511511
///
512512
/// ```should_panic
513513
/// #![feature(slice_range)]
514514
///
515515
/// use std::slice;
516516
///
517-
/// slice::range(1..=usize::MAX, ..3);
517+
/// let _ = slice::range(1..=usize::MAX, ..3);
518518
/// ```
519519
///
520520
/// [`Index::index`]: ops::Index::index

src/test/ui/iterators/into-iter-on-arrays-lint.fixed

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// run-rustfix
33
// rustfix-only-machine-applicable
44

5+
#[allow(unused_must_use)]
56
fn main() {
67
let small = [1, 2];
78
let big = [0u8; 33];

src/test/ui/iterators/into-iter-on-arrays-lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// run-rustfix
33
// rustfix-only-machine-applicable
44

5+
#[allow(unused_must_use)]
56
fn main() {
67
let small = [1, 2];
78
let big = [0u8; 33];

src/test/ui/iterators/into-iter-on-arrays-lint.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
2-
--> $DIR/into-iter-on-arrays-lint.rs:10:11
2+
--> $DIR/into-iter-on-arrays-lint.rs:11:11
33
|
44
LL | small.into_iter();
55
| ^^^^^^^^^
@@ -17,7 +17,7 @@ LL | IntoIterator::into_iter(small);
1717
| ++++++++++++++++++++++++ ~
1818

1919
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
20-
--> $DIR/into-iter-on-arrays-lint.rs:13:12
20+
--> $DIR/into-iter-on-arrays-lint.rs:14:12
2121
|
2222
LL | [1, 2].into_iter();
2323
| ^^^^^^^^^
@@ -34,7 +34,7 @@ LL | IntoIterator::into_iter([1, 2]);
3434
| ++++++++++++++++++++++++ ~
3535

3636
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
37-
--> $DIR/into-iter-on-arrays-lint.rs:16:9
37+
--> $DIR/into-iter-on-arrays-lint.rs:17:9
3838
|
3939
LL | big.into_iter();
4040
| ^^^^^^^^^
@@ -51,7 +51,7 @@ LL | IntoIterator::into_iter(big);
5151
| ++++++++++++++++++++++++ ~
5252

5353
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
54-
--> $DIR/into-iter-on-arrays-lint.rs:19:15
54+
--> $DIR/into-iter-on-arrays-lint.rs:20:15
5555
|
5656
LL | [0u8; 33].into_iter();
5757
| ^^^^^^^^^
@@ -68,7 +68,7 @@ LL | IntoIterator::into_iter([0u8; 33]);
6868
| ++++++++++++++++++++++++ ~
6969

7070
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
71-
--> $DIR/into-iter-on-arrays-lint.rs:23:21
71+
--> $DIR/into-iter-on-arrays-lint.rs:24:21
7272
|
7373
LL | Box::new(small).into_iter();
7474
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -77,7 +77,7 @@ LL | Box::new(small).into_iter();
7777
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
7878

7979
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
80-
--> $DIR/into-iter-on-arrays-lint.rs:26:22
80+
--> $DIR/into-iter-on-arrays-lint.rs:27:22
8181
|
8282
LL | Box::new([1, 2]).into_iter();
8383
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -86,7 +86,7 @@ LL | Box::new([1, 2]).into_iter();
8686
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
8787

8888
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
89-
--> $DIR/into-iter-on-arrays-lint.rs:29:19
89+
--> $DIR/into-iter-on-arrays-lint.rs:30:19
9090
|
9191
LL | Box::new(big).into_iter();
9292
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -95,7 +95,7 @@ LL | Box::new(big).into_iter();
9595
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
9696

9797
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
98-
--> $DIR/into-iter-on-arrays-lint.rs:32:25
98+
--> $DIR/into-iter-on-arrays-lint.rs:33:25
9999
|
100100
LL | Box::new([0u8; 33]).into_iter();
101101
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -104,7 +104,7 @@ LL | Box::new([0u8; 33]).into_iter();
104104
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
105105

106106
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
107-
--> $DIR/into-iter-on-arrays-lint.rs:36:31
107+
--> $DIR/into-iter-on-arrays-lint.rs:37:31
108108
|
109109
LL | Box::new(Box::new(small)).into_iter();
110110
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -113,7 +113,7 @@ LL | Box::new(Box::new(small)).into_iter();
113113
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
114114

115115
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
116-
--> $DIR/into-iter-on-arrays-lint.rs:39:32
116+
--> $DIR/into-iter-on-arrays-lint.rs:40:32
117117
|
118118
LL | Box::new(Box::new([1, 2])).into_iter();
119119
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -122,7 +122,7 @@ LL | Box::new(Box::new([1, 2])).into_iter();
122122
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
123123

124124
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
125-
--> $DIR/into-iter-on-arrays-lint.rs:42:29
125+
--> $DIR/into-iter-on-arrays-lint.rs:43:29
126126
|
127127
LL | Box::new(Box::new(big)).into_iter();
128128
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -131,7 +131,7 @@ LL | Box::new(Box::new(big)).into_iter();
131131
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
132132

133133
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
134-
--> $DIR/into-iter-on-arrays-lint.rs:45:35
134+
--> $DIR/into-iter-on-arrays-lint.rs:46:35
135135
|
136136
LL | Box::new(Box::new([0u8; 33])).into_iter();
137137
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`

0 commit comments

Comments
 (0)