Skip to content

Commit

Permalink
liballoc: refactor & fix some imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 2, 2019
1 parent e6e2792 commit 7693e3e
Show file tree
Hide file tree
Showing 35 changed files with 424 additions and 342 deletions.
14 changes: 9 additions & 5 deletions src/liballoc/alloc.rs
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 @@ -228,8 +230,10 @@ pub fn handle_alloc_error(layout: Layout) -> ! {
mod tests {
extern crate test;
use self::test::Bencher;
use boxed::Box;
use alloc::{Global, Alloc, Layout, handle_alloc_error};
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
@@ -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
@@ -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
11 changes: 6 additions & 5 deletions src/liballoc/borrow.rs
Expand Up @@ -2,12 +2,13 @@

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

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

use crate::fmt;
use crate::string::String;
use crate::{fmt, string::String};

use self::Cow::*;

Expand Down
38 changes: 20 additions & 18 deletions src/liballoc/boxed.rs
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 crate::vec::Vec;
use crate::raw_vec::RawVec;
use crate::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
14 changes: 8 additions & 6 deletions src/liballoc/boxed_test.rs
@@ -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
20 changes: 12 additions & 8 deletions src/liballoc/collections/binary_heap.rs
Expand Up @@ -145,14 +145,18 @@
#![allow(missing_docs)]
#![stable(feature = "rust1", since = "1.0.0")]

use core::ops::{Deref, DerefMut};
use core::iter::{FromIterator, FusedIterator};
use core::mem::{swap, size_of, ManuallyDrop};
use core::ptr;
use core::fmt;

use crate::slice;
use crate::vec::{self, Vec};
use core::{
ops::{Deref, DerefMut},
iter::{FromIterator, FusedIterator},
mem::{swap, size_of, ManuallyDrop},
ptr,
fmt,
};

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

use super::SpecExtend;

Expand Down
33 changes: 17 additions & 16 deletions src/liballoc/collections/btree/map.rs
@@ -1,23 +1,24 @@
use core::cmp::Ordering;
use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::iter::{FromIterator, Peekable, FusedIterator};
use core::marker::PhantomData;
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::Index;
use core::ops::RangeBounds;
use core::{fmt, intrinsics, mem, ptr};
use core::{
cmp::Ordering,
fmt::Debug,
hash::{Hash, Hasher},
iter::{FromIterator, Peekable, FusedIterator},
marker::PhantomData,
ops::{
Bound::{Excluded, Included, Unbounded},
Index, RangeBounds,
},
fmt, intrinsics, mem, ptr,
};

use crate::borrow::Borrow;

use super::node::{self, Handle, NodeRef, marker};
use super::search;
use super::{
node::{self, Handle, NodeRef, marker, InsertResult::*, ForceResult::*},
search::{self, SearchResult::*},
};

use super::node::InsertResult::*;
use super::node::ForceResult::*;
use super::search::SearchResult::*;
use self::UnderflowResult::*;
use self::Entry::*;
use self::{UnderflowResult::*, Entry::*};

/// A map based on a B-Tree.
///
Expand Down
16 changes: 10 additions & 6 deletions src/liballoc/collections/btree/node.rs
Expand Up @@ -31,13 +31,17 @@
// - A node of length `n` has `n` keys, `n` values, and (in an internal node) `n + 1` edges.
// This implies that even an empty internal node has at least one edge.

use core::marker::PhantomData;
use core::mem::{self, MaybeUninit};
use core::ptr::{self, Unique, NonNull};
use core::slice;
use core::{
marker::PhantomData,
mem::{self, MaybeUninit},
ptr::{self, Unique, NonNull},
slice,
};

use crate::alloc::{Global, Alloc, Layout};
use crate::boxed::Box;
use crate::{
alloc::{Global, Alloc, Layout},
boxed::Box,
};

const B: usize = 6;
pub const MIN_LEN: usize = B - 1;
Expand Down
3 changes: 1 addition & 2 deletions src/liballoc/collections/btree/search.rs
Expand Up @@ -2,9 +2,8 @@ use core::cmp::Ordering;

use crate::borrow::Borrow;

use super::node::{Handle, NodeRef, marker};
use super::node::{Handle, NodeRef, marker, ForceResult::*};

use super::node::ForceResult::*;
use self::SearchResult::*;

pub enum SearchResult<BorrowType, K, V, FoundType, GoDownType> {
Expand Down
23 changes: 14 additions & 9 deletions src/liballoc/collections/btree/set.rs
@@ -1,15 +1,20 @@
// This is pretty much entirely stolen from TreeSet, since BTreeMap has an identical interface
// to TreeMap

use core::cmp::Ordering::{self, Less, Greater, Equal};
use core::cmp::{min, max};
use core::fmt::Debug;
use core::fmt;
use core::iter::{Peekable, FromIterator, FusedIterator};
use core::ops::{BitOr, BitAnd, BitXor, Sub, RangeBounds};

use crate::borrow::Borrow;
use crate::collections::btree_map::{self, BTreeMap, Keys};
use core::{
cmp::{
Ordering::{self, Less, Greater, Equal},
min, max,
},
fmt::{self, Debug},
iter::{Peekable, FromIterator, FusedIterator},
ops::{BitOr, BitAnd, BitXor, Sub, RangeBounds},
};

use crate::{
borrow::Borrow,
collections::btree_map::{self, BTreeMap, Keys},
};
use super::Recover;

// FIXME(conventions): implement bounded iterators
Expand Down
21 changes: 10 additions & 11 deletions src/liballoc/collections/linked_list.rs
Expand Up @@ -12,13 +12,15 @@

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

use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hasher, Hash};
use core::iter::{FromIterator, FusedIterator};
use core::marker::PhantomData;
use core::mem;
use core::ptr::NonNull;
use core::{
cmp::Ordering,
fmt,
hash::{Hasher, Hash},
iter::{FromIterator, FusedIterator},
marker::PhantomData,
mem,
ptr::NonNull,
};

use crate::boxed::Box;
use super::SpecExtend;
Expand Down Expand Up @@ -1213,11 +1215,8 @@ unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {}

#[cfg(test)]
mod tests {
use std::thread;
use std::vec::Vec;

use std::{thread, vec::Vec};
use rand::{thread_rng, RngCore};

use super::{LinkedList, Node};

#[cfg(test)]
Expand Down
43 changes: 23 additions & 20 deletions src/liballoc/collections/vec_deque.rs
Expand Up @@ -7,22 +7,25 @@

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

use core::cmp::Ordering;
use core::fmt;
use core::iter::{repeat_with, FromIterator, FusedIterator};
use core::mem;
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::{Index, IndexMut, RangeBounds, Try};
use core::ptr;
use core::ptr::NonNull;
use core::slice;

use core::hash::{Hash, Hasher};
use core::cmp;

use crate::collections::CollectionAllocErr;
use crate::raw_vec::RawVec;
use crate::vec::Vec;
use core::{
cmp::{self, Ordering},
fmt,
iter::{repeat_with, FromIterator, FusedIterator},
mem,
ops::{
Bound::{Excluded, Included, Unbounded},
Index, IndexMut, RangeBounds, Try,
},
ptr::{self, NonNull},
slice,
hash::{Hash, Hasher},
};

use crate::{
collections::CollectionAllocErr,
raw_vec::RawVec,
vec::Vec,
};

const INITIAL_CAPACITY: usize = 7; // 2^3 - 1
const MINIMUM_CAPACITY: usize = 1; // 2 - 1
Expand Down Expand Up @@ -2758,7 +2761,7 @@ impl<T> From<VecDeque<T>> for Vec<T> {

#[cfg(test)]
mod tests {
use test;
use ::test;

use super::VecDeque;

Expand Down Expand Up @@ -3036,7 +3039,7 @@ mod tests {

#[test]
fn test_from_vec() {
use vec::Vec;
use crate::vec::Vec;
for cap in 0..35 {
for len in 0..=cap {
let mut vec = Vec::with_capacity(cap);
Expand All @@ -3052,7 +3055,7 @@ mod tests {

#[test]
fn test_vec_from_vecdeque() {
use vec::Vec;
use crate::vec::Vec;

fn create_vec_and_test_convert(cap: usize, offset: usize, len: usize) {
let mut vd = VecDeque::with_capacity(cap);
Expand Down Expand Up @@ -3114,7 +3117,7 @@ mod tests {

#[test]
fn issue_53529() {
use boxed::Box;
use crate::boxed::Box;

let mut dst = VecDeque::new();
dst.push_front(Box::new(1));
Expand Down

0 comments on commit 7693e3e

Please sign in to comment.