Skip to content

Commit 4cf3072

Browse files
committed
auto merge of #8026 : poiru/rust/issue-8024, r=alexcrichton
Closes #8024.
2 parents 906264b + f73bb2b commit 4cf3072

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/libstd/bool.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Implementations of the following traits:
2424
* `Ord`
2525
* `TotalOrd`
2626
* `Eq`
27+
* `Zero`
2728
2829
## Various functions to compare `bool`s
2930
@@ -36,14 +37,14 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.
3637
3738
*/
3839

39-
#[cfg(not(test))]
40-
use cmp::{Eq, Ord, TotalOrd, Ordering};
41-
#[cfg(not(test))]
42-
use ops::Not;
4340
use option::{None, Option, Some};
4441
use from_str::FromStr;
4542
use to_str::ToStr;
4643

44+
#[cfg(not(test))] use cmp::{Eq, Ord, TotalOrd, Ordering};
45+
#[cfg(not(test))] use ops::Not;
46+
#[cfg(not(test))] use num::Zero;
47+
4748
/**
4849
* Negation of a boolean value.
4950
*
@@ -330,6 +331,12 @@ impl Eq for bool {
330331
fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
331332
}
332333

334+
#[cfg(not(test))]
335+
impl Zero for bool {
336+
fn zero() -> bool { false }
337+
fn is_zero(&self) -> bool { *self == false }
338+
}
339+
333340
#[cfg(test)]
334341
mod tests {
335342
use super::*;

src/test/run-pass/deriving-zero.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct Lots {
3333
g: (f32, char),
3434
h: ~[util::NonCopyable],
3535
i: @mut (int, int),
36+
j: bool,
3637
}
3738

3839
fn main() {

0 commit comments

Comments
 (0)