Skip to content

Commit d3adc66

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 114559 b: refs/heads/master c: 28a4ee5 h: refs/heads/master i: 114557: adcca13 114555: 93e6f4b 114551: 5354f5d 114543: 9a551ca 114527: ab4dbab 114495: eba572b 114431: 2f791d2 v: v3
1 parent 66ca3cc commit d3adc66

File tree

22 files changed

+1404
-639
lines changed

22 files changed

+1404
-639
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e865415c2fe2c0e83fe1955238db082a1374c380
2+
refs/heads/master: 28a4ee5eeb6a7450f5c16b902504992e990c7042
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/libcore/bool.rs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,28 @@
1010

1111
//! Operations on boolean values (`bool` type)
1212
//!
13+
//! A quick summary:
14+
//!
15+
//! Implementations of the following traits:
16+
//!
17+
//! * `Not`
18+
//! * `BitAnd`
19+
//! * `BitOr`
20+
//! * `BitXor`
21+
//! * `Ord`
22+
//! * `TotalOrd`
23+
//! * `Eq`
24+
//! * `TotalEq`
25+
//! * `Default`
26+
//!
1327
//! A `to_bit` conversion function.
1428
1529
use num::{Int, one, zero};
1630

31+
#[cfg(not(test))] use cmp::{Eq, Ord, TotalOrd, Ordering, TotalEq};
32+
#[cfg(not(test))] use ops::{Not, BitAnd, BitOr, BitXor};
33+
#[cfg(not(test))] use default::Default;
34+
1735
/////////////////////////////////////////////////////////////////////////////
1836
// Freestanding functions
1937
/////////////////////////////////////////////////////////////////////////////
@@ -33,6 +51,131 @@ pub fn to_bit<N: Int>(p: bool) -> N {
3351
if p { one() } else { zero() }
3452
}
3553

54+
/////////////////////////////////////////////////////////////////////////////
55+
// Trait impls on `bool`
56+
/////////////////////////////////////////////////////////////////////////////
57+
58+
#[cfg(not(test))]
59+
impl Not<bool> for bool {
60+
/// The logical complement of a boolean value.
61+
///
62+
/// # Examples
63+
///
64+
/// ```rust
65+
/// assert_eq!(!true, false);
66+
/// assert_eq!(!false, true);
67+
/// ```
68+
#[inline]
69+
fn not(&self) -> bool { !*self }
70+
}
71+
72+
#[cfg(not(test))]
73+
impl BitAnd<bool, bool> for bool {
74+
/// Conjunction of two boolean values.
75+
///
76+
/// # Examples
77+
///
78+
/// ```rust
79+
/// assert_eq!(false.bitand(&false), false);
80+
/// assert_eq!(true.bitand(&false), false);
81+
/// assert_eq!(false.bitand(&true), false);
82+
/// assert_eq!(true.bitand(&true), true);
83+
///
84+
/// assert_eq!(false & false, false);
85+
/// assert_eq!(true & false, false);
86+
/// assert_eq!(false & true, false);
87+
/// assert_eq!(true & true, true);
88+
/// ```
89+
#[inline]
90+
fn bitand(&self, b: &bool) -> bool { *self & *b }
91+
}
92+
93+
#[cfg(not(test))]
94+
impl BitOr<bool, bool> for bool {
95+
/// Disjunction of two boolean values.
96+
///
97+
/// # Examples
98+
///
99+
/// ```rust
100+
/// assert_eq!(false.bitor(&false), false);
101+
/// assert_eq!(true.bitor(&false), true);
102+
/// assert_eq!(false.bitor(&true), true);
103+
/// assert_eq!(true.bitor(&true), true);
104+
///
105+
/// assert_eq!(false | false, false);
106+
/// assert_eq!(true | false, true);
107+
/// assert_eq!(false | true, true);
108+
/// assert_eq!(true | true, true);
109+
/// ```
110+
#[inline]
111+
fn bitor(&self, b: &bool) -> bool { *self | *b }
112+
}
113+
114+
#[cfg(not(test))]
115+
impl BitXor<bool, bool> for bool {
116+
/// An 'exclusive or' of two boolean values.
117+
///
118+
/// 'exclusive or' is identical to `or(and(a, not(b)), and(not(a), b))`.
119+
///
120+
/// # Examples
121+
///
122+
/// ```rust
123+
/// assert_eq!(false.bitxor(&false), false);
124+
/// assert_eq!(true.bitxor(&false), true);
125+
/// assert_eq!(false.bitxor(&true), true);
126+
/// assert_eq!(true.bitxor(&true), false);
127+
///
128+
/// assert_eq!(false ^ false, false);
129+
/// assert_eq!(true ^ false, true);
130+
/// assert_eq!(false ^ true, true);
131+
/// assert_eq!(true ^ true, false);
132+
/// ```
133+
#[inline]
134+
fn bitxor(&self, b: &bool) -> bool { *self ^ *b }
135+
}
136+
137+
#[cfg(not(test))]
138+
impl Ord for bool {
139+
#[inline]
140+
fn lt(&self, other: &bool) -> bool {
141+
to_bit::<u8>(*self) < to_bit(*other)
142+
}
143+
}
144+
145+
#[cfg(not(test))]
146+
impl TotalOrd for bool {
147+
#[inline]
148+
fn cmp(&self, other: &bool) -> Ordering {
149+
to_bit::<u8>(*self).cmp(&to_bit(*other))
150+
}
151+
}
152+
153+
/// Equality between two boolean values.
154+
///
155+
/// Two booleans are equal if they have the same value.
156+
///
157+
/// # Examples
158+
///
159+
/// ```rust
160+
/// assert_eq!(false.eq(&true), false);
161+
/// assert_eq!(false == false, true);
162+
/// assert_eq!(false != true, true);
163+
/// assert_eq!(false.ne(&false), false);
164+
/// ```
165+
#[cfg(not(test))]
166+
impl Eq for bool {
167+
#[inline]
168+
fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
169+
}
170+
171+
#[cfg(not(test))]
172+
impl TotalEq for bool {}
173+
174+
#[cfg(not(test))]
175+
impl Default for bool {
176+
fn default() -> bool { false }
177+
}
178+
36179
#[cfg(test)]
37180
mod tests {
38181
use realstd::prelude::*;

trunk/src/libcore/cell.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ mod test {
482482
}
483483

484484
#[test]
485+
#[allow(experimental)]
485486
fn clone_ref_updates_flag() {
486487
let x = RefCell::new(0);
487488
{

trunk/src/libcore/char.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub use unicode::normalization::decompose_canonical;
3434
/// Returns the compatibility decomposition of a character.
3535
pub use unicode::normalization::decompose_compatible;
3636

37+
#[cfg(not(test))] use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering};
38+
#[cfg(not(test))] use default::Default;
39+
3740
// UTF-8 ranges and tags for encoding characters
3841
static TAG_CONT: u8 = 0b1000_0000u8;
3942
static TAG_TWO_B: u8 = 0b1100_0000u8;
@@ -598,6 +601,33 @@ impl Char for char {
598601
}
599602
}
600603

604+
#[cfg(not(test))]
605+
impl Eq for char {
606+
#[inline]
607+
fn eq(&self, other: &char) -> bool { (*self) == (*other) }
608+
}
609+
610+
#[cfg(not(test))]
611+
impl TotalEq for char {}
612+
613+
#[cfg(not(test))]
614+
impl Ord for char {
615+
#[inline]
616+
fn lt(&self, other: &char) -> bool { *self < *other }
617+
}
618+
619+
#[cfg(not(test))]
620+
impl TotalOrd for char {
621+
fn cmp(&self, other: &char) -> Ordering {
622+
(*self as u32).cmp(&(*other as u32))
623+
}
624+
}
625+
626+
#[cfg(not(test))]
627+
impl Default for char {
628+
#[inline]
629+
fn default() -> char { '\x00' }
630+
}
601631

602632
#[cfg(test)]
603633
mod test {

trunk/src/libcore/cmp.rs

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -189,95 +189,27 @@ pub fn max<T: TotalOrd>(v1: T, v2: T) -> T {
189189
if v1 > v2 { v1 } else { v2 }
190190
}
191191

192-
// Implementation of Eq, TotalEq, Ord and TotalOrd for primitive types
192+
// Implementation of Eq/TotalEq for some primitive types
193193
#[cfg(not(test))]
194194
mod impls {
195-
use cmp::{Ord, TotalOrd, Eq, TotalEq, Ordering, Less, Greater, Equal};
196-
197-
macro_rules! eq_impl(
198-
($($t:ty)*) => ($(
199-
impl Eq for $t {
200-
#[inline]
201-
fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
202-
#[inline]
203-
fn ne(&self, other: &$t) -> bool { (*self) != (*other) }
204-
}
205-
)*)
206-
)
195+
use cmp::{Ord, TotalOrd, Eq, TotalEq, Ordering, Equal};
207196

208197
impl Eq for () {
209198
#[inline]
210199
fn eq(&self, _other: &()) -> bool { true }
211200
#[inline]
212201
fn ne(&self, _other: &()) -> bool { false }
213202
}
214-
215-
eq_impl!(bool char uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
216-
217-
macro_rules! totaleq_impl(
218-
($($t:ty)*) => ($(
219-
impl TotalEq for $t {}
220-
)*)
221-
)
222-
223-
totaleq_impl!(() bool char uint u8 u16 u32 u64 int i8 i16 i32 i64)
224-
225-
macro_rules! ord_impl(
226-
($($t:ty)*) => ($(
227-
impl Ord for $t {
228-
#[inline]
229-
fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
230-
#[inline]
231-
fn le(&self, other: &$t) -> bool { (*self) <= (*other) }
232-
#[inline]
233-
fn ge(&self, other: &$t) -> bool { (*self) >= (*other) }
234-
#[inline]
235-
fn gt(&self, other: &$t) -> bool { (*self) > (*other) }
236-
}
237-
)*)
238-
)
239-
203+
impl TotalEq for () {}
240204
impl Ord for () {
241205
#[inline]
242206
fn lt(&self, _other: &()) -> bool { false }
243207
}
244-
245-
impl Ord for bool {
246-
#[inline]
247-
fn lt(&self, other: &bool) -> bool {
248-
(*self as u8) < (*other as u8)
249-
}
250-
}
251-
252-
ord_impl!(char uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
253-
254-
macro_rules! totalord_impl(
255-
($($t:ty)*) => ($(
256-
impl TotalOrd for $t {
257-
#[inline]
258-
fn cmp(&self, other: &$t) -> Ordering {
259-
if *self < *other { Less }
260-
else if *self > *other { Greater }
261-
else { Equal }
262-
}
263-
}
264-
)*)
265-
)
266-
267208
impl TotalOrd for () {
268209
#[inline]
269210
fn cmp(&self, _other: &()) -> Ordering { Equal }
270211
}
271212

272-
impl TotalOrd for bool {
273-
#[inline]
274-
fn cmp(&self, other: &bool) -> Ordering {
275-
(*self as u8).cmp(&(*other as u8))
276-
}
277-
}
278-
279-
totalord_impl!(char uint u8 u16 u32 u64 int i8 i16 i32 i64)
280-
281213
// & pointers
282214
impl<'a, T: Eq> Eq for &'a T {
283215
#[inline]

trunk/src/libcore/default.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,10 @@ pub trait Default {
1616
fn default() -> Self;
1717
}
1818

19-
macro_rules! default_impl(
20-
($t:ty, $v:expr) => {
21-
impl Default for $t {
22-
#[inline]
23-
fn default() -> $t { $v }
24-
}
25-
}
26-
)
27-
28-
default_impl!((), ())
29-
default_impl!(bool, false)
30-
default_impl!(char, '\x00')
31-
32-
default_impl!(uint, 0u)
33-
default_impl!(u8, 0u8)
34-
default_impl!(u16, 0u16)
35-
default_impl!(u32, 0u32)
36-
default_impl!(u64, 0u64)
37-
38-
default_impl!(int, 0i)
39-
default_impl!(i8, 0i8)
40-
default_impl!(i16, 0i16)
41-
default_impl!(i32, 0i32)
42-
default_impl!(i64, 0i64)
43-
44-
default_impl!(f32, 0.0f32)
45-
default_impl!(f64, 0.0f64)
19+
impl Default for () {
20+
#[inline]
21+
fn default() -> () { () }
22+
}
4623

4724
impl<T: Default + 'static> Default for @T {
4825
fn default() -> @T { @Default::default() }

0 commit comments

Comments
 (0)