Skip to content

Commit

Permalink
Rollup merge of rust-lang#54687 - scottmcm:more-elision, r=dtolnay
Browse files Browse the repository at this point in the history
Use impl_header_lifetime_elision in libcore

The feature is approved for stabilization, so let's use it to remove about 300 `'a`s.

Tracking issue for the feature: rust-lang#15872
  • Loading branch information
pietroalbini authored Oct 2, 2018
2 parents a1ee000 + d4840da commit 7bec3e8
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 151 deletions.
6 changes: 3 additions & 3 deletions src/libcore/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ impl<T: ?Sized> BorrowMut<T> for T {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Borrow<T> for &'a T {
impl<T: ?Sized> Borrow<T> for &T {
fn borrow(&self) -> &T { &**self }
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Borrow<T> for &'a mut T {
impl<T: ?Sized> Borrow<T> for &mut T {
fn borrow(&self) -> &T { &**self }
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> BorrowMut<T> for &'a mut T {
impl<T: ?Sized> BorrowMut<T> for &mut T {
fn borrow_mut(&mut self) -> &mut T { &mut **self }
}
18 changes: 9 additions & 9 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ impl<'b> BorrowRef<'b> {
}
}

impl<'b> Drop for BorrowRef<'b> {
impl Drop for BorrowRef<'_> {
#[inline]
fn drop(&mut self) {
let borrow = self.borrow.get();
Expand All @@ -1101,9 +1101,9 @@ impl<'b> Drop for BorrowRef<'b> {
}
}

impl<'b> Clone for BorrowRef<'b> {
impl Clone for BorrowRef<'_> {
#[inline]
fn clone(&self) -> BorrowRef<'b> {
fn clone(&self) -> Self {
// Since this Ref exists, we know the borrow flag
// is a reading borrow.
let borrow = self.borrow.get();
Expand All @@ -1127,7 +1127,7 @@ pub struct Ref<'b, T: ?Sized + 'b> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T: ?Sized> Deref for Ref<'b, T> {
impl<T: ?Sized> Deref for Ref<'_, T> {
type Target = T;

#[inline]
Expand Down Expand Up @@ -1219,7 +1219,7 @@ impl<'b, T: ?Sized> Ref<'b, T> {
impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Ref<'b, U>> for Ref<'b, T> {}

#[stable(feature = "std_guard_impls", since = "1.20.0")]
impl<'a, T: ?Sized + fmt::Display> fmt::Display for Ref<'a, T> {
impl<T: ?Sized + fmt::Display> fmt::Display for Ref<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.value.fmt(f)
}
Expand Down Expand Up @@ -1305,7 +1305,7 @@ struct BorrowRefMut<'b> {
borrow: &'b Cell<BorrowFlag>,
}

impl<'b> Drop for BorrowRefMut<'b> {
impl Drop for BorrowRefMut<'_> {
#[inline]
fn drop(&mut self) {
let borrow = self.borrow.get();
Expand Down Expand Up @@ -1356,7 +1356,7 @@ pub struct RefMut<'b, T: ?Sized + 'b> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T: ?Sized> Deref for RefMut<'b, T> {
impl<T: ?Sized> Deref for RefMut<'_, T> {
type Target = T;

#[inline]
Expand All @@ -1366,7 +1366,7 @@ impl<'b, T: ?Sized> Deref for RefMut<'b, T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
impl<T: ?Sized> DerefMut for RefMut<'_, T> {
#[inline]
fn deref_mut(&mut self) -> &mut T {
self.value
Expand All @@ -1377,7 +1377,7 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<RefMut<'b, U>> for RefMut<'b, T> {}

#[stable(feature = "std_guard_impls", since = "1.20.0")]
impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.value.fmt(f)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod impls {

// Shared references can be cloned, but mutable references *cannot*!
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Clone for &'a T {
impl<T: ?Sized> Clone for &T {
#[inline]
fn clone(&self) -> Self {
*self
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,12 @@ mod impls {
fn gt(&self, other: & &'b B) -> bool { PartialOrd::gt(*self, *other) }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Ord for &'a A where A: Ord {
impl<A: ?Sized> Ord for &A where A: Ord {
#[inline]
fn cmp(&self, other: & &'a A) -> Ordering { Ord::cmp(*self, *other) }
fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(*self, *other) }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Eq for &'a A where A: Eq {}
impl<A: ?Sized> Eq for &A where A: Eq {}

// &mut pointers

Expand All @@ -1065,12 +1065,12 @@ mod impls {
fn gt(&self, other: &&'b mut B) -> bool { PartialOrd::gt(*self, *other) }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Ord for &'a mut A where A: Ord {
impl<A: ?Sized> Ord for &mut A where A: Ord {
#[inline]
fn cmp(&self, other: &&'a mut A) -> Ordering { Ord::cmp(*self, *other) }
fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(*self, *other) }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Eq for &'a mut A where A: Eq {}
impl<A: ?Sized> Eq for &mut A where A: Eq {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a A where A: PartialEq<B> {
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub trait TryFrom<T>: Sized {

// As lifts over &
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T where T: AsRef<U>
impl<T: ?Sized, U: ?Sized> AsRef<U> for &T where T: AsRef<U>
{
fn as_ref(&self) -> &U {
<T as AsRef<U>>::as_ref(*self)
Expand All @@ -416,7 +416,7 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T where T: AsRef<U>

// As lifts over &mut
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U>
impl<T: ?Sized, U: ?Sized> AsRef<U> for &mut T where T: AsRef<U>
{
fn as_ref(&self) -> &U {
<T as AsRef<U>>::as_ref(*self)
Expand All @@ -433,7 +433,7 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U>

// AsMut lifts over &mut
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U>
impl<T: ?Sized, U: ?Sized> AsMut<U> for &mut T where T: AsMut<U>
{
fn as_mut(&mut self) -> &mut U {
(*self).as_mut()
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'a> PadAdapter<'a> {
}
}

impl<'a> fmt::Write for PadAdapter<'a> {
impl fmt::Write for PadAdapter<'_> {
fn write_str(&mut self, mut s: &str) -> fmt::Result {
while !s.is_empty() {
if self.on_newline {
Expand Down
26 changes: 13 additions & 13 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub trait Write {
// requiring a `Sized` bound.
struct Adapter<'a,T: ?Sized +'a>(&'a mut T);

impl<'a, T: ?Sized> Write for Adapter<'a, T>
impl<T: ?Sized> Write for Adapter<'_, T>
where T: Write
{
fn write_str(&mut self, s: &str) -> Result {
Expand All @@ -229,7 +229,7 @@ pub trait Write {
}

#[stable(feature = "fmt_write_blanket_impl", since = "1.4.0")]
impl<'a, W: Write + ?Sized> Write for &'a mut W {
impl<W: Write + ?Sized> Write for &mut W {
fn write_str(&mut self, s: &str) -> Result {
(**self).write_str(s)
}
Expand Down Expand Up @@ -291,8 +291,8 @@ pub struct ArgumentV1<'a> {

#[unstable(feature = "fmt_internals", reason = "internal to format_args!",
issue = "0")]
impl<'a> Clone for ArgumentV1<'a> {
fn clone(&self) -> ArgumentV1<'a> {
impl Clone for ArgumentV1<'_> {
fn clone(&self) -> Self {
*self
}
}
Expand Down Expand Up @@ -436,14 +436,14 @@ pub struct Arguments<'a> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Debug for Arguments<'a> {
impl Debug for Arguments<'_> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
Display::fmt(self, fmt)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Display for Arguments<'a> {
impl Display for Arguments<'_> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
write(fmt.buf, *self)
}
Expand Down Expand Up @@ -1884,7 +1884,7 @@ impl<'a> Formatter<'a> {
}

#[stable(since = "1.2.0", feature = "formatter_write")]
impl<'a> Write for Formatter<'a> {
impl Write for Formatter<'_> {
fn write_str(&mut self, s: &str) -> Result {
self.buf.write_str(s)
}
Expand All @@ -1911,11 +1911,11 @@ macro_rules! fmt_refs {
($($tr:ident),*) => {
$(
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + $tr> $tr for &'a T {
impl<T: ?Sized + $tr> $tr for &T {
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + $tr> $tr for &'a mut T {
impl<T: ?Sized + $tr> $tr for &mut T {
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
}
)*
Expand Down Expand Up @@ -2039,14 +2039,14 @@ impl<T: ?Sized> Pointer for *mut T {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Pointer for &'a T {
impl<T: ?Sized> Pointer for &T {
fn fmt(&self, f: &mut Formatter) -> Result {
Pointer::fmt(&(*self as *const T), f)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Pointer for &'a mut T {
impl<T: ?Sized> Pointer for &mut T {
fn fmt(&self, f: &mut Formatter) -> Result {
Pointer::fmt(&(&**self as *const T), f)
}
Expand Down Expand Up @@ -2153,14 +2153,14 @@ impl<T: ?Sized + Debug> Debug for RefCell<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T: ?Sized + Debug> Debug for Ref<'b, T> {
impl<T: ?Sized + Debug> Debug for Ref<'_, T> {
fn fmt(&self, f: &mut Formatter) -> Result {
Debug::fmt(&**self, f)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T: ?Sized + Debug> Debug for RefMut<'b, T> {
impl<T: ?Sized + Debug> Debug for RefMut<'_, T> {
fn fmt(&self, f: &mut Formatter) -> Result {
Debug::fmt(&*(self.deref()), f)
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ pub trait Hasher {
}

#[stable(feature = "indirect_hasher_impl", since = "1.22.0")]
impl<'a, H: Hasher + ?Sized> Hasher for &'a mut H {
impl<H: Hasher + ?Sized> Hasher for &mut H {
fn finish(&self) -> u64 {
(**self).finish()
}
Expand Down Expand Up @@ -669,14 +669,14 @@ mod impls {


#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + Hash> Hash for &'a T {
impl<T: ?Sized + Hash> Hash for &T {
fn hash<H: Hasher>(&self, state: &mut H) {
(**self).hash(state);
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + Hash> Hash for &'a mut T {
impl<T: ?Sized + Hash> Hash for &mut T {
fn hash<H: Hasher>(&self, state: &mut H) {
(**self).hash(state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,7 @@ fn select_fold1<I, B, FProj, FCmp>(mut it: I,
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
impl<I: Iterator + ?Sized> Iterator for &mut I {
type Item = I::Item;
fn next(&mut self) -> Option<I::Item> { (**self).next() }
fn size_hint(&self) -> (usize, Option<usize>) { (**self).size_hint() }
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ pub trait ExactSizeIterator: Iterator {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, I: ExactSizeIterator + ?Sized> ExactSizeIterator for &'a mut I {
impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for &mut I {
fn len(&self) -> usize {
(**self).len()
}
Expand Down Expand Up @@ -974,7 +974,7 @@ impl<T, U, E> Product<Result<U, E>> for Result<T, E>
pub trait FusedIterator: Iterator {}

#[stable(feature = "fused", since = "1.26.0")]
impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {}
impl<I: FusedIterator + ?Sized> FusedIterator for &mut I {}

/// An iterator that reports an accurate length using size_hint.
///
Expand All @@ -999,4 +999,4 @@ impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {}
pub unsafe trait TrustedLen : Iterator {}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, I: TrustedLen + ?Sized> TrustedLen for &'a mut I {}
unsafe impl<I: TrustedLen + ?Sized> TrustedLen for &mut I {}
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#![feature(doc_spotlight)]
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(impl_header_lifetime_elision)]
#![feature(intrinsics)]
#![feature(lang_items)]
#![feature(link_llvm_intrinsics)]
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ impls! { PhantomData }

mod impls {
#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<'a, T: Sync + ?Sized> Send for &'a T {}
unsafe impl<T: Sync + ?Sized> Send for &T {}
#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<'a, T: Send + ?Sized> Send for &'a mut T {}
unsafe impl<T: Send + ?Sized> Send for &mut T {}
}

/// Compiler-internal trait used to determine whether a type contains
Expand All @@ -600,8 +600,8 @@ impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
unsafe impl<T: ?Sized> Freeze for *const T {}
unsafe impl<T: ?Sized> Freeze for *mut T {}
unsafe impl<'a, T: ?Sized> Freeze for &'a T {}
unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
unsafe impl<T: ?Sized> Freeze for &T {}
unsafe impl<T: ?Sized> Freeze for &mut T {}

/// Types which can be safely moved after being pinned.
///
Expand Down Expand Up @@ -689,6 +689,6 @@ mod copy_impls {

// Shared references can be copied, but mutable references *cannot*!
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Copy for &'a T {}
impl<T: ?Sized> Copy for &T {}

}
6 changes: 3 additions & 3 deletions src/libcore/ops/deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ pub trait Deref {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Deref for &'a T {
impl<T: ?Sized> Deref for &T {
type Target = T;

fn deref(&self) -> &T { *self }
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Deref for &'a mut T {
impl<T: ?Sized> Deref for &mut T {
type Target = T;

fn deref(&self) -> &T { *self }
Expand Down Expand Up @@ -174,6 +174,6 @@ pub trait DerefMut: Deref {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> DerefMut for &'a mut T {
impl<T: ?Sized> DerefMut for &mut T {
fn deref_mut(&mut self) -> &mut T { *self }
}
Loading

0 comments on commit 7bec3e8

Please sign in to comment.