Skip to content

Commit 321af1b

Browse files
committed
---
yaml --- r: 152525 b: refs/heads/try2 c: 0642cbb h: refs/heads/master i: 152523: 56cb09a v: v3
1 parent 70b97ad commit 321af1b

Some content is hidden

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

43 files changed

+272
-718
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: dbd29ea96ef77a67496bb44de382140354c23632
8+
refs/heads/try2: 0642cbbde0e51d5f4465b937ab8ff7d46df02df0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
110110
let matches =
111111
&match getopts::getopts(args_.as_slice(), groups.as_slice()) {
112112
Ok(m) => m,
113-
Err(f) => fail!("{}", f.to_err_msg())
113+
Err(f) => fail!("{}", f)
114114
};
115115

116116
if matches.opt_present("h") || matches.opt_present("help") {

branches/try2/src/libarena/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ impl<T> TypedArenaChunk<T> {
406406
None => {}
407407
Some(mut next) => {
408408
// We assume that the next chunk is completely filled.
409-
let capacity = next.capacity;
410-
next.destroy(capacity)
409+
next.destroy(next.capacity)
411410
}
412411
}
413412
}

branches/try2/src/libcollections/ringbuf.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ impl<T> Deque<T> for RingBuf<T> {
6666

6767
/// Return a mutable reference to the last element in the RingBuf
6868
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
69-
let nelts = self.nelts;
70-
if nelts > 0 { Some(self.get_mut(nelts - 1)) } else { None }
69+
if self.nelts > 0 { Some(self.get_mut(self.nelts - 1)) } else { None }
7170
}
7271

7372
/// Remove and return the first element in the RingBuf, or None if it is empty

branches/try2/src/libcollections/vec.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ impl<T> Vec<T> {
114114
unsafe {
115115
let mut xs = Vec::with_capacity(length);
116116
while xs.len < length {
117-
let len = xs.len;
118-
ptr::write(xs.as_mut_slice().unsafe_mut_ref(len), op(len));
117+
ptr::write(xs.as_mut_slice().unsafe_mut_ref(xs.len), op(xs.len));
119118
xs.len += 1;
120119
}
121120
xs
@@ -211,8 +210,7 @@ impl<T: Clone> Vec<T> {
211210
unsafe {
212211
let mut xs = Vec::with_capacity(length);
213212
while xs.len < length {
214-
let len = xs.len;
215-
ptr::write(xs.as_mut_slice().unsafe_mut_ref(len),
213+
ptr::write(xs.as_mut_slice().unsafe_mut_ref(xs.len),
216214
value.clone());
217215
xs.len += 1;
218216
}
@@ -323,10 +321,9 @@ impl<T:Clone> Clone for Vec<T> {
323321
let this_slice = self.as_slice();
324322
while vector.len < len {
325323
unsafe {
326-
let len = vector.len;
327324
ptr::write(
328-
vector.as_mut_slice().unsafe_mut_ref(len),
329-
this_slice.unsafe_ref(len).clone());
325+
vector.as_mut_slice().unsafe_mut_ref(vector.len),
326+
this_slice.unsafe_ref(vector.len).clone());
330327
}
331328
vector.len += 1;
332329
}

branches/try2/src/libcore/num/int_macros.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,33 +113,6 @@ mod tests {
113113
assert!((0b1111001 as $T).count_zeros() == BITS as $T - 5);
114114
}
115115

116-
#[test]
117-
fn test_swap_bytes() {
118-
let n: $T = 0b0101100; assert_eq!(n.swap_bytes().swap_bytes(), n);
119-
let n: $T = 0b0100001; assert_eq!(n.swap_bytes().swap_bytes(), n);
120-
let n: $T = 0b1111001; assert_eq!(n.swap_bytes().swap_bytes(), n);
121-
122-
// Swapping these should make no difference
123-
let n: $T = 0; assert_eq!(n.swap_bytes(), n);
124-
let n: $T = -1; assert_eq!(n.swap_bytes(), n);
125-
}
126-
127-
#[test]
128-
fn test_rotate() {
129-
let n: $T = 0b0101100; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
130-
let n: $T = 0b0100001; assert_eq!(n.rotate_left(3).rotate_left(2).rotate_right(5), n);
131-
let n: $T = 0b1111001; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
132-
133-
// Rotating these should make no difference
134-
//
135-
// We test using 124 bits because to ensure that overlong bit shifts do
136-
// not cause undefined behaviour. See #10183.
137-
let n: $T = 0; assert_eq!(n.rotate_left(124), n);
138-
let n: $T = -1; assert_eq!(n.rotate_left(124), n);
139-
let n: $T = 0; assert_eq!(n.rotate_right(124), n);
140-
let n: $T = -1; assert_eq!(n.rotate_right(124), n);
141-
}
142-
143116
#[test]
144117
fn test_signed_checked_div() {
145118
assert!(10i.checked_div(&2) == Some(5));

branches/try2/src/libcore/num/mod.rs

Lines changed: 20 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -436,135 +436,57 @@ pub trait Bitwise: Bounded
436436
/// assert_eq!(n.trailing_zeros(), 3);
437437
/// ```
438438
fn trailing_zeros(&self) -> Self;
439-
440-
/// Reverses the byte order of a binary number.
441-
///
442-
/// # Example
443-
///
444-
/// ```rust
445-
/// use std::num::Bitwise;
446-
///
447-
/// let n = 0x0123456789ABCDEFu64;
448-
/// let m = 0xEFCDAB8967452301u64;
449-
/// assert_eq!(n.swap_bytes(), m);
450-
/// ```
451-
fn swap_bytes(&self) -> Self;
452-
453-
/// Shifts the bits to the left by a specified amount amount, `r`, wrapping
454-
/// the truncated bits to the end of the resulting value.
455-
///
456-
/// # Example
457-
///
458-
/// ```rust
459-
/// use std::num::Bitwise;
460-
///
461-
/// let n = 0x0123456789ABCDEFu64;
462-
/// let m = 0x3456789ABCDEF012u64;
463-
/// assert_eq!(n.rotate_left(12), m);
464-
/// ```
465-
fn rotate_left(&self, r: uint) -> Self;
466-
467-
/// Shifts the bits to the right by a specified amount amount, `r`, wrapping
468-
/// the truncated bits to the beginning of the resulting value.
469-
///
470-
/// # Example
471-
///
472-
/// ```rust
473-
/// use std::num::Bitwise;
474-
///
475-
/// let n = 0x0123456789ABCDEFu64;
476-
/// let m = 0xDEF0123456789ABCu64;
477-
/// assert_eq!(n.rotate_right(12), m);
478-
/// ```
479-
fn rotate_right(&self, r: uint) -> Self;
480439
}
481440

482-
/// Swapping a single byte does nothing. This is unsafe to be consistent with
483-
/// the other `bswap` intrinsics.
484-
#[inline]
485-
unsafe fn bswap8(x: u8) -> u8 { x }
486-
487441
macro_rules! bitwise_impl(
488-
($t:ty, $bits:expr, $co:ident, $lz:ident, $tz:ident, $bs:path) => {
442+
($t:ty, $co:path, $lz:path, $tz:path) => {
489443
impl Bitwise for $t {
490444
#[inline]
491-
fn count_ones(&self) -> $t { unsafe { intrinsics::$co(*self) } }
445+
fn count_ones(&self) -> $t { unsafe { $co(*self) } }
492446

493447
#[inline]
494-
fn leading_zeros(&self) -> $t { unsafe { intrinsics::$lz(*self) } }
448+
fn leading_zeros(&self) -> $t { unsafe { $lz(*self) } }
495449

496450
#[inline]
497-
fn trailing_zeros(&self) -> $t { unsafe { intrinsics::$tz(*self) } }
498-
499-
#[inline]
500-
fn swap_bytes(&self) -> $t { unsafe { $bs(*self) } }
501-
502-
#[inline]
503-
fn rotate_left(&self, r: uint) -> $t {
504-
// Protect against undefined behaviour for overlong bit shifts
505-
let r = r % $bits;
506-
(*self << r) | (*self >> ($bits - r))
507-
}
508-
509-
#[inline]
510-
fn rotate_right(&self, r: uint) -> $t {
511-
// Protect against undefined behaviour for overlong bit shifts
512-
let r = r % $bits;
513-
(*self >> r) | (*self << ($bits - r))
514-
}
451+
fn trailing_zeros(&self) -> $t { unsafe { $tz(*self) } }
515452
}
516453
}
517454
)
518455

519456
macro_rules! bitwise_cast_impl(
520-
($t:ty, $t_cast:ty, $bits:expr, $co:ident, $lz:ident, $tz:ident, $bs:path) => {
457+
($t:ty, $t_cast:ty, $co:path, $lz:path, $tz:path) => {
521458
impl Bitwise for $t {
522459
#[inline]
523-
fn count_ones(&self) -> $t { unsafe { intrinsics::$co(*self as $t_cast) as $t } }
524-
525-
#[inline]
526-
fn leading_zeros(&self) -> $t { unsafe { intrinsics::$lz(*self as $t_cast) as $t } }
527-
528-
#[inline]
529-
fn trailing_zeros(&self) -> $t { unsafe { intrinsics::$tz(*self as $t_cast) as $t } }
460+
fn count_ones(&self) -> $t { unsafe { $co(*self as $t_cast) as $t } }
530461

531462
#[inline]
532-
fn swap_bytes(&self) -> $t { unsafe { $bs(*self as $t_cast) as $t } }
463+
fn leading_zeros(&self) -> $t { unsafe { $lz(*self as $t_cast) as $t } }
533464

534465
#[inline]
535-
fn rotate_left(&self, r: uint) -> $t {
536-
// cast to prevent the sign bit from being corrupted
537-
(*self as $t_cast).rotate_left(r) as $t
538-
}
539-
540-
#[inline]
541-
fn rotate_right(&self, r: uint) -> $t {
542-
// cast to prevent the sign bit from being corrupted
543-
(*self as $t_cast).rotate_right(r) as $t
544-
}
466+
fn trailing_zeros(&self) -> $t { unsafe { $tz(*self as $t_cast) as $t } }
545467
}
546468
}
547469
)
548470

549471
#[cfg(target_word_size = "32")]
550-
bitwise_cast_impl!(uint, u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
472+
bitwise_cast_impl!(uint, u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
551473
#[cfg(target_word_size = "64")]
552-
bitwise_cast_impl!(uint, u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
474+
bitwise_cast_impl!(uint, u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
553475

554-
bitwise_impl!(u8, 8, ctpop8, ctlz8, cttz8, bswap8)
555-
bitwise_impl!(u16, 16, ctpop16, ctlz16, cttz16, intrinsics::bswap16)
556-
bitwise_impl!(u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
557-
bitwise_impl!(u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
476+
bitwise_impl!(u8, intrinsics::ctpop8, intrinsics::ctlz8, intrinsics::cttz8)
477+
bitwise_impl!(u16, intrinsics::ctpop16, intrinsics::ctlz16, intrinsics::cttz16)
478+
bitwise_impl!(u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
479+
bitwise_impl!(u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
558480

559481
#[cfg(target_word_size = "32")]
560-
bitwise_cast_impl!(int, u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
482+
bitwise_cast_impl!(int, u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
561483
#[cfg(target_word_size = "64")]
562-
bitwise_cast_impl!(int, u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
484+
bitwise_cast_impl!(int, u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
563485

564-
bitwise_cast_impl!(i8, u8, 8, ctpop8, ctlz8, cttz8, bswap8)
565-
bitwise_cast_impl!(i16, u16, 16, ctpop16, ctlz16, cttz16, intrinsics::bswap16)
566-
bitwise_cast_impl!(i32, u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
567-
bitwise_cast_impl!(i64, u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
486+
bitwise_cast_impl!(i8, u8, intrinsics::ctpop8, intrinsics::ctlz8, intrinsics::cttz8)
487+
bitwise_cast_impl!(i16, u16, intrinsics::ctpop16, intrinsics::ctlz16, intrinsics::cttz16)
488+
bitwise_cast_impl!(i32, u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
489+
bitwise_cast_impl!(i64, u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
568490

569491
/// Specifies the available operations common to all of Rust's core numeric primitives.
570492
/// These may not always make sense from a purely mathematical point of view, but

branches/try2/src/libcore/num/uint_macros.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,6 @@ mod tests {
6464
assert!((0b1111001 as $T).count_zeros() == BITS as $T - 5);
6565
}
6666

67-
#[test]
68-
fn test_swap_bytes() {
69-
let n: $T = 0b0101100; assert_eq!(n.swap_bytes().swap_bytes(), n);
70-
let n: $T = 0b0100001; assert_eq!(n.swap_bytes().swap_bytes(), n);
71-
let n: $T = 0b1111001; assert_eq!(n.swap_bytes().swap_bytes(), n);
72-
73-
// Swapping these should make no difference
74-
let n: $T = 0; assert_eq!(n.swap_bytes(), n);
75-
let n: $T = MAX; assert_eq!(n.swap_bytes(), n);
76-
}
77-
78-
#[test]
79-
fn test_rotate() {
80-
let n: $T = 0b0101100; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
81-
let n: $T = 0b0100001; assert_eq!(n.rotate_left(3).rotate_left(2).rotate_right(5), n);
82-
let n: $T = 0b1111001; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
83-
84-
// Rotating these should make no difference
85-
//
86-
// We test using 124 bits because to ensure that overlong bit shifts do
87-
// not cause undefined behaviour. See #10183.
88-
let n: $T = 0; assert_eq!(n.rotate_left(124), n);
89-
let n: $T = MAX; assert_eq!(n.rotate_left(124), n);
90-
let n: $T = 0; assert_eq!(n.rotate_right(124), n);
91-
let n: $T = MAX; assert_eq!(n.rotate_right(124), n);
92-
}
93-
9467
#[test]
9568
fn test_unsigned_checked_div() {
9669
assert!(10u.checked_div(&2) == Some(5));

branches/try2/src/libdebug/repr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,13 @@ impl<'a> ReprVisitor<'a> {
127127
#[inline]
128128
pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T| -> bool) -> bool {
129129
unsafe {
130-
let ptr = self.ptr;
131-
f(self, mem::transmute::<*u8,&T>(ptr))
130+
f(self, mem::transmute::<*u8,&T>(self.ptr))
132131
}
133132
}
134133

135134
#[inline]
136135
pub fn visit_inner(&mut self, inner: *TyDesc) -> bool {
137-
let ptr = self.ptr;
138-
self.visit_ptr_inner(ptr, inner)
136+
self.visit_ptr_inner(self.ptr, inner)
139137
}
140138

141139
#[inline]

branches/try2/src/libgetopts/lib.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
//! ];
6262
//! let matches = match getopts(args.tail(), opts) {
6363
//! Ok(m) => { m }
64-
//! Err(f) => { fail!(f.to_err_msg()) }
64+
//! Err(f) => { fail!(f.to_str()) }
6565
//! };
6666
//! if matches.opt_present("h") {
6767
//! print_usage(program.as_slice(), opts);
@@ -94,6 +94,7 @@
9494
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
9595

9696
use std::cmp::PartialEq;
97+
use std::fmt;
9798
use std::result::{Err, Ok};
9899
use std::result;
99100
use std::string::String;
@@ -182,9 +183,9 @@ pub struct Matches {
182183
}
183184

184185
/// The type returned when the command line does not conform to the
185-
/// expected format. Call the `to_err_msg` method to retrieve the
186-
/// error as a string.
187-
#[deriving(Clone, PartialEq, Show)]
186+
/// expected format. Use the `Show` implementation to output detailed
187+
/// information.
188+
#[deriving(Clone, PartialEq)]
188189
pub enum Fail_ {
189190
/// The option requires an argument but none was passed.
190191
ArgumentMissing(String),
@@ -498,22 +499,29 @@ pub fn opt(short_name: &str,
498499

499500
impl Fail_ {
500501
/// Convert a `Fail_` enum into an error string.
502+
#[deprecated="use `Show` (`{}` format specifier)"]
501503
pub fn to_err_msg(self) -> String {
502-
match self {
504+
self.to_str()
505+
}
506+
}
507+
508+
impl fmt::Show for Fail_ {
509+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
510+
match *self {
503511
ArgumentMissing(ref nm) => {
504-
format!("Argument to option '{}' missing.", *nm)
512+
write!(f, "Argument to option '{}' missing.", *nm)
505513
}
506514
UnrecognizedOption(ref nm) => {
507-
format!("Unrecognized option: '{}'.", *nm)
515+
write!(f, "Unrecognized option: '{}'.", *nm)
508516
}
509517
OptionMissing(ref nm) => {
510-
format!("Required option '{}' missing.", *nm)
518+
write!(f, "Required option '{}' missing.", *nm)
511519
}
512520
OptionDuplicated(ref nm) => {
513-
format!("Option '{}' given more than once.", *nm)
521+
write!(f, "Option '{}' given more than once.", *nm)
514522
}
515523
UnexpectedArgument(ref nm) => {
516-
format!("Option '{}' does not take an argument.", *nm)
524+
write!(f, "Option '{}' does not take an argument.", *nm)
517525
}
518526
}
519527
}
@@ -522,8 +530,9 @@ impl Fail_ {
522530
/// Parse command line arguments according to the provided options.
523531
///
524532
/// On success returns `Ok(Opt)`. Use methods such as `opt_present`
525-
/// `opt_str`, etc. to interrogate results. Returns `Err(Fail_)` on failure.
526-
/// Use `to_err_msg` to get an error message.
533+
/// `opt_str`, etc. to interrogate results. Returns `Err(Fail_)` on
534+
/// failure: use the `Show` implementation of `Fail_` to display
535+
/// information about it.
527536
pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
528537
let opts: Vec<Opt> = optgrps.iter().map(|x| x.long_to_short()).collect();
529538
let n_opts = opts.len();
@@ -1110,7 +1119,6 @@ mod tests {
11101119
let rs = getopts(args.as_slice(), opts.as_slice());
11111120
match rs {
11121121
Err(f) => {
1113-
error!("{:?}", f.clone().to_err_msg());
11141122
check_fail_type(f, UnexpectedArgument_);
11151123
}
11161124
_ => fail!()

0 commit comments

Comments
 (0)