Skip to content

Commit c6ef251

Browse files
committed
---
yaml --- r: 130554 b: refs/heads/snap-stage3 c: 82c0527 h: refs/heads/master v: v3
1 parent 4664a7d commit c6ef251

File tree

117 files changed

+1242
-799
lines changed

Some content is hidden

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

117 files changed

+1242
-799
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: ee72e46638f2b2ae92e99df2a7ea92690baa0d07
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 0ad4644ae1474b5443e34d273e5553612c6d9364
4+
refs/heads/snap-stage3: 82c052794d4234752f0154c150d0b40779240db4
55
refs/heads/try: a2473a89da106f7dd3be86e9d52fe23f43d5bfa5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// except according to those terms.
1010

1111
#[cfg(rustdoc)]
12-
extern crate this = "rustdoc";
12+
extern crate "rustdoc" as this;
1313

1414
#[cfg(rustc)]
15-
extern crate this = "rustc";
15+
extern crate "rustc" as this;
1616

1717
fn main() { this::main() }

branches/snap-stage3/src/libcollections/bitv.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ fn match_words <'a,'b>(a: &'a Bitv, b: &'b Bitv) -> (MatchWords<'a>, MatchWords<
9595
static TRUE: bool = true;
9696
static FALSE: bool = false;
9797

98-
#[deriving(Clone)]
99-
struct SmallBitv {
100-
/// only the lowest nbits of this value are used. the rest is undefined.
101-
bits: uint
102-
}
103-
104-
#[deriving(Clone)]
105-
struct BigBitv {
106-
storage: Vec<uint>
107-
}
108-
109-
#[deriving(Clone)]
110-
enum BitvVariant { Big(BigBitv), Small(SmallBitv) }
111-
11298
/// The bitvector type.
11399
///
114100
/// # Example
@@ -1653,6 +1639,7 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
16531639
#[cfg(test)]
16541640
mod tests {
16551641
use std::prelude::*;
1642+
use std::iter::range_step;
16561643
use std::uint;
16571644
use std::rand;
16581645
use std::rand::Rng;
@@ -2046,12 +2033,14 @@ mod tests {
20462033

20472034
#[test]
20482035
fn test_bitv_iterator() {
2049-
let bools = [true, false, true, true];
2036+
let bools = vec![true, false, true, true];
20502037
let bitv: Bitv = bools.iter().map(|n| *n).collect();
20512038

2052-
for (act, &ex) in bitv.iter().zip(bools.iter()) {
2053-
assert_eq!(ex, act);
2054-
}
2039+
assert_eq!(bitv.iter().collect::<Vec<bool>>(), bools)
2040+
2041+
let long = Vec::from_fn(10000, |i| i % 2 == 0);
2042+
let bitv: Bitv = long.iter().map(|n| *n).collect();
2043+
assert_eq!(bitv.iter().collect::<Vec<bool>>(), long)
20552044
}
20562045

20572046
#[test]
@@ -2061,6 +2050,12 @@ mod tests {
20612050

20622051
let idxs: Vec<uint> = bitv.iter().collect();
20632052
assert_eq!(idxs, vec!(0, 2, 3));
2053+
2054+
let long: BitvSet = range(0u, 10000).map(|n| n % 2 == 0).collect();
2055+
let real = range_step(0, 10000, 2).collect::<Vec<uint>>();
2056+
2057+
let idxs: Vec<uint> = long.iter().collect();
2058+
assert_eq!(idxs, real);
20642059
}
20652060

20662061
#[test]
@@ -2574,7 +2569,7 @@ mod tests {
25742569
}
25752570

25762571
#[bench]
2577-
fn bench_bitv_big(b: &mut Bencher) {
2572+
fn bench_bitv_set_big_fixed(b: &mut Bencher) {
25782573
let mut r = rng();
25792574
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
25802575
b.iter(|| {
@@ -2586,7 +2581,19 @@ mod tests {
25862581
}
25872582

25882583
#[bench]
2589-
fn bench_bitv_small(b: &mut Bencher) {
2584+
fn bench_bitv_set_big_variable(b: &mut Bencher) {
2585+
let mut r = rng();
2586+
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
2587+
b.iter(|| {
2588+
for i in range(0u, 100) {
2589+
bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen());
2590+
}
2591+
&bitv
2592+
})
2593+
}
2594+
2595+
#[bench]
2596+
fn bench_bitv_set_small(b: &mut Bencher) {
25902597
let mut r = rng();
25912598
let mut bitv = Bitv::with_capacity(uint::BITS, false);
25922599
b.iter(|| {
@@ -2598,7 +2605,7 @@ mod tests {
25982605
}
25992606

26002607
#[bench]
2601-
fn bench_bitv_set_small(b: &mut Bencher) {
2608+
fn bench_bitvset_small(b: &mut Bencher) {
26022609
let mut r = rng();
26032610
let mut bitv = BitvSet::new();
26042611
b.iter(|| {
@@ -2610,7 +2617,7 @@ mod tests {
26102617
}
26112618

26122619
#[bench]
2613-
fn bench_bitv_set_big(b: &mut Bencher) {
2620+
fn bench_bitvset_big(b: &mut Bencher) {
26142621
let mut r = rng();
26152622
let mut bitv = BitvSet::new();
26162623
b.iter(|| {

branches/snap-stage3/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T> Rawlink<T> {
9090
/// Convert the `Rawlink` into an Option value
9191
fn resolve_immut<'a>(&self) -> Option<&'a T> {
9292
unsafe {
93-
mem::transmute(self.p.to_option())
93+
self.p.as_ref()
9494
}
9595
}
9696

branches/snap-stage3/src/libcollections/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub trait Set<T>: Collection {
289289
}
290290

291291
/// A mutable collection of values which are distinct from one another that
292-
/// can be mutaed.
292+
/// can be mutated.
293293
pub trait MutableSet<T>: Set<T> + Mutable {
294294
/// Adds a value to the set. Returns `true` if the value was not already
295295
/// present in the set.

branches/snap-stage3/src/libcollections/ringbuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<T> RingBuf<T> {
132132
elts: Vec::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
133133
}
134134

135-
/// Retrieva an element in the `RingBuf` by index.
135+
/// Retrieve an element in the `RingBuf` by index.
136136
///
137137
/// Fails if there is no element with the given index.
138138
///

branches/snap-stage3/src/libcollections/smallintmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<V:Clone> SmallIntMap<V> {
324324
/// Updates a value in the map. If the key already exists in the map,
325325
/// modifies the value with `ff` taking `oldval, newval`.
326326
/// Otherwise, sets the value to `newval`.
327-
/// Returasn `true` if the key did not already exist in the map.
327+
/// Returns `true` if the key did not already exist in the map.
328328
///
329329
/// # Example
330330
///

branches/snap-stage3/src/libcollections/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//!
4545
//! # Representation
4646
//!
47-
//! Rust's string type, `str`, is a sequence of unicode scalar values encoded as a
47+
//! Rust's string type, `str`, is a sequence of Unicode scalar values encoded as a
4848
//! stream of UTF-8 bytes. All strings are guaranteed to be validly encoded UTF-8
4949
//! sequences. Additionally, strings are not null-terminated and can contain null
5050
//! bytes.

branches/snap-stage3/src/libcore/char.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub fn escape_unicode(c: char, f: |char|) {
201201
/// - Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively.
202202
/// - Single-quote, double-quote and backslash chars are backslash-escaped.
203203
/// - Any other chars in the range [0x20,0x7e] are not escaped.
204-
/// - Any other chars are given hex unicode escapes; see `escape_unicode`.
204+
/// - Any other chars are given hex Unicode escapes; see `escape_unicode`.
205205
///
206206
pub fn escape_default(c: char, f: |char|) {
207207
match c {
@@ -290,7 +290,7 @@ pub trait Char {
290290
/// * Single-quote, double-quote and backslash chars are backslash-
291291
/// escaped.
292292
/// * Any other chars in the range [0x20,0x7e] are not escaped.
293-
/// * Any other chars are given hex unicode escapes; see `escape_unicode`.
293+
/// * Any other chars are given hex Unicode escapes; see `escape_unicode`.
294294
fn escape_default(&self, f: |char|);
295295

296296
/// Returns the amount of bytes this character would need if encoded in

branches/snap-stage3/src/libcore/fmt/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,28 @@ impl<'a> Formatter<'a> {
461461
use char::Char;
462462
let align = match self.align {
463463
rt::AlignUnknown => default,
464-
rt::AlignLeft | rt::AlignRight => self.align
464+
_ => self.align
465465
};
466-
if align == rt::AlignLeft {
467-
try!(f(self));
468-
}
466+
467+
let (pre_pad, post_pad) = match align {
468+
rt::AlignLeft => (0u, padding),
469+
rt::AlignRight | rt::AlignUnknown => (padding, 0u),
470+
rt::AlignCenter => (padding / 2, (padding + 1) / 2),
471+
};
472+
469473
let mut fill = [0u8, ..4];
470474
let len = self.fill.encode_utf8(fill).unwrap_or(0);
471-
for _ in range(0, padding) {
475+
476+
for _ in range(0, pre_pad) {
472477
try!(self.buf.write(fill.slice_to(len)));
473478
}
474-
if align == rt::AlignRight {
475-
try!(f(self));
479+
480+
try!(f(self));
481+
482+
for _ in range(0, post_pad) {
483+
try!(self.buf.write(fill.slice_to(len)));
476484
}
485+
477486
Ok(())
478487
}
479488

branches/snap-stage3/src/libcore/fmt/rt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub enum Alignment {
4343
AlignLeft,
4444
/// Indication that contents should be right-aligned.
4545
AlignRight,
46+
/// Indication that contents should be center-aligned.
47+
AlignCenter,
4648
/// No alignment was requested.
4749
AlignUnknown,
4850
}

branches/snap-stage3/src/libcore/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ extern "rust-intrinsic" {
311311

312312
/// Gives the address for the return value of the enclosing function.
313313
///
314-
/// Using this instrinsic in a function that does not use an out pointer
314+
/// Using this intrinsic in a function that does not use an out pointer
315315
/// will trigger a compiler error.
316316
pub fn return_address() -> *const u8;
317317

branches/snap-stage3/src/libcore/ptr.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,46 @@ pub unsafe fn position<T>(buf: *const T, f: |&T| -> bool) -> uint {
256256
pub trait RawPtr<T> {
257257
/// Returns the null pointer.
258258
fn null() -> Self;
259+
259260
/// Returns true if the pointer is equal to the null pointer.
260261
fn is_null(&self) -> bool;
262+
261263
/// Returns true if the pointer is not equal to the null pointer.
262264
fn is_not_null(&self) -> bool { !self.is_null() }
265+
263266
/// Returns the value of this pointer (ie, the address it points to)
264267
fn to_uint(&self) -> uint;
265-
/// Returns `None` if the pointer is null, or else returns the value wrapped
266-
/// in `Some`.
268+
269+
/// Returns `None` if the pointer is null, or else returns a reference to the
270+
/// value wrapped in `Some`.
267271
///
268272
/// # Safety Notes
269273
///
270-
/// While this method is useful for null-safety, it is important to note
271-
/// that this is still an unsafe operation because the returned value could
272-
/// be pointing to invalid memory.
273-
unsafe fn to_option(&self) -> Option<&T>;
274+
/// While this method and its mutable counterpart are useful for null-safety,
275+
/// it is important to note that this is still an unsafe operation because
276+
/// the returned value could be pointing to invalid memory.
277+
unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
278+
279+
/// A synonym for `as_ref`, except with incorrect lifetime semantics
280+
#[deprecated="Use `as_ref` instead"]
281+
unsafe fn to_option<'a>(&'a self) -> Option<&'a T> {
282+
mem::transmute(self.as_ref())
283+
}
284+
274285
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
275286
/// the object, or one-byte-past-the-end. `count` is in units of T; e.g. a
276287
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
277288
unsafe fn offset(self, count: int) -> Self;
278289
}
279290

291+
/// Methods on mutable raw pointers
292+
pub trait RawMutPtr<T>{
293+
/// Returns `None` if the pointer is null, or else returns a mutable reference
294+
/// to the value wrapped in `Some`. As with `as_ref`, this is unsafe because
295+
/// it cannot verify the validity of the returned pointer.
296+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T>;
297+
}
298+
280299
impl<T> RawPtr<T> for *const T {
281300
#[inline]
282301
fn null() -> *const T { null() }
@@ -293,7 +312,7 @@ impl<T> RawPtr<T> for *const T {
293312
}
294313

295314
#[inline]
296-
unsafe fn to_option(&self) -> Option<&T> {
315+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
297316
if self.is_null() {
298317
None
299318
} else {
@@ -318,7 +337,7 @@ impl<T> RawPtr<T> for *mut T {
318337
}
319338

320339
#[inline]
321-
unsafe fn to_option(&self) -> Option<&T> {
340+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
322341
if self.is_null() {
323342
None
324343
} else {
@@ -327,6 +346,17 @@ impl<T> RawPtr<T> for *mut T {
327346
}
328347
}
329348

349+
impl<T> RawMutPtr<T> for *mut T {
350+
#[inline]
351+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
352+
if self.is_null() {
353+
None
354+
} else {
355+
Some(&mut **self)
356+
}
357+
}
358+
}
359+
330360
// Equality for pointers
331361
impl<T> PartialEq for *const T {
332362
#[inline]

branches/snap-stage3/src/libcore/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ pub trait StrSlice<'a> {
11281128
fn contains_char(&self, needle: char) -> bool;
11291129

11301130
/// An iterator over the characters of `self`. Note, this iterates
1131-
/// over unicode code-points, not unicode graphemes.
1131+
/// over Unicode code-points, not Unicode graphemes.
11321132
///
11331133
/// # Example
11341134
///
@@ -1505,7 +1505,7 @@ pub trait StrSlice<'a> {
15051505
/// Pluck a character out of a string and return the index of the next
15061506
/// character.
15071507
///
1508-
/// This function can be used to iterate over the unicode characters of a
1508+
/// This function can be used to iterate over the Unicode characters of a
15091509
/// string.
15101510
///
15111511
/// # Example
@@ -1549,7 +1549,7 @@ pub trait StrSlice<'a> {
15491549
/// # Return value
15501550
///
15511551
/// A record {ch: char, next: uint} containing the char value and the byte
1552-
/// index of the next unicode character.
1552+
/// index of the next Unicode character.
15531553
///
15541554
/// # Failure
15551555
///
@@ -1559,7 +1559,7 @@ pub trait StrSlice<'a> {
15591559

15601560
/// Given a byte position and a str, return the previous char and its position.
15611561
///
1562-
/// This function can be used to iterate over a unicode string in reverse.
1562+
/// This function can be used to iterate over a Unicode string in reverse.
15631563
///
15641564
/// Returns 0 for next index if called on start index 0.
15651565
///

0 commit comments

Comments
 (0)