Skip to content

Commit 760b93a

Browse files
committed
Fallout from the libcollections movement
1 parent 6a58537 commit 760b93a

File tree

130 files changed

+331
-340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+331
-340
lines changed

src/doc/tutorial.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,7 @@ illegal to copy and pass by value.
20582058
Generic `type`, `struct`, and `enum` declarations follow the same pattern:
20592059

20602060
~~~~
2061-
extern crate collections;
2062-
type Set<T> = collections::HashMap<T, ()>;
2061+
type Set<T> = std::collections::HashMap<T, ()>;
20632062
20642063
struct Stack<T> {
20652064
elements: Vec<T>

src/libarena/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
html_root_url = "http://doc.rust-lang.org/")]
2929
#![allow(missing_doc)]
3030

31-
extern crate collections;
32-
3331
use std::cell::{Cell, RefCell};
3432
use std::cmp;
3533
use std::intrinsics::{TyDesc, get_tydesc};

src/libcollections/bitv.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use core::ops;
1919
use core::slice;
2020
use core::uint;
2121

22-
use string::String;
2322
use vec::Vec;
2423

2524
#[deriving(Clone)]
@@ -980,26 +979,26 @@ impl<'a> Iterator<uint> for BitPositions<'a> {
980979

981980
#[cfg(test)]
982981
mod tests {
983-
extern crate test;
984-
use self::test::Bencher;
982+
use std::prelude::*;
983+
use std::uint;
984+
use std::rand;
985+
use std::rand::Rng;
986+
use test::Bencher;
985987

986988
use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn,
987989
from_bytes};
988990
use bitv;
989-
990-
use std::uint;
991-
use std::rand;
992-
use std::rand::Rng;
991+
use vec::Vec;
993992

994993
static BENCH_BITS : uint = 1 << 14;
995994

996995
#[test]
997996
fn test_to_str() {
998997
let zerolen = Bitv::new(0u, false);
999-
assert_eq!(zerolen.to_str(), "".to_string());
998+
assert_eq!(zerolen.to_str().as_slice(), "");
1000999

10011000
let eightbits = Bitv::new(8u, false);
1002-
assert_eq!(eightbits.to_str(), "00000000".to_string());
1001+
assert_eq!(eightbits.to_str().as_slice(), "00000000")
10031002
}
10041003

10051004
#[test]
@@ -1022,7 +1021,7 @@ mod tests {
10221021
let mut b = bitv::Bitv::new(2, false);
10231022
b.set(0, true);
10241023
b.set(1, false);
1025-
assert_eq!(b.to_str(), "10".to_string());
1024+
assert_eq!(b.to_str().as_slice(), "10");
10261025
}
10271026

10281027
#[test]
@@ -1333,7 +1332,7 @@ mod tests {
13331332
fn test_from_bytes() {
13341333
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
13351334
let str = format!("{}{}{}", "10110110", "00000000", "11111111");
1336-
assert_eq!(bitv.to_str(), str);
1335+
assert_eq!(bitv.to_str().as_slice(), str.as_slice());
13371336
}
13381337

13391338
#[test]
@@ -1350,8 +1349,8 @@ mod tests {
13501349

13511350
#[test]
13521351
fn test_from_bools() {
1353-
assert!(from_bools([true, false, true, true]).to_str() ==
1354-
"1011".to_string());
1352+
assert!(from_bools([true, false, true, true]).to_str().as_slice() ==
1353+
"1011");
13551354
}
13561355

13571356
#[test]

src/libcollections/btree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ impl<K: fmt::Show + Ord, V: fmt::Show> fmt::Show for BranchElt<K, V> {
777777

778778
#[cfg(test)]
779779
mod test_btree {
780+
use std::prelude::*;
780781

781782
use super::{BTree, Node, LeafElt};
782783

src/libcollections/deque.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ pub trait Deque<T> : Mutable {
4141

4242
#[cfg(test)]
4343
pub mod bench {
44-
extern crate test;
45-
use self::test::Bencher;
46-
use std::container::MutableMap;
44+
use std::prelude::*;
4745
use std::rand;
4846
use std::rand::Rng;
47+
use test::Bencher;
4948

5049
pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
5150
map: &mut M,

src/libcollections/dlist.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,14 @@ impl<A: Clone> Clone for DList<A> {
610610

611611
#[cfg(test)]
612612
mod tests {
613-
extern crate test;
614-
use self::test::Bencher;
615-
use deque::Deque;
613+
use std::prelude::*;
616614
use std::rand;
615+
use test::Bencher;
616+
use test;
617+
618+
use deque::Deque;
617619
use super::{DList, Node, ListInsertion};
620+
use vec::Vec;
618621

619622
pub fn check_links<T>(list: &DList<T>) {
620623
let mut len = 0u;

src/libcollections/enum_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<E:CLike> Iterator<E> for Items<E> {
138138

139139
#[cfg(test)]
140140
mod test {
141-
141+
use std::prelude::*;
142142
use std::mem;
143143

144144
use enum_set::{EnumSet, CLike};

src/libcollections/hash/mod.rs

+32-12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ use core::prelude::*;
6868
use alloc::owned::Box;
6969
use alloc::rc::Rc;
7070
use core::intrinsics::TypeId;
71+
use core::mem;
7172

7273
use vec::Vec;
7374

@@ -97,14 +98,16 @@ pub trait Writer {
9798

9899
//////////////////////////////////////////////////////////////////////////////
99100

101+
fn id<T>(t: T) -> T { t }
102+
100103
macro_rules! impl_hash(
101-
( $($ty:ident)* ) => (
104+
( $($ty:ident, $uty:ident, $f:path;)* ) => (
102105
$(
103106
impl<S: Writer> Hash<S> for $ty {
104107
#[inline]
105108
fn hash(&self, state: &mut S) {
106109
let a: [u8, ..::core::$ty::BYTES] = unsafe {
107-
::core::mem::transmute(*self)
110+
mem::transmute($f(*self as $uty) as $ty)
108111
};
109112
state.write(a.as_slice())
110113
}
@@ -113,7 +116,28 @@ macro_rules! impl_hash(
113116
)
114117
)
115118

116-
impl_hash!( u8 u16 u32 u64 uint i8 i16 i32 i64 int )
119+
impl_hash!(
120+
u8, u8, id;
121+
u16, u16, mem::to_le16;
122+
u32, u32, mem::to_le32;
123+
u64, u64, mem::to_le64;
124+
i8, u8, id;
125+
i16, u16, mem::to_le16;
126+
i32, u32, mem::to_le32;
127+
i64, u64, mem::to_le64;
128+
)
129+
130+
#[cfg(target_word_size = "32")]
131+
impl_hash!(
132+
uint, u32, mem::to_le32;
133+
int, u32, mem::to_le32;
134+
)
135+
136+
#[cfg(target_word_size = "64")]
137+
impl_hash!(
138+
uint, u64, mem::to_le64;
139+
int, u64, mem::to_le64;
140+
)
117141

118142
impl<S: Writer> Hash<S> for bool {
119143
#[inline]
@@ -292,14 +316,11 @@ impl<S: Writer, T: Hash<S>, U: Hash<S>> Hash<S> for Result<T, U> {
292316

293317
#[cfg(test)]
294318
mod tests {
295-
use mem;
296-
use io::{IoResult, Writer};
297-
use iter::{Iterator};
298-
use option::{Some, None};
299-
use result::Ok;
300-
use slice::ImmutableVector;
319+
use std::prelude::*;
320+
use std::mem;
301321

302-
use super::{Hash, Hasher};
322+
use slice::ImmutableVector;
323+
use super::{Hash, Hasher, Writer};
303324

304325
struct MyWriterHasher;
305326

@@ -317,11 +338,10 @@ mod tests {
317338

318339
impl Writer for MyWriter {
319340
// Most things we'll just add up the bytes.
320-
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
341+
fn write(&mut self, buf: &[u8]) {
321342
for byte in buf.iter() {
322343
self.hash += *byte as u64;
323344
}
324-
Ok(())
325345
}
326346
}
327347

src/libcollections/hash/sip.rs

+12-26
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,15 @@ pub fn hash_with_keys<T: Hash<SipState>>(k0: u64, k1: u64, value: &T) -> u64 {
269269

270270
#[cfg(test)]
271271
mod tests {
272-
extern crate test;
273-
use prelude::*;
274-
use num::ToStrRadix;
275-
use option::{Some, None};
272+
use test::Bencher;
273+
use std::prelude::*;
274+
use std::num::ToStrRadix;
275+
276276
use str::Str;
277277
use string::String;
278278
use slice::{Vector, ImmutableVector};
279-
use self::test::Bencher;
280279

281-
use super::super::Hash;
280+
use super::super::{Hash, Writer};
282281
use super::{SipState, hash, hash_with_keys};
283282

284283
// Hash just the bytes of the slice, without length prefix
@@ -399,7 +398,7 @@ mod tests {
399398
}
400399

401400
while t < 64 {
402-
debug!("siphash test {}", t);
401+
debug!("siphash test {}: {}", t, buf);
403402
let vec = u8to64_le!(vecs[t], 0);
404403
let out = hash_with_keys(k0, k1, &Bytes(buf.as_slice()));
405404
debug!("got {:?}, expected {:?}", out, vec);
@@ -412,10 +411,14 @@ mod tests {
412411
let v = to_hex_str(&vecs[t]);
413412
debug!("{}: ({}) => inc={} full={}", t, v, i, f);
414413

415-
assert!(f == i && f == v);
414+
debug!("full state {:?}", state_full);
415+
debug!("inc state {:?}", state_inc);
416+
417+
assert_eq!(f, i);
418+
assert_eq!(f, v);
416419

417420
buf.push(t as u8);
418-
state_inc.write_u8(t as u8);
421+
state_inc.write([t as u8]);
419422

420423
t += 1;
421424
}
@@ -542,21 +545,4 @@ officia deserunt mollit anim id est laborum.";
542545
assert_eq!(hash(&u), 5254097107239593357);
543546
})
544547
}
545-
546-
#[deriving(Hash)]
547-
struct Compound {
548-
x: u8,
549-
y: u64,
550-
}
551-
552-
#[bench]
553-
fn bench_compound_1(b: &mut Bencher) {
554-
let compound = Compound {
555-
x: 1,
556-
y: 2,
557-
};
558-
b.iter(|| {
559-
assert_eq!(hash(&compound), 12506681940457338191);
560-
})
561-
}
562548
}

src/libcollections/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
extern crate alloc;
2727

2828
#[cfg(test)] extern crate native;
29-
#[cfg(test)] extern crate std;
3029
#[cfg(test)] extern crate test;
30+
#[cfg(test)] extern crate debug;
31+
#[cfg(test)] #[phase(syntax, link)] extern crate std;
3132
#[cfg(test)] #[phase(syntax, link)] extern crate log;
3233

3334
pub use bitv::{Bitv, BitvSet};
@@ -66,10 +67,11 @@ mod unicode;
6667
fn expect<T>(a: core::option::Option<T>, b: &str) -> T {
6768
match a {
6869
core::option::Some(a) => a,
69-
core::option::None => fail!(b),
70+
core::option::None => fail!("{}", b),
7071
}
7172
}
7273

74+
#[cfg(not(test))]
7375
mod std {
7476
pub use core::fmt; // necessary for fail!()
7577
pub use core::option; // necessary for fail!()

src/libcollections/priority_queue.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
use core::prelude::*;
1616

17-
use core::mem::{overwrite, zeroed, replace, swap};
17+
use core::mem::{zeroed, replace, swap};
18+
use core::ptr;
1819

1920
use slice;
2021
use vec::Vec;
@@ -240,7 +241,10 @@ impl<T: Ord> Extendable<T> for PriorityQueue<T> {
240241

241242
#[cfg(test)]
242243
mod tests {
244+
use std::prelude::*;
245+
243246
use priority_queue::PriorityQueue;
247+
use vec::Vec;
244248

245249
#[test]
246250
fn test_iterator() {
@@ -344,8 +348,8 @@ mod tests {
344348
v.sort();
345349
data.sort();
346350

347-
assert_eq!(v, data);
348-
assert_eq!(heap.into_sorted_vec(), data);
351+
assert_eq!(v.as_slice(), data.as_slice());
352+
assert_eq!(heap.into_sorted_vec().as_slice(), data.as_slice());
349353
}
350354

351355
#[test]

src/libcollections/ringbuf.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,14 @@ impl<T: fmt::Show> fmt::Show for RingBuf<T> {
410410

411411
#[cfg(test)]
412412
mod tests {
413-
extern crate test;
414-
use self::test::Bencher;
415-
use deque::Deque;
416-
use std::clone::Clone;
417-
use std::cmp::PartialEq;
418413
use std::fmt::Show;
414+
use std::prelude::*;
415+
use test::Bencher;
416+
use test;
417+
418+
use deque::Deque;
419419
use super::RingBuf;
420+
use vec::Vec;
420421

421422
#[test]
422423
fn test_simple() {

0 commit comments

Comments
 (0)