1
Fork 0

std: Remove Zero impl from vec

Vecs are not numeric types, so it doesn't make sense for them to
implement Zero.
This commit is contained in:
Erick Tryzelaar 2013-09-11 22:16:22 -07:00
parent a0e123eb6e
commit 43aba856b4
2 changed files with 7 additions and 25 deletions

View file

@ -107,7 +107,7 @@ use cmp;
use default::Default; use default::Default;
use iter::*; use iter::*;
use libc::c_void; use libc::c_void;
use num::{Integer, Zero, CheckedAdd, Saturating}; use num::{Integer, CheckedAdd, Saturating};
use option::{None, Option, Some}; use option::{None, Option, Some};
use ptr::to_unsafe_ptr; use ptr::to_unsafe_ptr;
use ptr; use ptr;
@ -2250,22 +2250,6 @@ impl<A> Default for @[A] {
fn default() -> @[A] { @[] } fn default() -> @[A] { @[] }
} }
// This works because every lifetime is a sub-lifetime of 'static
impl<'self, A> Zero for &'self [A] {
fn zero() -> &'self [A] { &'self [] }
fn is_zero(&self) -> bool { self.is_empty() }
}
impl<A> Zero for ~[A] {
fn zero() -> ~[A] { ~[] }
fn is_zero(&self) -> bool { self.len() == 0 }
}
impl<A> Zero for @[A] {
fn zero() -> @[A] { @[] }
fn is_zero(&self) -> bool { self.len() == 0 }
}
macro_rules! iterator { macro_rules! iterator {
/* FIXME: #4375 Cannot attach documentation/attributes to a macro generated struct. /* FIXME: #4375 Cannot attach documentation/attributes to a macro generated struct.
(struct $name:ident -> $ptr:ty, $elem:ty) => { (struct $name:ident -> $ptr:ty, $elem:ty) => {
@ -3602,13 +3586,12 @@ mod tests {
} }
#[test] #[test]
fn test_vec_zero() { fn test_vec_default() {
use num::Zero; use default::Default;
macro_rules! t ( macro_rules! t (
($ty:ty) => {{ ($ty:ty) => {{
let v: $ty = Zero::zero(); let v: $ty = Default::default();
assert!(v.is_empty()); assert!(v.is_empty());
assert!(v.is_zero());
}} }}
); );

View file

@ -29,10 +29,9 @@ struct Lots {
e: char, e: char,
f: float, f: float,
g: (f32, char), g: (f32, char),
h: ~[util::NonCopyable], h: @mut (int, int),
i: @mut (int, int), i: bool,
j: bool, j: (),
k: (),
} }
fn main() { fn main() {