Add #[must_use] to conversions that move self

This commit is contained in:
John Kugelman
2021-10-10 19:50:52 -04:00
parent 6928fafe06
commit b115781bcd
19 changed files with 54 additions and 11 deletions

View File

@@ -267,6 +267,7 @@ impl<'a, T> IterMut<'a, T> {
/// // Now slice is "[2, 2, 3]":
/// println!("{:?}", slice);
/// ```
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "iter_to_slice", since = "1.4.0")]
pub fn into_slice(self) -> &'a mut [T] {
// SAFETY: the iterator was created from a mutable slice with pointer
@@ -1869,6 +1870,7 @@ impl<'a, T> ChunksExactMut<'a, T> {
/// Returns the remainder of the original slice that is not going to be
/// returned by the iterator. The returned slice has at most `chunk_size-1`
/// elements.
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "chunks_exact", since = "1.31.0")]
pub fn into_remainder(self) -> &'a mut [T] {
self.rem
@@ -2264,6 +2266,7 @@ impl<'a, T, const N: usize> ArrayChunksMut<'a, T, N> {
/// Returns the remainder of the original slice that is not going to be
/// returned by the iterator. The returned slice has at most `N-1`
/// elements.
#[must_use = "`self` will be dropped if the result is not used"]
#[unstable(feature = "array_chunks", issue = "74985")]
pub fn into_remainder(self) -> &'a mut [T] {
self.rem
@@ -2875,6 +2878,7 @@ impl<'a, T> RChunksExactMut<'a, T> {
/// Returns the remainder of the original slice that is not going to be
/// returned by the iterator. The returned slice has at most `chunk_size-1`
/// elements.
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "rchunks", since = "1.31.0")]
pub fn into_remainder(self) -> &'a mut [T] {
self.rem