Skip to content

Commit

Permalink
Be super-explicit about IterMut slice lifetimes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
scottmcm committed Apr 26, 2024
1 parent ce284af commit 0178215
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions library/core/src/slice/iter.rs
Expand Up @@ -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() }
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0178215

Please sign in to comment.