Add #[must_use] to conversions that move self
This commit is contained in:
parent
6928fafe06
commit
b115781bcd
19 changed files with 54 additions and 11 deletions
|
@ -1473,6 +1473,7 @@ impl<T: Copy> Option<&mut T> {
|
|||
/// let copied = opt_x.copied();
|
||||
/// assert_eq!(copied, Some(12));
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "copied", since = "1.35.0")]
|
||||
pub fn copied(self) -> Option<T> {
|
||||
self.map(|&mut t| t)
|
||||
|
@ -1492,6 +1493,7 @@ impl<T: Clone> Option<&T> {
|
|||
/// let cloned = opt_x.cloned();
|
||||
/// assert_eq!(cloned, Some(12));
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn cloned(self) -> Option<T> {
|
||||
self.map(|t| t.clone())
|
||||
|
|
|
@ -715,6 +715,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
|
|||
impl<'a, T: ?Sized> Pin<&'a mut T> {
|
||||
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
|
||||
#[inline(always)]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
pub const fn into_ref(self) -> Pin<&'a T> {
|
||||
|
@ -731,6 +732,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
|
|||
/// the `Pin` itself. This method allows turning the `Pin` into a reference
|
||||
/// with the same lifetime as the original `Pin`.
|
||||
#[inline(always)]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
||||
pub const fn get_mut(self) -> &'a mut T
|
||||
|
@ -751,6 +753,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
|
|||
/// If the underlying data is `Unpin`, `Pin::get_mut` should be used
|
||||
/// instead.
|
||||
#[inline(always)]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
||||
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
|
||||
|
@ -772,6 +775,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
|
|||
/// not move out of the argument you receive to the interior function.
|
||||
///
|
||||
/// [`pin` module]: self#projections-and-structural-pinning
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
pub unsafe fn map_unchecked_mut<U, F>(self, func: F) -> Pin<&'a mut U>
|
||||
where
|
||||
|
@ -811,6 +815,7 @@ impl<'a, P: DerefMut> Pin<&'a mut Pin<P>> {
|
|||
/// implementations of `P::DerefMut` are likewise ruled out by the contract of
|
||||
/// `Pin::new_unchecked`.
|
||||
#[unstable(feature = "pin_deref_mut", issue = "86918")]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[inline(always)]
|
||||
pub fn as_deref_mut(self) -> Pin<&'a mut P::Target> {
|
||||
// SAFETY: What we're asserting here is that going from
|
||||
|
|
|
@ -101,6 +101,7 @@ impl<T: ?Sized> Unique<T> {
|
|||
}
|
||||
|
||||
/// Acquires the underlying `*mut` pointer.
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[inline]
|
||||
pub const fn as_ptr(self) -> *mut T {
|
||||
self.pointer as *mut T
|
||||
|
@ -131,6 +132,7 @@ impl<T: ?Sized> Unique<T> {
|
|||
}
|
||||
|
||||
/// Casts to a pointer of another type.
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[inline]
|
||||
pub const fn cast<U>(self) -> Unique<U> {
|
||||
// SAFETY: Unique::new_unchecked() creates a new unique and needs
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue