Skip to content

Commit 16a13b6

Browse files
committed
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.
1 parent f7bd3d4 commit 16a13b6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

library/core/src/slice/iter.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,10 @@ impl<'a, T> IterMut<'a, T> {
325325
#[must_use]
326326
#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
327327
#[inline]
328-
pub fn as_slice(&self) -> &[T] {
328+
pub fn as_slice<'b>(&'b self) -> &'b [T]
329+
where
330+
'a: 'b,
331+
{
329332
// SAFETY: the type invariant guarantees the pointer represents a valid slice
330333
unsafe { self.make_nonnull_slice().as_ref() }
331334
}
@@ -364,7 +367,10 @@ impl<'a, T> IterMut<'a, T> {
364367
#[must_use]
365368
// FIXME: Uncomment the `AsMut<[T]>` impl when this gets stabilized.
366369
#[unstable(feature = "slice_iter_mut_as_mut_slice", issue = "93079")]
367-
pub fn as_mut_slice(&mut self) -> &mut [T] {
370+
pub fn as_mut_slice<'b>(&'b mut self) -> &'b mut [T]
371+
where
372+
'a: 'b,
373+
{
368374
// SAFETY: the iterator was created from a mutable slice with pointer
369375
// `self.ptr` and length `len!(self)`. This guarantees that all the prerequisites
370376
// for `from_raw_parts_mut` are fulfilled.

0 commit comments

Comments
 (0)