From 16a13b6a9d2b5095c9f6c28145c284b0c8712ff6 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 26 Apr 2024 14:16:06 -0700 Subject: [PATCH] Be super-explicit about `IterMut` slice lifetimes This is the same as the previous signature, but since it's *not* `-> &'a [T]` like in `Iter`, I think it's worth emphasizing that in the signature too, not just the text. --- library/core/src/slice/iter.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index fb3cde6e30c93..f1ec0ca05755c 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -325,7 +325,10 @@ impl<'a, T> IterMut<'a, T> { #[must_use] #[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")] #[inline] - pub fn as_slice(&self) -> &[T] { + pub fn as_slice<'b>(&'b self) -> &'b [T] + where + 'a: 'b, + { // SAFETY: the type invariant guarantees the pointer represents a valid slice unsafe { self.make_nonnull_slice().as_ref() } } @@ -364,7 +367,10 @@ impl<'a, T> IterMut<'a, T> { #[must_use] // FIXME: Uncomment the `AsMut<[T]>` impl when this gets stabilized. #[unstable(feature = "slice_iter_mut_as_mut_slice", issue = "93079")] - pub fn as_mut_slice(&mut self) -> &mut [T] { + pub fn as_mut_slice<'b>(&'b mut self) -> &'b mut [T] + where + 'a: 'b, + { // SAFETY: the iterator was created from a mutable slice with pointer // `self.ptr` and length `len!(self)`. This guarantees that all the prerequisites // for `from_raw_parts_mut` are fulfilled.