Skip to content

Commit

Permalink
add #[must_use] to functions of slice and its iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikw committed Jan 13, 2022
1 parent 67c9ef2 commit cdf22c3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions library/core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,23 +498,23 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {
///
/// use std::slice;
///
/// slice::range(2..1, ..3);
/// let _ = slice::range(2..1, ..3);
/// ```
///
/// ```should_panic
/// #![feature(slice_range)]
///
/// use std::slice;
///
/// slice::range(1..4, ..3);
/// let _ = slice::range(1..4, ..3);
/// ```
///
/// ```should_panic
/// #![feature(slice_range)]
///
/// use std::slice;
///
/// slice::range(1..=usize::MAX, ..3);
/// let _ = slice::range(1..=usize::MAX, ..3);
/// ```
///
/// [`Index::index`]: ops::Index::index
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/iterators/into-iter-on-arrays-lint.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// run-rustfix
// rustfix-only-machine-applicable

#[allow(unused_must_use)]
fn main() {
let small = [1, 2];
let big = [0u8; 33];
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/iterators/into-iter-on-arrays-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// run-rustfix
// rustfix-only-machine-applicable

#[allow(unused_must_use)]
fn main() {
let small = [1, 2];
let big = [0u8; 33];
Expand Down
24 changes: 12 additions & 12 deletions src/test/ui/iterators/into-iter-on-arrays-lint.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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
--> $DIR/into-iter-on-arrays-lint.rs:10:11
--> $DIR/into-iter-on-arrays-lint.rs:11:11
|
LL | small.into_iter();
| ^^^^^^^^^
Expand All @@ -17,7 +17,7 @@ LL | IntoIterator::into_iter(small);
| ++++++++++++++++++++++++ ~

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
--> $DIR/into-iter-on-arrays-lint.rs:13:12
--> $DIR/into-iter-on-arrays-lint.rs:14:12
|
LL | [1, 2].into_iter();
| ^^^^^^^^^
Expand All @@ -34,7 +34,7 @@ LL | IntoIterator::into_iter([1, 2]);
| ++++++++++++++++++++++++ ~

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
--> $DIR/into-iter-on-arrays-lint.rs:16:9
--> $DIR/into-iter-on-arrays-lint.rs:17:9
|
LL | big.into_iter();
| ^^^^^^^^^
Expand All @@ -51,7 +51,7 @@ LL | IntoIterator::into_iter(big);
| ++++++++++++++++++++++++ ~

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
--> $DIR/into-iter-on-arrays-lint.rs:19:15
--> $DIR/into-iter-on-arrays-lint.rs:20:15
|
LL | [0u8; 33].into_iter();
| ^^^^^^^^^
Expand All @@ -68,7 +68,7 @@ LL | IntoIterator::into_iter([0u8; 33]);
| ++++++++++++++++++++++++ ~

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
--> $DIR/into-iter-on-arrays-lint.rs:23:21
--> $DIR/into-iter-on-arrays-lint.rs:24:21
|
LL | Box::new(small).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -77,7 +77,7 @@ LL | Box::new(small).into_iter();
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>

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
--> $DIR/into-iter-on-arrays-lint.rs:26:22
--> $DIR/into-iter-on-arrays-lint.rs:27:22
|
LL | Box::new([1, 2]).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -86,7 +86,7 @@ LL | Box::new([1, 2]).into_iter();
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>

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
--> $DIR/into-iter-on-arrays-lint.rs:29:19
--> $DIR/into-iter-on-arrays-lint.rs:30:19
|
LL | Box::new(big).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -95,7 +95,7 @@ LL | Box::new(big).into_iter();
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>

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
--> $DIR/into-iter-on-arrays-lint.rs:32:25
--> $DIR/into-iter-on-arrays-lint.rs:33:25
|
LL | Box::new([0u8; 33]).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -104,7 +104,7 @@ LL | Box::new([0u8; 33]).into_iter();
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>

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
--> $DIR/into-iter-on-arrays-lint.rs:36:31
--> $DIR/into-iter-on-arrays-lint.rs:37:31
|
LL | Box::new(Box::new(small)).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -113,7 +113,7 @@ LL | Box::new(Box::new(small)).into_iter();
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>

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
--> $DIR/into-iter-on-arrays-lint.rs:39:32
--> $DIR/into-iter-on-arrays-lint.rs:40:32
|
LL | Box::new(Box::new([1, 2])).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -122,7 +122,7 @@ LL | Box::new(Box::new([1, 2])).into_iter();
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>

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
--> $DIR/into-iter-on-arrays-lint.rs:42:29
--> $DIR/into-iter-on-arrays-lint.rs:43:29
|
LL | Box::new(Box::new(big)).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -131,7 +131,7 @@ LL | Box::new(Box::new(big)).into_iter();
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>

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
--> $DIR/into-iter-on-arrays-lint.rs:45:35
--> $DIR/into-iter-on-arrays-lint.rs:46:35
|
LL | Box::new(Box::new([0u8; 33])).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand Down

0 comments on commit cdf22c3

Please sign in to comment.