From a5912736be38ff10e41b475634119f83b937a072 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Wed, 31 Jul 2013 18:19:26 +0400 Subject: [PATCH] Implement Zero for unit --- src/libstd/nil.rs | 11 +++++++++++ src/test/run-pass/deriving-zero.rs | 1 + 2 files changed, 12 insertions(+) diff --git a/src/libstd/nil.rs b/src/libstd/nil.rs index 40f6d53ed22..81b7662e581 100644 --- a/src/libstd/nil.rs +++ b/src/libstd/nil.rs @@ -16,6 +16,10 @@ Functions for the unit type. #[cfg(not(test))] use prelude::*; +#[cfg(not(test))] +use num::Zero; + + #[cfg(not(test))] impl Eq for () { @@ -48,3 +52,10 @@ impl TotalEq for () { #[inline] fn equals(&self, _other: &()) -> bool { true } } + +#[cfg(not(test))] +impl Zero for () { + fn zero() -> () { () } + fn is_zero(&self) -> bool { true } +} + diff --git a/src/test/run-pass/deriving-zero.rs b/src/test/run-pass/deriving-zero.rs index f2c5a7e94ef..54895d1796f 100644 --- a/src/test/run-pass/deriving-zero.rs +++ b/src/test/run-pass/deriving-zero.rs @@ -34,6 +34,7 @@ struct Lots { h: ~[util::NonCopyable], i: @mut (int, int), j: bool, + k: (), } fn main() {