Skip to content

Commit e3a8f7d

Browse files
committed
Rollup merge of rust-lang#58553 - scottmcm:more-ihle, r=Centril
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)
2 parents ef0aadd + 3bea2ca commit e3a8f7d

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
@@ -92,7 +92,7 @@ pub trait Future {
9292
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output>;
9393
}
9494

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

9898
fn poll(mut self: Pin<&mut Self>, waker: &Waker) -> 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
@@ -2903,7 +2903,7 @@ macro_rules! iterator {
29032903
}
29042904

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

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

31033103
#[unstable(feature = "trusted_len", issue = "37572")]
3104-
unsafe impl<'a, T> TrustedLen for $name<'a, T> {}
3104+
unsafe impl<T> TrustedLen for $name<'_, T> {}
31053105
}
31063106
}
31073107

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

48374837
#[doc(hidden)]
48384838
#[stable(feature = "rchunks", since = "1.31.0")]

src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl FusedIterator for Bytes<'_> {}
823823
unsafe impl TrustedLen for Bytes<'_> {}
824824

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

0 commit comments

Comments
 (0)