Skip to content

Commit 4f4f4a4

Browse files
committed
Auto merge of #58081 - Centril:liballoc-2018, r=oli-obk
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.
2 parents e858c26 + 2396780 commit 4f4f4a4

34 files changed

+360
-393
lines changed

Diff for: src/liballoc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ name = "alloc"
44
version = "0.0.0"
55
autotests = false
66
autobenches = false
7+
edition = "2018"
78

89
[lib]
910
name = "alloc"

Diff for: src/liballoc/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ pub fn handle_alloc_error(layout: Layout) -> ! {
227227
#[cfg(test)]
228228
mod tests {
229229
extern crate test;
230-
use self::test::Bencher;
231-
use boxed::Box;
232-
use alloc::{Global, Alloc, Layout, handle_alloc_error};
230+
use test::Bencher;
231+
use crate::boxed::Box;
232+
use crate::alloc::{Global, Alloc, Layout, handle_alloc_error};
233233

234234
#[test]
235235
fn allocate_zeroed() {

Diff for: src/liballoc/benches/btree/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::iter::Iterator;
22
use std::vec::Vec;
33
use std::collections::BTreeMap;
4+
45
use rand::{Rng, seq::SliceRandom, thread_rng};
56
use test::{Bencher, black_box};
67

Diff for: src/liballoc/benches/slice.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use rand::{thread_rng};
2-
use std::mem;
3-
use std::ptr;
1+
use std::{mem, ptr};
42

5-
use rand::{Rng, SeedableRng};
3+
use rand::{thread_rng, Rng, SeedableRng};
64
use rand::distributions::{Standard, Alphanumeric};
75
use rand_xorshift::XorShiftRng;
86
use test::{Bencher, black_box};

Diff for: src/liballoc/borrow.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use core::cmp::Ordering;
66
use core::hash::{Hash, Hasher};
77
use core::ops::{Add, AddAssign, Deref};
88

9-
use fmt;
10-
use string::String;
11-
12-
use self::Cow::*;
13-
149
#[stable(feature = "rust1", since = "1.0.0")]
1510
pub use core::borrow::{Borrow, BorrowMut};
1611

12+
use crate::fmt;
13+
use crate::string::String;
14+
15+
use Cow::*;
16+
1717
#[stable(feature = "rust1", since = "1.0.0")]
1818
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
1919
where B: ToOwned,
@@ -182,9 +182,7 @@ pub enum Cow<'a, B: ?Sized + 'a>
182182
}
183183

184184
#[stable(feature = "rust1", since = "1.0.0")]
185-
impl<'a, B: ?Sized> Clone for Cow<'a, B>
186-
where B: ToOwned
187-
{
185+
impl<'a, B: ?Sized + ToOwned> Clone for Cow<'a, B> {
188186
fn clone(&self) -> Cow<'a, B> {
189187
match *self {
190188
Borrowed(b) => Borrowed(b),
@@ -207,9 +205,7 @@ impl<'a, B: ?Sized> Clone for Cow<'a, B>
207205
}
208206
}
209207

210-
impl<'a, B: ?Sized> Cow<'a, B>
211-
where B: ToOwned
212-
{
208+
impl<B: ?Sized + ToOwned> Cow<'_, B> {
213209
/// Acquires a mutable reference to the owned form of the data.
214210
///
215211
/// Clones the data if it is not already owned.
@@ -285,9 +281,7 @@ impl<'a, B: ?Sized> Cow<'a, B>
285281
}
286282

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

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

301295
#[stable(feature = "rust1", since = "1.0.0")]
302-
impl<'a, B: ?Sized> Eq for Cow<'a, B> where B: Eq + ToOwned {}
296+
impl<B: ?Sized> Eq for Cow<'_, B> where B: Eq + ToOwned {}
303297

304298
#[stable(feature = "rust1", since = "1.0.0")]
305299
impl<'a, B: ?Sized> Ord for Cow<'a, B>
@@ -333,11 +327,11 @@ impl<'a, B: ?Sized> PartialOrd for Cow<'a, B>
333327
}
334328

335329
#[stable(feature = "rust1", since = "1.0.0")]
336-
impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
330+
impl<B: ?Sized> fmt::Debug for Cow<'_, B>
337331
where B: fmt::Debug + ToOwned,
338332
<B as ToOwned>::Owned: fmt::Debug
339333
{
340-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
334+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
341335
match *self {
342336
Borrowed(ref b) => fmt::Debug::fmt(b, f),
343337
Owned(ref o) => fmt::Debug::fmt(o, f),
@@ -346,11 +340,11 @@ impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
346340
}
347341

348342
#[stable(feature = "rust1", since = "1.0.0")]
349-
impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
343+
impl<B: ?Sized> fmt::Display for Cow<'_, B>
350344
where B: fmt::Display + ToOwned,
351345
<B as ToOwned>::Owned: fmt::Display
352346
{
353-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
347+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
354348
match *self {
355349
Borrowed(ref b) => fmt::Display::fmt(b, f),
356350
Owned(ref o) => fmt::Display::fmt(o, f),
@@ -380,7 +374,7 @@ impl<'a, B: ?Sized> Hash for Cow<'a, B>
380374
}
381375

382376
#[stable(feature = "rust1", since = "1.0.0")]
383-
impl<'a, T: ?Sized + ToOwned> AsRef<T> for Cow<'a, T> {
377+
impl<T: ?Sized + ToOwned> AsRef<T> for Cow<'_, T> {
384378
fn as_ref(&self) -> &T {
385379
self
386380
}

Diff for: src/liballoc/boxed.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ use core::ops::{
7373
use core::ptr::{self, NonNull, Unique};
7474
use core::task::{LocalWaker, Poll};
7575

76-
use vec::Vec;
77-
use raw_vec::RawVec;
78-
use str::from_boxed_utf8_unchecked;
76+
use crate::vec::Vec;
77+
use crate::raw_vec::RawVec;
78+
use crate::str::from_boxed_utf8_unchecked;
7979

8080
/// A pointer type for heap allocation.
8181
///
@@ -603,21 +603,21 @@ impl Box<dyn Any + Send> {
603603

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

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

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

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

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

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

753753
extern "rust-call" fn call_once(self, args: A) -> R {

Diff for: src/liballoc/collections/binary_heap.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ use core::mem::{swap, size_of, ManuallyDrop};
151151
use core::ptr;
152152
use core::fmt;
153153

154-
use slice;
155-
use vec::{self, Vec};
154+
use crate::slice;
155+
use crate::vec::{self, Vec};
156156

157157
use super::SpecExtend;
158158

@@ -227,16 +227,16 @@ pub struct PeekMut<'a, T: 'a + Ord> {
227227
}
228228

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

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

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

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

292292
#[stable(feature = "binaryheap_debug", since = "1.4.0")]
293293
impl<T: fmt::Debug + Ord> fmt::Debug for BinaryHeap<T> {
294-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
294+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
295295
f.debug_list().entries(self.iter()).finish()
296296
}
297297
}
@@ -349,7 +349,7 @@ impl<T: Ord> BinaryHeap<T> {
349349
/// }
350350
/// ```
351351
#[stable(feature = "rust1", since = "1.0.0")]
352-
pub fn iter(&self) -> Iter<T> {
352+
pub fn iter(&self) -> Iter<'_, T> {
353353
Iter { iter: self.data.iter() }
354354
}
355355

@@ -400,7 +400,7 @@ impl<T: Ord> BinaryHeap<T> {
400400
/// assert_eq!(heap.peek(), Some(&2));
401401
/// ```
402402
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
403-
pub fn peek_mut(&mut self) -> Option<PeekMut<T>> {
403+
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
404404
if self.is_empty() {
405405
None
406406
} else {
@@ -761,7 +761,7 @@ impl<T: Ord> BinaryHeap<T> {
761761
/// ```
762762
#[inline]
763763
#[stable(feature = "drain", since = "1.6.0")]
764-
pub fn drain(&mut self) -> Drain<T> {
764+
pub fn drain(&mut self) -> Drain<'_, T> {
765765
Drain { iter: self.data.drain(..) }
766766
}
767767

@@ -908,7 +908,7 @@ impl<'a, T> Hole<'a, T> {
908908
}
909909
}
910910

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)