Skip to content
Merged
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
16 changes: 10 additions & 6 deletions src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#![stable(feature = "alloc_module", since = "1.28.0")]

use core::intrinsics::{min_align_of_val, size_of_val};
use core::ptr::{NonNull, Unique};
use core::usize;
use core::{
intrinsics::{min_align_of_val, size_of_val},
ptr::{NonNull, Unique},
usize,
};

#[stable(feature = "alloc_module", since = "1.28.0")]
#[doc(inline)]
Expand Down Expand Up @@ -227,9 +229,11 @@ 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,
alloc::{Global, Alloc, Layout, handle_alloc_error},
};

#[test]
fn allocate_zeroed() {
Expand Down
8 changes: 5 additions & 3 deletions src/liballoc/benches/btree/map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::iter::Iterator;
use std::vec::Vec;
use std::collections::BTreeMap;
use std::{
iter::Iterator,
vec::Vec,
collections::BTreeMap,
};
use rand::{Rng, seq::SliceRandom, thread_rng};
use test::{Bencher, black_box};

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

use rand::{Rng, SeedableRng};
use rand::distributions::{Standard, Alphanumeric};
use std::{mem, ptr};
use rand::{
thread_rng, Rng, SeedableRng,
distributions::{Standard, Alphanumeric},
};
use rand_xorshift::XorShiftRng;
use test::{Bencher, black_box};

Expand Down
41 changes: 18 additions & 23 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::cmp::Ordering;
use core::hash::{Hash, Hasher};
use core::ops::{Add, AddAssign, Deref};

use fmt;
use string::String;

use self::Cow::*;
use core::{
cmp::Ordering,
hash::{Hash, Hasher},
ops::{Add, AddAssign, Deref},
};

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

use crate::{fmt, 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 +183,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 +206,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 +282,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 +294,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 +328,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 +341,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 +375,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
48 changes: 25 additions & 23 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,28 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::any::Any;
use core::borrow;
use core::cmp::Ordering;
use core::convert::From;
use core::fmt;
use core::future::Future;
use core::hash::{Hash, Hasher};
use core::iter::{Iterator, FromIterator, FusedIterator};
use core::marker::{Unpin, Unsize};
use core::mem;
use core::pin::Pin;
use core::ops::{
CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Receiver, Generator, GeneratorState
use core::{
any::Any,
borrow,
cmp::Ordering,
convert::From,
fmt,
future::Future,
hash::{Hash, Hasher},
iter::{Iterator, FromIterator, FusedIterator},
marker::{Unpin, Unsize},
mem,
pin::Pin,
ops::{CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Receiver, Generator, GeneratorState},
ptr::{self, NonNull, Unique},
task::{LocalWaker, Poll},
};
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,
raw_vec::RawVec,
str::from_boxed_utf8_unchecked,
};

/// A pointer type for heap allocation.
///
Expand Down Expand Up @@ -603,21 +605,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 +739,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 +749,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
14 changes: 8 additions & 6 deletions src/liballoc/boxed_test.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Test for `boxed` mod.

use core::any::Any;
use core::ops::Deref;
use core::result::Result::{Err, Ok};
use core::clone::Clone;
use core::f64;
use core::i64;
use core::{
any::Any,
ops::Deref,
result::Result::{Err, Ok},
clone::Clone,
f64,
i64,
};

use std::boxed::Box;

Expand Down
Loading