Skip to content

Commit e91daaa

Browse files
committed
auto merge of #6586 : bjz/rust/formatting-and-conditionals, r=thestinger
2 parents ac74bbe + ad6ee5f commit e91daaa

File tree

12 files changed

+284
-254
lines changed

12 files changed

+284
-254
lines changed

src/libcore/bool.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@ pub fn is_false(v: bool) -> bool { !v }
4949
/// Parse logic value from `s`
5050
impl FromStr for bool {
5151
fn from_str(s: &str) -> Option<bool> {
52-
if s == "true" {
53-
Some(true)
54-
} else if s == "false" {
55-
Some(false)
56-
} else {
57-
None
52+
match s {
53+
"true" => Some(true),
54+
"false" => Some(false),
55+
_ => None,
5856
}
5957
}
6058
}

src/libcore/cmp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,11 @@ totalord_impl!(uint)
127127

128128
totalord_impl!(char)
129129

130+
/// Compares (a1, b1) against (a2, b2), where the a values are more significant.
130131
pub fn cmp2<A:TotalOrd,B:TotalOrd>(
131132
a1: &A, b1: &B,
132133
a2: &A, b2: &B) -> Ordering
133134
{
134-
//! Compares (a1, b1) against (a2, b2), where the a values are more significant.
135-
136135
match a1.cmp(a2) {
137136
Less => Less,
138137
Greater => Greater,

src/libcore/either.rs

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,22 @@ pub enum Either<T, U> {
2626
Right(U)
2727
}
2828

29+
/// Applies a function based on the given either value
30+
///
31+
/// If `value` is left(T) then `f_left` is applied to its contents, if
32+
/// `value` is right(U) then `f_right` is applied to its contents, and the
33+
/// result is returned.
2934
#[inline(always)]
3035
pub fn either<T, U, V>(f_left: &fn(&T) -> V,
3136
f_right: &fn(&U) -> V, value: &Either<T, U>) -> V {
32-
/*!
33-
* Applies a function based on the given either value
34-
*
35-
* If `value` is left(T) then `f_left` is applied to its contents, if
36-
* `value` is right(U) then `f_right` is applied to its contents, and the
37-
* result is returned.
38-
*/
39-
4037
match *value {
41-
Left(ref l) => f_left(l),
42-
Right(ref r) => f_right(r)
38+
Left(ref l) => f_left(l),
39+
Right(ref r) => f_right(r)
4340
}
4441
}
4542

43+
/// Extracts from a vector of either all the left values
4644
pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[T] {
47-
//! Extracts from a vector of either all the left values
48-
4945
do vec::build_sized(eithers.len()) |push| {
5046
for eithers.each |elt| {
5147
match *elt {
@@ -56,9 +52,8 @@ pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[T] {
5652
}
5753
}
5854

55+
/// Extracts from a vector of either all the right values
5956
pub fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
60-
//! Extracts from a vector of either all the right values
61-
6257
do vec::build_sized(eithers.len()) |push| {
6358
for eithers.each |elt| {
6459
match *elt {
@@ -69,80 +64,73 @@ pub fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
6964
}
7065
}
7166

72-
pub fn partition<T, U>(eithers: ~[Either<T, U>])
73-
-> (~[T], ~[U]) {
74-
/*!
75-
* Extracts from a vector of either all the left values and right values
76-
*
77-
* Returns a structure containing a vector of left values and a vector of
78-
* right values.
79-
*/
80-
67+
/// Extracts from a vector of either all the left values and right values
68+
///
69+
/// Returns a structure containing a vector of left values and a vector of
70+
/// right values.
71+
pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
8172
let mut lefts: ~[T] = ~[];
8273
let mut rights: ~[U] = ~[];
8374
do vec::consume(eithers) |_i, elt| {
8475
match elt {
85-
Left(l) => lefts.push(l),
86-
Right(r) => rights.push(r)
76+
Left(l) => lefts.push(l),
77+
Right(r) => rights.push(r)
8778
}
8879
}
8980
return (lefts, rights);
9081
}
9182

83+
/// Flips between left and right of a given either
9284
#[inline(always)]
9385
pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
94-
//! Flips between left and right of a given either
95-
9686
match eith {
97-
Right(r) => Left(r),
98-
Left(l) => Right(l)
87+
Right(r) => Left(r),
88+
Left(l) => Right(l)
9989
}
10090
}
10191

92+
/// Converts either::t to a result::t
93+
///
94+
/// Converts an `either` type to a `result` type, making the "right" choice
95+
/// an ok result, and the "left" choice a fail
10296
#[inline(always)]
103-
pub fn to_result<T, U>(eith: Either<T, U>)
104-
-> Result<U, T> {
105-
/*!
106-
* Converts either::t to a result::t
107-
*
108-
* Converts an `either` type to a `result` type, making the "right" choice
109-
* an ok result, and the "left" choice a fail
110-
*/
111-
97+
pub fn to_result<T, U>(eith: Either<T, U>) -> Result<U, T> {
11298
match eith {
113-
Right(r) => result::Ok(r),
114-
Left(l) => result::Err(l)
99+
Right(r) => result::Ok(r),
100+
Left(l) => result::Err(l)
115101
}
116102
}
117103

104+
/// Checks whether the given value is a left
118105
#[inline(always)]
119106
pub fn is_left<T, U>(eith: &Either<T, U>) -> bool {
120-
//! Checks whether the given value is a left
121-
122-
match *eith { Left(_) => true, _ => false }
107+
match *eith {
108+
Left(_) => true,
109+
_ => false
110+
}
123111
}
124112

113+
/// Checks whether the given value is a right
125114
#[inline(always)]
126115
pub fn is_right<T, U>(eith: &Either<T, U>) -> bool {
127-
//! Checks whether the given value is a right
128-
129-
match *eith { Right(_) => true, _ => false }
116+
match *eith {
117+
Right(_) => true,
118+
_ => false
119+
}
130120
}
131121

122+
/// Retrieves the value in the left branch. Fails if the either is Right.
132123
#[inline(always)]
133124
pub fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
134-
//! Retrieves the value in the left branch. Fails if the either is Right.
135-
136125
match eith {
137126
Left(x) => x,
138127
Right(_) => fail!("either::unwrap_left Right")
139128
}
140129
}
141130

131+
/// Retrieves the value in the right branch. Fails if the either is Left.
142132
#[inline(always)]
143133
pub fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
144-
//! Retrieves the value in the right branch. Fails if the either is Left.
145-
146134
match eith {
147135
Right(x) => x,
148136
Left(_) => fail!("either::unwrap_right Left")

src/libcore/managed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ pub mod raw {
3535

3636
}
3737

38+
/// Determine if two shared boxes point to the same object
3839
#[inline(always)]
3940
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
40-
//! Determine if two shared boxes point to the same object
4141
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
4242
a_ptr == b_ptr
4343
}
4444

45+
/// Determine if two mutable shared boxes point to the same object
4546
#[inline(always)]
4647
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
47-
//! Determine if two mutable shared boxes point to the same object
4848
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
4949
a_ptr == b_ptr
5050
}

src/libcore/num/f32.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,27 @@ impl Orderable for f32 {
248248
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
249249
}
250250

251-
/// Returns the number constrained within the range `mn <= self <= mx`.
252-
/// If any of the numbers are `NaN` then `NaN` is returned.
251+
#[cfg(stage0)]
253252
#[inline(always)]
254253
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
255254
if self.is_NaN() { *self }
256255
else if !(*self <= *mx) { *mx }
257256
else if !(*self >= *mn) { *mn }
258257
else { *self }
259258
}
259+
260+
/// Returns the number constrained within the range `mn <= self <= mx`.
261+
/// If any of the numbers are `NaN` then `NaN` is returned.
262+
#[cfg(not(stage0))]
263+
#[inline(always)]
264+
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
265+
cond!(
266+
(self.is_NaN()) { *self }
267+
(!(*self <= *mx)) { *mx }
268+
(!(*self >= *mn)) { *mn }
269+
_ { *self }
270+
)
271+
}
260272
}
261273

262274
impl Zero for f32 {

src/libcore/num/f64.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,27 @@ impl Orderable for f64 {
270270
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
271271
}
272272

273-
/// Returns the number constrained within the range `mn <= self <= mx`.
274-
/// If any of the numbers are `NaN` then `NaN` is returned.
273+
#[cfg(stage0)]
275274
#[inline(always)]
276275
fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
277276
if self.is_NaN() { *self }
278277
else if !(*self <= *mx) { *mx }
279278
else if !(*self >= *mn) { *mn }
280279
else { *self }
281280
}
281+
282+
/// Returns the number constrained within the range `mn <= self <= mx`.
283+
/// If any of the numbers are `NaN` then `NaN` is returned.
284+
#[cfg(not(stage0))]
285+
#[inline(always)]
286+
fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
287+
cond!(
288+
(self.is_NaN()) { *self }
289+
(!(*self <= *mx)) { *mx }
290+
(!(*self >= *mn)) { *mn }
291+
_ { *self }
292+
)
293+
}
282294
}
283295

284296
impl Zero for f64 {

src/libcore/num/int-template.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,23 @@ impl Orderable for T {
187187
if *self > *other { *self } else { *other }
188188
}
189189

190+
#[cfg(stage0)]
190191
#[inline(always)]
191192
fn clamp(&self, mn: &T, mx: &T) -> T {
192193
if *self > *mx { *mx } else
193194
if *self < *mn { *mn } else { *self }
194195
}
196+
197+
/// Returns the number constrained within the range `mn <= self <= mx`.
198+
#[cfg(not(stage0))]
199+
#[inline(always)]
200+
fn clamp(&self, mn: &T, mx: &T) -> T {
201+
cond!(
202+
(*self > *mx) { *mx }
203+
(*self < *mn) { *mn }
204+
_ { *self }
205+
)
206+
}
195207
}
196208

197209
impl Zero for T {

src/libcore/num/uint-template.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,23 @@ impl Orderable for T {
153153
if *self > *other { *self } else { *other }
154154
}
155155

156+
#[cfg(stage0)]
156157
#[inline(always)]
157158
fn clamp(&self, mn: &T, mx: &T) -> T {
158159
if *self > *mx { *mx } else
159160
if *self < *mn { *mn } else { *self }
160161
}
162+
163+
/// Returns the number constrained within the range `mn <= self <= mx`.
164+
#[cfg(not(stage0))]
165+
#[inline(always)]
166+
fn clamp(&self, mn: &T, mx: &T) -> T {
167+
cond!(
168+
(*self > *mx) { *mx }
169+
(*self < *mn) { *mn }
170+
_ { *self }
171+
)
172+
}
161173
}
162174

163175
impl Zero for T {

src/libcore/option.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ impl<T:Ord> Ord for Option<T> {
8989
}
9090

9191
fn ge(&self, other: &Option<T>) -> bool {
92-
! (self < other)
92+
!(self < other)
9393
}
9494

9595
fn gt(&self, other: &Option<T>) -> bool {
96-
! (self <= other)
96+
!(self <= other)
9797
}
9898
}
9999

@@ -182,34 +182,28 @@ pub impl<T> Option<T> {
182182
#[inline(always)]
183183
fn is_some(&const self) -> bool { !self.is_none() }
184184

185+
/// Update an optional value by optionally running its content through a
186+
/// function that returns an option.
185187
#[inline(always)]
186188
fn chain<U>(self, f: &fn(t: T) -> Option<U>) -> Option<U> {
187-
/*!
188-
* Update an optional value by optionally running its content through a
189-
* function that returns an option.
190-
*/
191189

192190
match self {
193191
Some(t) => f(t),
194192
None => None
195193
}
196194
}
197195

196+
/// Returns the leftmost Some() value, or None if both are None.
198197
#[inline(always)]
199198
fn or(self, optb: Option<T>) -> Option<T> {
200-
/*!
201-
* Returns the leftmost Some() value, or None if both are None.
202-
*/
203199
match self {
204200
Some(opta) => Some(opta),
205201
_ => optb
206202
}
207203
}
208204

209-
/**
210-
* Update an optional value by optionally running its content by reference
211-
* through a function that returns an option.
212-
*/
205+
/// Update an optional value by optionally running its content by reference
206+
/// through a function that returns an option.
213207
#[inline(always)]
214208
fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option<U>) -> Option<U> {
215209
match *self { Some(ref x) => f(x), None => None }

0 commit comments

Comments
 (0)