Skip to content

Commit

Permalink
Rollup merge of rust-lang#58553 - scottmcm:more-ihle, r=Centril
Browse files Browse the repository at this point in the history
Use more impl header lifetime elision

Inspired by seeing explicit lifetimes on these two:

- https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator
- https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not

And a follow-up to rust-lang#54687, that started using IHLE in libcore.

Most of the changes in here fall into two big categories:

- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`)

- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)

I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm).

I also removed two lifetimes that turned out to be completely unused; see rust-lang#41960 (comment)
  • Loading branch information
kennytm committed Feb 20, 2019
2 parents ef0aadd + 3bea2ca commit e3a8f7d
Show file tree
Hide file tree
Showing 35 changed files with 219 additions and 219 deletions.
16 changes: 8 additions & 8 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ pub enum Cow<'a, B: ?Sized + 'a>
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized + ToOwned> Clone for Cow<'a, B> {
fn clone(&self) -> Cow<'a, B> {
impl<B: ?Sized + ToOwned> Clone for Cow<'_, B> {
fn clone(&self) -> Self {
match *self {
Borrowed(b) => Borrowed(b),
Owned(ref o) => {
Expand All @@ -193,7 +193,7 @@ impl<'a, B: ?Sized + ToOwned> Clone for Cow<'a, B> {
}
}

fn clone_from(&mut self, source: &Cow<'a, B>) {
fn clone_from(&mut self, source: &Self) {
if let Owned(ref mut dest) = *self {
if let Owned(ref o) = *source {
o.borrow().clone_into(dest);
Expand Down Expand Up @@ -296,11 +296,11 @@ impl<B: ?Sized + ToOwned> Deref for Cow<'_, B> {
impl<B: ?Sized> Eq for Cow<'_, B> where B: Eq + ToOwned {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Ord for Cow<'a, B>
impl<B: ?Sized> Ord for Cow<'_, B>
where B: Ord + ToOwned
{
#[inline]
fn cmp(&self, other: &Cow<'a, B>) -> Ordering {
fn cmp(&self, other: &Self) -> Ordering {
Ord::cmp(&**self, &**other)
}
}
Expand Down Expand Up @@ -353,18 +353,18 @@ impl<B: ?Sized> fmt::Display for Cow<'_, B>
}

#[stable(feature = "default", since = "1.11.0")]
impl<'a, B: ?Sized> Default for Cow<'a, B>
impl<B: ?Sized> Default for Cow<'_, B>
where B: ToOwned,
<B as ToOwned>::Owned: Default
{
/// Creates an owned Cow<'a, B> with the default value for the contained owned value.
fn default() -> Cow<'a, B> {
fn default() -> Self {
Owned(<B as ToOwned>::Owned::default())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Hash for Cow<'a, B>
impl<B: ?Sized> Hash for Cow<'_, B>
where B: Hash + ToOwned
{
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {

// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Iter<'a, T> {
fn clone(&self) -> Iter<'a, T> {
impl<T> Clone for Iter<'_, T> {
fn clone(&self) -> Self {
Iter { iter: self.iter.clone() }
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,8 @@ impl<K, V> ExactSizeIterator for Iter<'_, K, V> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Clone for Iter<'a, K, V> {
fn clone(&self) -> Iter<'a, K, V> {
impl<K, V> Clone for Iter<'_, K, V> {
fn clone(&self) -> Self {
Iter {
range: self.range.clone(),
length: self.length,
Expand Down Expand Up @@ -1441,8 +1441,8 @@ impl<K, V> ExactSizeIterator for Keys<'_, K, V> {
impl<K, V> FusedIterator for Keys<'_, K, V> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Clone for Keys<'a, K, V> {
fn clone(&self) -> Keys<'a, K, V> {
impl<K, V> Clone for Keys<'_, K, V> {
fn clone(&self) -> Self {
Keys { inner: self.inner.clone() }
}
}
Expand Down Expand Up @@ -1478,8 +1478,8 @@ impl<K, V> ExactSizeIterator for Values<'_, K, V> {
impl<K, V> FusedIterator for Values<'_, K, V> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Clone for Values<'a, K, V> {
fn clone(&self) -> Values<'a, K, V> {
impl<K, V> Clone for Values<'_, K, V> {
fn clone(&self) -> Self {
Values { inner: self.inner.clone() }
}
}
Expand Down Expand Up @@ -1606,8 +1606,8 @@ impl<'a, K, V> Range<'a, K, V> {
impl<K, V> FusedIterator for Range<'_, K, V> {}

#[stable(feature = "btree_range", since = "1.17.0")]
impl<'a, K, V> Clone for Range<'a, K, V> {
fn clone(&self) -> Range<'a, K, V> {
impl<K, V> Clone for Range<'_, K, V> {
fn clone(&self) -> Self {
Range {
front: self.front,
back: self.back,
Expand Down
24 changes: 12 additions & 12 deletions src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,8 @@ impl<T: Debug> Debug for BTreeSet<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Iter<'a, T> {
fn clone(&self) -> Iter<'a, T> {
impl<T> Clone for Iter<'_, T> {
fn clone(&self) -> Self {
Iter { iter: self.iter.clone() }
}
}
Expand Down Expand Up @@ -963,8 +963,8 @@ impl<T> ExactSizeIterator for IntoIter<T> {
impl<T> FusedIterator for IntoIter<T> {}

#[stable(feature = "btree_range", since = "1.17.0")]
impl<'a, T> Clone for Range<'a, T> {
fn clone(&self) -> Range<'a, T> {
impl<T> Clone for Range<'_, T> {
fn clone(&self) -> Self {
Range { iter: self.iter.clone() }
}
}
Expand Down Expand Up @@ -998,8 +998,8 @@ fn cmp_opt<T: Ord>(x: Option<&T>, y: Option<&T>, short: Ordering, long: Ordering
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Difference<'a, T> {
fn clone(&self) -> Difference<'a, T> {
impl<T> Clone for Difference<'_, T> {
fn clone(&self) -> Self {
Difference {
a: self.a.clone(),
b: self.b.clone(),
Expand Down Expand Up @@ -1036,8 +1036,8 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> {
impl<T: Ord> FusedIterator for Difference<'_, T> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for SymmetricDifference<'a, T> {
fn clone(&self) -> SymmetricDifference<'a, T> {
impl<T> Clone for SymmetricDifference<'_, T> {
fn clone(&self) -> Self {
SymmetricDifference {
a: self.a.clone(),
b: self.b.clone(),
Expand Down Expand Up @@ -1070,8 +1070,8 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
impl<T: Ord> FusedIterator for SymmetricDifference<'_, T> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Intersection<'a, T> {
fn clone(&self) -> Intersection<'a, T> {
impl<T> Clone for Intersection<'_, T> {
fn clone(&self) -> Self {
Intersection {
a: self.a.clone(),
b: self.b.clone(),
Expand Down Expand Up @@ -1108,8 +1108,8 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
impl<T: Ord> FusedIterator for Intersection<'_, T> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Union<'a, T> {
fn clone(&self) -> Union<'a, T> {
impl<T> Clone for Union<'_, T> {
fn clone(&self) -> Self {
Union {
a: self.a.clone(),
b: self.b.clone(),
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,16 +1200,16 @@ unsafe impl<T: Send> Send for LinkedList<T> {}
unsafe impl<T: Sync> Sync for LinkedList<T> {}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<'a, T: Sync> Send for Iter<'a, T> {}
unsafe impl<T: Sync> Send for Iter<'_, T> {}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<'a, T: Sync> Sync for Iter<'a, T> {}
unsafe impl<T: Sync> Sync for Iter<'_, T> {}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<'a, T: Send> Send for IterMut<'a, T> {}
unsafe impl<T: Send> Send for IterMut<'_, T> {}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {}
unsafe impl<T: Sync> Sync for IterMut<'_, T> {}

#[cfg(test)]
mod tests {
Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2132,8 +2132,8 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {

// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Iter<'a, T> {
fn clone(&self) -> Iter<'a, T> {
impl<T> Clone for Iter<'_, T> {
fn clone(&self) -> Self {
Iter {
ring: self.ring,
tail: self.tail,
Expand Down Expand Up @@ -2225,7 +2225,7 @@ pub struct IterMut<'a, T: 'a> {
}

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<'a, T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (front, back) = RingSlices::ring_slices(&*self.ring, self.head, self.tail);
f.debug_tuple("IterMut")
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,7 @@ pub struct Drain<'a, T: 'a> {
}

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> {
impl<T: fmt::Debug> fmt::Debug for Drain<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Drain")
.field(&self.iter.as_slice())
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub trait Future {
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output>;
}

impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {
impl<F: ?Sized + Future + Unpin> Future for &mut F {
type Output = F::Output;

fn poll(mut self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro_rules! forward_ref_unop {
};
(impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
#[$attr]
impl<'a> $imp for &'a $t {
impl $imp for &$t {
type Output = <$t as $imp>::Output;

#[inline]
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ impl<T> Option<T> {
}
}

impl<'a, T: Copy> Option<&'a T> {
impl<T: Copy> Option<&T> {
/// Maps an `Option<&T>` to an `Option<T>` by copying the contents of the
/// option.
///
Expand All @@ -895,7 +895,7 @@ impl<'a, T: Copy> Option<&'a T> {
}
}

impl<'a, T: Copy> Option<&'a mut T> {
impl<T: Copy> Option<&mut T> {
/// Maps an `Option<&mut T>` to an `Option<T>` by copying the contents of the
/// option.
///
Expand All @@ -916,7 +916,7 @@ impl<'a, T: Copy> Option<&'a mut T> {
}
}

impl<'a, T: Clone> Option<&'a T> {
impl<T: Clone> Option<&T> {
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
/// option.
///
Expand All @@ -935,7 +935,7 @@ impl<'a, T: Clone> Option<&'a T> {
}
}

impl<'a, T: Clone> Option<&'a mut T> {
impl<T: Clone> Option<&mut T> {
/// Maps an `Option<&mut T>` to an `Option<T>` by cloning the contents of the
/// option.
///
Expand Down
32 changes: 16 additions & 16 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2903,7 +2903,7 @@ macro_rules! iterator {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for $name<'a, T> {
impl<T> ExactSizeIterator for $name<'_, T> {
#[inline(always)]
fn len(&self) -> usize {
len!(self)
Expand Down Expand Up @@ -3098,10 +3098,10 @@ macro_rules! iterator {
}

#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for $name<'a, T> {}
impl<T> FusedIterator for $name<'_, T> {}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, T> TrustedLen for $name<'a, T> {}
unsafe impl<T> TrustedLen for $name<'_, T> {}
}
}

Expand Down Expand Up @@ -4365,8 +4365,8 @@ pub struct RChunks<'a, T:'a> {

// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> Clone for RChunks<'a, T> {
fn clone(&self) -> RChunks<'a, T> {
impl<T> Clone for RChunks<'_, T> {
fn clone(&self) -> Self {
RChunks {
v: self.v,
chunk_size: self.chunk_size,
Expand Down Expand Up @@ -4455,13 +4455,13 @@ impl<'a, T> DoubleEndedIterator for RChunks<'a, T> {
}

#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> ExactSizeIterator for RChunks<'a, T> {}
impl<T> ExactSizeIterator for RChunks<'_, T> {}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, T> TrustedLen for RChunks<'a, T> {}
unsafe impl<T> TrustedLen for RChunks<'_, T> {}

#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> FusedIterator for RChunks<'a, T> {}
impl<T> FusedIterator for RChunks<'_, T> {}

#[doc(hidden)]
#[stable(feature = "rchunks", since = "1.31.0")]
Expand Down Expand Up @@ -4580,13 +4580,13 @@ impl<'a, T> DoubleEndedIterator for RChunksMut<'a, T> {
}

#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> ExactSizeIterator for RChunksMut<'a, T> {}
impl<T> ExactSizeIterator for RChunksMut<'_, T> {}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, T> TrustedLen for RChunksMut<'a, T> {}
unsafe impl<T> TrustedLen for RChunksMut<'_, T> {}

#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> FusedIterator for RChunksMut<'a, T> {}
impl<T> FusedIterator for RChunksMut<'_, T> {}

#[doc(hidden)]
#[stable(feature = "rchunks", since = "1.31.0")]
Expand Down Expand Up @@ -4711,10 +4711,10 @@ impl<'a, T> ExactSizeIterator for RChunksExact<'a, T> {
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, T> TrustedLen for RChunksExact<'a, T> {}
unsafe impl<T> TrustedLen for RChunksExact<'_, T> {}

#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> FusedIterator for RChunksExact<'a, T> {}
impl<T> FusedIterator for RChunksExact<'_, T> {}

#[doc(hidden)]
#[stable(feature = "rchunks", since = "1.31.0")]
Expand Down Expand Up @@ -4822,17 +4822,17 @@ impl<'a, T> DoubleEndedIterator for RChunksExactMut<'a, T> {
}

#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> ExactSizeIterator for RChunksExactMut<'a, T> {
impl<T> ExactSizeIterator for RChunksExactMut<'_, T> {
fn is_empty(&self) -> bool {
self.v.is_empty()
}
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, T> TrustedLen for RChunksExactMut<'a, T> {}
unsafe impl<T> TrustedLen for RChunksExactMut<'_, T> {}

#[stable(feature = "rchunks", since = "1.31.0")]
impl<'a, T> FusedIterator for RChunksExactMut<'a, T> {}
impl<T> FusedIterator for RChunksExactMut<'_, T> {}

#[doc(hidden)]
#[stable(feature = "rchunks", since = "1.31.0")]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ impl FusedIterator for Bytes<'_> {}
unsafe impl TrustedLen for Bytes<'_> {}

#[doc(hidden)]
unsafe impl<'a> TrustedRandomAccess for Bytes<'a> {
unsafe impl TrustedRandomAccess for Bytes<'_> {
unsafe fn get_unchecked(&mut self, i: usize) -> u8 {
self.0.get_unchecked(i)
}
Expand Down
Loading

0 comments on commit e3a8f7d

Please sign in to comment.