Skip to content

Commit bee5669

Browse files
committed
---
yaml --- r: 159575 b: refs/heads/auto c: d431a67 h: refs/heads/master i: 159573: 020f7b9 159571: 4efec0f 159567: 775aed2 v: v3
1 parent fec14cd commit bee5669

File tree

7 files changed

+27
-43
lines changed

7 files changed

+27
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: d1eb68e8d7d2883c70304021d5443c96bca18abb
13+
refs/heads/auto: d431a67cecc426a4d24dcf24d72a9147b8e08860
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use clone::Clone;
6262
use cmp;
6363
use cmp::{PartialEq, PartialOrd, Ord};
6464
use mem;
65-
use num::{Zero, One, CheckedAdd, CheckedSub, Saturating, ToPrimitive, Int};
65+
use num::{Zero, One, CheckedAdd, CheckedSub, ToPrimitive, Int};
6666
use ops::{Add, Mul, Sub};
6767
use option::{Option, Some, None};
6868
use uint;

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

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,28 @@ pub trait Int: Primitive
525525
fn to_le(self) -> Self {
526526
if cfg!(target_endian = "little") { self } else { self.swap_bytes() }
527527
}
528+
529+
/// Saturating addition. Returns `self + other`, saturating at the
530+
/// numeric bounds instead of overflowing.
531+
#[inline]
532+
fn saturating_add(self, other: Self) -> Self {
533+
match self.checked_add(&other) {
534+
Some(x) => x,
535+
None if other >= Zero::zero() => Bounded::max_value(),
536+
None => Bounded::min_value(),
537+
}
538+
}
539+
540+
/// Saturating subtraction. Returns `self - other`, saturating at the
541+
/// numeric bounds instead of overflowing.
542+
#[inline]
543+
fn saturating_sub(self, other: Self) -> Self {
544+
match self.checked_sub(&other) {
545+
Some(x) => x,
546+
None if other >= Zero::zero() => Bounded::min_value(),
547+
None => Bounded::max_value(),
548+
}
549+
}
528550
}
529551

530552
macro_rules! int_impl {
@@ -1150,43 +1172,6 @@ impl_num_cast!(int, to_int)
11501172
impl_num_cast!(f32, to_f32)
11511173
impl_num_cast!(f64, to_f64)
11521174

1153-
/// Saturating math operations
1154-
pub trait Saturating {
1155-
/// Saturating addition operator.
1156-
/// Returns a+b, saturating at the numeric bounds instead of overflowing.
1157-
fn saturating_add(self, v: Self) -> Self;
1158-
1159-
/// Saturating subtraction operator.
1160-
/// Returns a-b, saturating at the numeric bounds instead of overflowing.
1161-
fn saturating_sub(self, v: Self) -> Self;
1162-
}
1163-
1164-
impl<T: CheckedAdd + CheckedSub + Zero + PartialOrd + Bounded> Saturating for T {
1165-
#[inline]
1166-
fn saturating_add(self, v: T) -> T {
1167-
match self.checked_add(&v) {
1168-
Some(x) => x,
1169-
None => if v >= Zero::zero() {
1170-
Bounded::max_value()
1171-
} else {
1172-
Bounded::min_value()
1173-
}
1174-
}
1175-
}
1176-
1177-
#[inline]
1178-
fn saturating_sub(self, v: T) -> T {
1179-
match self.checked_sub(&v) {
1180-
Some(x) => x,
1181-
None => if v >= Zero::zero() {
1182-
Bounded::min_value()
1183-
} else {
1184-
Bounded::max_value()
1185-
}
1186-
}
1187-
}
1188-
}
1189-
11901175
/// Performs addition that returns `None` instead of wrapping around on overflow.
11911176
pub trait CheckedAdd: Add<Self, Self> {
11921177
/// Adds two numbers, checking for overflow. If overflow happens, `None` is returned.

branches/auto/src/libcore/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Less, Equal, Greater, Equiv}
4040
use cmp;
4141
use default::Default;
4242
use iter::*;
43-
use num::{CheckedAdd, Saturating, div_rem};
43+
use num::{CheckedAdd, Int, div_rem};
4444
use ops;
4545
use option::{None, Option, Some};
4646
use ptr;

branches/auto/src/libcore/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use iter::{Map, Iterator};
2525
use iter::{DoubleEndedIterator, ExactSize};
2626
use iter::range;
2727
use kinds::Sized;
28-
use num::{CheckedMul, Saturating};
28+
use num::{CheckedMul, Int};
2929
use option::{Option, None, Some};
3030
use raw::Repr;
3131
use slice::{mod, SlicePrelude};

branches/auto/src/libstd/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use option::Option;
2323
pub use core::num::{Num, div_rem, Zero, zero, One, one};
2424
pub use core::num::{Signed, abs, signum};
2525
pub use core::num::{Unsigned, pow, Bounded};
26-
pub use core::num::{Primitive, Int, UnsignedInt, Saturating};
26+
pub use core::num::{Primitive, Int, UnsignedInt};
2727
pub use core::num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
2828
pub use core::num::{cast, FromPrimitive, NumCast, ToPrimitive};
2929
pub use core::num::{next_power_of_two, is_power_of_two};

branches/auto/src/libtest/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ enum NamePadding { PadNone, PadOnLeft, PadOnRight }
106106

107107
impl TestDesc {
108108
fn padded_name(&self, column_count: uint, align: NamePadding) -> String {
109-
use std::num::Saturating;
110109
let mut name = String::from_str(self.name.as_slice());
111110
let fill = column_count.saturating_sub(name.len());
112111
let mut pad = " ".repeat(fill);

0 commit comments

Comments
 (0)