Skip to content

Commit 3bea2ca

Browse files
committed
Use more impl header lifetime elision
There are two big categories of changes in here - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`) - 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.
1 parent 16ca0b9 commit 3bea2ca

35 files changed

+219
-219
lines changed

src/liballoc/borrow.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ pub enum Cow<'a, B: ?Sized + 'a>
182182
}
183183

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

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

298298
#[stable(feature = "rust1", since = "1.0.0")]
299-
impl<'a, B: ?Sized> Ord for Cow<'a, B>
299+
impl<B: ?Sized> Ord for Cow<'_, B>
300300
where B: Ord + ToOwned
301301
{
302302
#[inline]
303-
fn cmp(&self, other: &Cow<'a, B>) -> Ordering {
303+
fn cmp(&self, other: &Self) -> Ordering {
304304
Ord::cmp(&**self, &**other)
305305
}
306306
}
@@ -353,18 +353,18 @@ impl<B: ?Sized> fmt::Display for Cow<'_, B>
353353
}
354354

355355
#[stable(feature = "default", since = "1.11.0")]
356-
impl<'a, B: ?Sized> Default for Cow<'a, B>
356+
impl<B: ?Sized> Default for Cow<'_, B>
357357
where B: ToOwned,
358358
<B as ToOwned>::Owned: Default
359359
{
360360
/// Creates an owned Cow<'a, B> with the default value for the contained owned value.
361-
fn default() -> Cow<'a, B> {
361+
fn default() -> Self {
362362
Owned(<B as ToOwned>::Owned::default())
363363
}
364364
}
365365

366366
#[stable(feature = "rust1", since = "1.0.0")]
367-
impl<'a, B: ?Sized> Hash for Cow<'a, B>
367+
impl<B: ?Sized> Hash for Cow<'_, B>
368368
where B: Hash + ToOwned
369369
{
370370
#[inline]

src/liballoc/collections/binary_heap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
947947

948948
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
949949
#[stable(feature = "rust1", since = "1.0.0")]
950-
impl<'a, T> Clone for Iter<'a, T> {
951-
fn clone(&self) -> Iter<'a, T> {
950+
impl<T> Clone for Iter<'_, T> {
951+
fn clone(&self) -> Self {
952952
Iter { iter: self.iter.clone() }
953953
}
954954
}

src/liballoc/collections/btree/map.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,8 @@ impl<K, V> ExactSizeIterator for Iter<'_, K, V> {
12181218
}
12191219

12201220
#[stable(feature = "rust1", since = "1.0.0")]
1221-
impl<'a, K, V> Clone for Iter<'a, K, V> {
1222-
fn clone(&self) -> Iter<'a, K, V> {
1221+
impl<K, V> Clone for Iter<'_, K, V> {
1222+
fn clone(&self) -> Self {
12231223
Iter {
12241224
range: self.range.clone(),
12251225
length: self.length,
@@ -1441,8 +1441,8 @@ impl<K, V> ExactSizeIterator for Keys<'_, K, V> {
14411441
impl<K, V> FusedIterator for Keys<'_, K, V> {}
14421442

14431443
#[stable(feature = "rust1", since = "1.0.0")]
1444-
impl<'a, K, V> Clone for Keys<'a, K, V> {
1445-
fn clone(&self) -> Keys<'a, K, V> {
1444+
impl<K, V> Clone for Keys<'_, K, V> {
1445+
fn clone(&self) -> Self {
14461446
Keys { inner: self.inner.clone() }
14471447
}
14481448
}
@@ -1478,8 +1478,8 @@ impl<K, V> ExactSizeIterator for Values<'_, K, V> {
14781478
impl<K, V> FusedIterator for Values<'_, K, V> {}
14791479

14801480
#[stable(feature = "rust1", since = "1.0.0")]
1481-
impl<'a, K, V> Clone for Values<'a, K, V> {
1482-
fn clone(&self) -> Values<'a, K, V> {
1481+
impl<K, V> Clone for Values<'_, K, V> {
1482+
fn clone(&self) -> Self {
14831483
Values { inner: self.inner.clone() }
14841484
}
14851485
}
@@ -1606,8 +1606,8 @@ impl<'a, K, V> Range<'a, K, V> {
16061606
impl<K, V> FusedIterator for Range<'_, K, V> {}
16071607

16081608
#[stable(feature = "btree_range", since = "1.17.0")]
1609-
impl<'a, K, V> Clone for Range<'a, K, V> {
1610-
fn clone(&self) -> Range<'a, K, V> {
1609+
impl<K, V> Clone for Range<'_, K, V> {
1610+
fn clone(&self) -> Self {
16111611
Range {
16121612
front: self.front,
16131613
back: self.back,

src/liballoc/collections/btree/set.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ impl<T: Debug> Debug for BTreeSet<T> {
907907
}
908908

909909
#[stable(feature = "rust1", since = "1.0.0")]
910-
impl<'a, T> Clone for Iter<'a, T> {
911-
fn clone(&self) -> Iter<'a, T> {
910+
impl<T> Clone for Iter<'_, T> {
911+
fn clone(&self) -> Self {
912912
Iter { iter: self.iter.clone() }
913913
}
914914
}
@@ -963,8 +963,8 @@ impl<T> ExactSizeIterator for IntoIter<T> {
963963
impl<T> FusedIterator for IntoIter<T> {}
964964

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

10001000
#[stable(feature = "rust1", since = "1.0.0")]
1001-
impl<'a, T> Clone for Difference<'a, T> {
1002-
fn clone(&self) -> Difference<'a, T> {
1001+
impl<T> Clone for Difference<'_, T> {
1002+
fn clone(&self) -> Self {
10031003
Difference {
10041004
a: self.a.clone(),
10051005
b: self.b.clone(),
@@ -1036,8 +1036,8 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> {
10361036
impl<T: Ord> FusedIterator for Difference<'_, T> {}
10371037

10381038
#[stable(feature = "rust1", since = "1.0.0")]
1039-
impl<'a, T> Clone for SymmetricDifference<'a, T> {
1040-
fn clone(&self) -> SymmetricDifference<'a, T> {
1039+
impl<T> Clone for SymmetricDifference<'_, T> {
1040+
fn clone(&self) -> Self {
10411041
SymmetricDifference {
10421042
a: self.a.clone(),
10431043
b: self.b.clone(),
@@ -1070,8 +1070,8 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
10701070
impl<T: Ord> FusedIterator for SymmetricDifference<'_, T> {}
10711071

10721072
#[stable(feature = "rust1", since = "1.0.0")]
1073-
impl<'a, T> Clone for Intersection<'a, T> {
1074-
fn clone(&self) -> Intersection<'a, T> {
1073+
impl<T> Clone for Intersection<'_, T> {
1074+
fn clone(&self) -> Self {
10751075
Intersection {
10761076
a: self.a.clone(),
10771077
b: self.b.clone(),
@@ -1108,8 +1108,8 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
11081108
impl<T: Ord> FusedIterator for Intersection<'_, T> {}
11091109

11101110
#[stable(feature = "rust1", since = "1.0.0")]
1111-
impl<'a, T> Clone for Union<'a, T> {
1112-
fn clone(&self) -> Union<'a, T> {
1111+
impl<T> Clone for Union<'_, T> {
1112+
fn clone(&self) -> Self {
11131113
Union {
11141114
a: self.a.clone(),
11151115
b: self.b.clone(),

src/liballoc/collections/linked_list.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1200,16 +1200,16 @@ unsafe impl<T: Send> Send for LinkedList<T> {}
12001200
unsafe impl<T: Sync> Sync for LinkedList<T> {}
12011201

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

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

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

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

12141214
#[cfg(test)]
12151215
mod tests {

src/liballoc/collections/vec_deque.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2132,8 +2132,8 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
21322132

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

22272227
#[stable(feature = "collection_debug", since = "1.17.0")]
2228-
impl<'a, T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
2228+
impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
22292229
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22302230
let (front, back) = RingSlices::ring_slices(&*self.ring, self.head, self.tail);
22312231
f.debug_tuple("IterMut")

src/liballoc/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2455,7 +2455,7 @@ pub struct Drain<'a, T: 'a> {
24552455
}
24562456

24572457
#[stable(feature = "collection_debug", since = "1.17.0")]
2458-
impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> {
2458+
impl<T: fmt::Debug> fmt::Debug for Drain<'_, T> {
24592459
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24602460
f.debug_tuple("Drain")
24612461
.field(&self.iter.as_slice())

src/libcore/future/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub trait Future {
100100
fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output>;
101101
}
102102

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

106106
fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {

src/libcore/internal_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ macro_rules! forward_ref_unop {
77
};
88
(impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
99
#[$attr]
10-
impl<'a> $imp for &'a $t {
10+
impl $imp for &$t {
1111
type Output = <$t as $imp>::Output;
1212

1313
#[inline]

src/libcore/option.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ impl<T> Option<T> {
874874
}
875875
}
876876

877-
impl<'a, T: Copy> Option<&'a T> {
877+
impl<T: Copy> Option<&T> {
878878
/// Maps an `Option<&T>` to an `Option<T>` by copying the contents of the
879879
/// option.
880880
///
@@ -895,7 +895,7 @@ impl<'a, T: Copy> Option<&'a T> {
895895
}
896896
}
897897

898-
impl<'a, T: Copy> Option<&'a mut T> {
898+
impl<T: Copy> Option<&mut T> {
899899
/// Maps an `Option<&mut T>` to an `Option<T>` by copying the contents of the
900900
/// option.
901901
///
@@ -916,7 +916,7 @@ impl<'a, T: Copy> Option<&'a mut T> {
916916
}
917917
}
918918

919-
impl<'a, T: Clone> Option<&'a T> {
919+
impl<T: Clone> Option<&T> {
920920
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
921921
/// option.
922922
///
@@ -935,7 +935,7 @@ impl<'a, T: Clone> Option<&'a T> {
935935
}
936936
}
937937

938-
impl<'a, T: Clone> Option<&'a mut T> {
938+
impl<T: Clone> Option<&mut T> {
939939
/// Maps an `Option<&mut T>` to an `Option<T>` by cloning the contents of the
940940
/// option.
941941
///

src/libcore/slice/mod.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ macro_rules! iterator {
28992899
}
29002900

29012901
#[stable(feature = "rust1", since = "1.0.0")]
2902-
impl<'a, T> ExactSizeIterator for $name<'a, T> {
2902+
impl<T> ExactSizeIterator for $name<'_, T> {
29032903
#[inline(always)]
29042904
fn len(&self) -> usize {
29052905
len!(self)
@@ -3094,10 +3094,10 @@ macro_rules! iterator {
30943094
}
30953095

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

30993099
#[unstable(feature = "trusted_len", issue = "37572")]
3100-
unsafe impl<'a, T> TrustedLen for $name<'a, T> {}
3100+
unsafe impl<T> TrustedLen for $name<'_, T> {}
31013101
}
31023102
}
31033103

@@ -4361,8 +4361,8 @@ pub struct RChunks<'a, T:'a> {
43614361

43624362
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
43634363
#[stable(feature = "rchunks", since = "1.31.0")]
4364-
impl<'a, T> Clone for RChunks<'a, T> {
4365-
fn clone(&self) -> RChunks<'a, T> {
4364+
impl<T> Clone for RChunks<'_, T> {
4365+
fn clone(&self) -> Self {
43664366
RChunks {
43674367
v: self.v,
43684368
chunk_size: self.chunk_size,
@@ -4451,13 +4451,13 @@ impl<'a, T> DoubleEndedIterator for RChunks<'a, T> {
44514451
}
44524452

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

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

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

44624462
#[doc(hidden)]
44634463
#[stable(feature = "rchunks", since = "1.31.0")]
@@ -4576,13 +4576,13 @@ impl<'a, T> DoubleEndedIterator for RChunksMut<'a, T> {
45764576
}
45774577

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

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

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

45874587
#[doc(hidden)]
45884588
#[stable(feature = "rchunks", since = "1.31.0")]
@@ -4707,10 +4707,10 @@ impl<'a, T> ExactSizeIterator for RChunksExact<'a, T> {
47074707
}
47084708

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

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

47154715
#[doc(hidden)]
47164716
#[stable(feature = "rchunks", since = "1.31.0")]
@@ -4818,17 +4818,17 @@ impl<'a, T> DoubleEndedIterator for RChunksExactMut<'a, T> {
48184818
}
48194819

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

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

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

48334833
#[doc(hidden)]
48344834
#[stable(feature = "rchunks", since = "1.31.0")]

src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl FusedIterator for Bytes<'_> {}
820820
unsafe impl TrustedLen for Bytes<'_> {}
821821

822822
#[doc(hidden)]
823-
unsafe impl<'a> TrustedRandomAccess for Bytes<'a> {
823+
unsafe impl TrustedRandomAccess for Bytes<'_> {
824824
unsafe fn get_unchecked(&mut self, i: usize) -> u8 {
825825
self.0.get_unchecked(i)
826826
}

0 commit comments

Comments
 (0)