Skip to content

Commit

Permalink
Auto merge of #58081 - Centril:liballoc-2018, r=oli-obk
Browse files Browse the repository at this point in the history
Transition liballoc to Rust 2018

This transitions liballoc to Rust 2018 edition and applies relevant idiom lints.
I also did a small bit of drive-by cleanup along the way.

r? @oli-obk

I started with liballoc since it seemed easiest. In particular, adding `edition = "2018"` to libcore gave me way too many errors due to stdsimd. Ideally we should be able to continue this crate-by-crate until all crates use 2018.
  • Loading branch information
bors committed Feb 3, 2019
2 parents e858c26 + 2396780 commit 4f4f4a4
Show file tree
Hide file tree
Showing 34 changed files with 360 additions and 393 deletions.
1 change: 1 addition & 0 deletions src/liballoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name = "alloc"
version = "0.0.0"
autotests = false
autobenches = false
edition = "2018"

[lib]
name = "alloc"
Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ pub fn handle_alloc_error(layout: Layout) -> ! {
#[cfg(test)]
mod tests {
extern crate test;
use self::test::Bencher;
use boxed::Box;
use alloc::{Global, Alloc, Layout, handle_alloc_error};
use test::Bencher;
use crate::boxed::Box;
use crate::alloc::{Global, Alloc, Layout, handle_alloc_error};

#[test]
fn allocate_zeroed() {
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/benches/btree/map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::iter::Iterator;
use std::vec::Vec;
use std::collections::BTreeMap;

use rand::{Rng, seq::SliceRandom, thread_rng};
use test::{Bencher, black_box};

Expand Down
6 changes: 2 additions & 4 deletions src/liballoc/benches/slice.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use rand::{thread_rng};
use std::mem;
use std::ptr;
use std::{mem, ptr};

use rand::{Rng, SeedableRng};
use rand::{thread_rng, Rng, SeedableRng};
use rand::distributions::{Standard, Alphanumeric};
use rand_xorshift::XorShiftRng;
use test::{Bencher, black_box};
Expand Down
34 changes: 14 additions & 20 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use core::cmp::Ordering;
use core::hash::{Hash, Hasher};
use core::ops::{Add, AddAssign, Deref};

use fmt;
use string::String;

use self::Cow::*;

#[stable(feature = "rust1", since = "1.0.0")]
pub use core::borrow::{Borrow, BorrowMut};

use crate::fmt;
use crate::string::String;

use Cow::*;

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
where B: ToOwned,
Expand Down Expand Up @@ -182,9 +182,7 @@ pub enum Cow<'a, B: ?Sized + 'a>
}

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

impl<'a, B: ?Sized> Cow<'a, B>
where B: ToOwned
{
impl<B: ?Sized + ToOwned> Cow<'_, B> {
/// Acquires a mutable reference to the owned form of the data.
///
/// Clones the data if it is not already owned.
Expand Down Expand Up @@ -285,9 +281,7 @@ impl<'a, B: ?Sized> Cow<'a, B>
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Deref for Cow<'a, B>
where B: ToOwned
{
impl<B: ?Sized + ToOwned> Deref for Cow<'_, B> {
type Target = B;

fn deref(&self) -> &B {
Expand All @@ -299,7 +293,7 @@ impl<'a, B: ?Sized> Deref for Cow<'a, B>
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Eq for Cow<'a, B> where B: Eq + ToOwned {}
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>
Expand Down Expand Up @@ -333,11 +327,11 @@ impl<'a, B: ?Sized> PartialOrd for Cow<'a, B>
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
impl<B: ?Sized> fmt::Debug for Cow<'_, B>
where B: fmt::Debug + ToOwned,
<B as ToOwned>::Owned: fmt::Debug
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Borrowed(ref b) => fmt::Debug::fmt(b, f),
Owned(ref o) => fmt::Debug::fmt(o, f),
Expand All @@ -346,11 +340,11 @@ impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
impl<B: ?Sized> fmt::Display for Cow<'_, B>
where B: fmt::Display + ToOwned,
<B as ToOwned>::Owned: fmt::Display
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Borrowed(ref b) => fmt::Display::fmt(b, f),
Owned(ref o) => fmt::Display::fmt(o, f),
Expand Down Expand Up @@ -380,7 +374,7 @@ impl<'a, B: ?Sized> Hash for Cow<'a, B>
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + ToOwned> AsRef<T> for Cow<'a, T> {
impl<T: ?Sized + ToOwned> AsRef<T> for Cow<'_, T> {
fn as_ref(&self) -> &T {
self
}
Expand Down
16 changes: 8 additions & 8 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ use core::ops::{
use core::ptr::{self, NonNull, Unique};
use core::task::{LocalWaker, Poll};

use vec::Vec;
use raw_vec::RawVec;
use str::from_boxed_utf8_unchecked;
use crate::vec::Vec;
use crate::raw_vec::RawVec;
use crate::str::from_boxed_utf8_unchecked;

/// A pointer type for heap allocation.
///
Expand Down Expand Up @@ -603,21 +603,21 @@ impl Box<dyn Any + Send> {

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

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

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> fmt::Pointer for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// It's not possible to extract the inner Uniq directly from the Box,
// instead we cast it to a *const which aliases the Unique
let ptr: *const T = &**self;
Expand Down Expand Up @@ -737,7 +737,7 @@ impl<A, F> FnBox<A> for F

#[unstable(feature = "fnbox",
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + 'a> {
impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + '_> {
type Output = R;

extern "rust-call" fn call_once(self, args: A) -> R {
Expand All @@ -747,7 +747,7 @@ impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + 'a> {

#[unstable(feature = "fnbox",
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + 'a> {
impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + '_> {
type Output = R;

extern "rust-call" fn call_once(self, args: A) -> R {
Expand Down
42 changes: 21 additions & 21 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ use core::mem::{swap, size_of, ManuallyDrop};
use core::ptr;
use core::fmt;

use slice;
use vec::{self, Vec};
use crate::slice;
use crate::vec::{self, Vec};

use super::SpecExtend;

Expand Down Expand Up @@ -227,16 +227,16 @@ pub struct PeekMut<'a, T: 'a + Ord> {
}

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<'a, T: Ord + fmt::Debug> fmt::Debug for PeekMut<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<T: Ord + fmt::Debug> fmt::Debug for PeekMut<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("PeekMut")
.field(&self.heap.data[0])
.finish()
}
}

#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
impl<'a, T: Ord> Drop for PeekMut<'a, T> {
impl<T: Ord> Drop for PeekMut<'_, T> {
fn drop(&mut self) {
if self.sift {
self.heap.sift_down(0);
Expand All @@ -245,15 +245,15 @@ impl<'a, T: Ord> Drop for PeekMut<'a, T> {
}

#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
impl<'a, T: Ord> Deref for PeekMut<'a, T> {
impl<T: Ord> Deref for PeekMut<'_, T> {
type Target = T;
fn deref(&self) -> &T {
&self.heap.data[0]
}
}

#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
impl<'a, T: Ord> DerefMut for PeekMut<'a, T> {
impl<T: Ord> DerefMut for PeekMut<'_, T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.heap.data[0]
}
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<T: Ord> Default for BinaryHeap<T> {

#[stable(feature = "binaryheap_debug", since = "1.4.0")]
impl<T: fmt::Debug + Ord> fmt::Debug for BinaryHeap<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.iter()).finish()
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ impl<T: Ord> BinaryHeap<T> {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
pub fn iter(&self) -> Iter<'_, T> {
Iter { iter: self.data.iter() }
}

Expand Down Expand Up @@ -400,7 +400,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.peek(), Some(&2));
/// ```
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
pub fn peek_mut(&mut self) -> Option<PeekMut<T>> {
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
if self.is_empty() {
None
} else {
Expand Down Expand Up @@ -761,7 +761,7 @@ impl<T: Ord> BinaryHeap<T> {
/// ```
#[inline]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain(&mut self) -> Drain<T> {
pub fn drain(&mut self) -> Drain<'_, T> {
Drain { iter: self.data.drain(..) }
}

Expand Down Expand Up @@ -908,7 +908,7 @@ impl<'a, T> Hole<'a, T> {
}
}

impl<'a, T> Drop for Hole<'a, T> {
impl<T> Drop for Hole<'_, T> {
#[inline]
fn drop(&mut self) {
// fill the hole again
Expand All @@ -932,8 +932,8 @@ pub struct Iter<'a, T: 'a> {
}

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Iter")
.field(&self.iter.as_slice())
.finish()
Expand Down Expand Up @@ -972,14 +972,14 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {
impl<T> ExactSizeIterator for Iter<'_, T> {
fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

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

/// An owning iterator over the elements of a `BinaryHeap`.
///
Expand All @@ -996,7 +996,7 @@ pub struct IntoIter<T> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("IntoIter")
.field(&self.iter.as_slice())
.finish()
Expand Down Expand Up @@ -1050,7 +1050,7 @@ pub struct Drain<'a, T: 'a> {
}

#[stable(feature = "drain", since = "1.6.0")]
impl<'a, T: 'a> Iterator for Drain<'a, T> {
impl<T> Iterator for Drain<'_, T> {
type Item = T;

#[inline]
Expand All @@ -1065,22 +1065,22 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> {
}

#[stable(feature = "drain", since = "1.6.0")]
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
impl<T> DoubleEndedIterator for Drain<'_, T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
self.iter.next_back()
}
}

#[stable(feature = "drain", since = "1.6.0")]
impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {
impl<T> ExactSizeIterator for Drain<'_, T> {
fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

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

#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
impl<T: Ord> From<Vec<T>> for BinaryHeap<T> {
Expand Down
Loading

0 comments on commit 4f4f4a4

Please sign in to comment.