auto merge of #10719 : Kimundi/rust/switch_to_multi_item_macros, r=alexcrichton

- Removed module reexport workaround for the integer module macros
- Removed legacy reexports of `cmp::{min, max}` in the integer module macros
- Combined a few macros in `vec` into one
- Documented a few issues
This commit is contained in:
bors 2013-11-29 14:01:48 -08:00
commit 80991bb578
19 changed files with 261 additions and 273 deletions

View File

@ -10,32 +10,31 @@
use back::{link}; use back::{link};
use std::libc::c_uint;
use lib::llvm::{ValueRef, CallConv, StructRetAttribute};
use lib::llvm::llvm; use lib::llvm::llvm;
use lib::llvm::{ValueRef, CallConv, StructRetAttribute};
use lib; use lib;
use middle::trans::machine;
use middle::trans::base;
use middle::trans::base::push_ctxt; use middle::trans::base::push_ctxt;
use middle::trans::cabi; use middle::trans::base;
use middle::trans::build::*; use middle::trans::build::*;
use middle::trans::builder::noname; use middle::trans::builder::noname;
use middle::trans::cabi;
use middle::trans::common::*; use middle::trans::common::*;
use middle::trans::machine;
use middle::trans::type_::Type;
use middle::trans::type_of::*; use middle::trans::type_of::*;
use middle::trans::type_of; use middle::trans::type_of;
use middle::ty;
use middle::ty::FnSig; use middle::ty::FnSig;
use middle::ty;
use std::uint; use std::cmp;
use std::libc::c_uint;
use std::vec; use std::vec;
use syntax::abi::{Cdecl, Aapcs, C, AbiSet, Win64};
use syntax::abi::{RustIntrinsic, Rust, Stdcall, Fastcall, System};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::parse::token::special_idents;
use syntax::{ast}; use syntax::{ast};
use syntax::{attr, ast_map}; use syntax::{attr, ast_map};
use syntax::parse::token::special_idents;
use syntax::abi::{RustIntrinsic, Rust, Stdcall, Fastcall, System,
Cdecl, Aapcs, C, AbiSet, Win64};
use util::ppaux::{Repr, UserString}; use util::ppaux::{Repr, UserString};
use middle::trans::type_::Type;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Type definitions // Type definitions
@ -332,7 +331,7 @@ pub fn trans_native_call(bcx: @mut Block,
let llrust_size = machine::llsize_of_store(ccx, llrust_ret_ty); let llrust_size = machine::llsize_of_store(ccx, llrust_ret_ty);
let llforeign_align = machine::llalign_of_min(ccx, llforeign_ret_ty); let llforeign_align = machine::llalign_of_min(ccx, llforeign_ret_ty);
let llrust_align = machine::llalign_of_min(ccx, llrust_ret_ty); let llrust_align = machine::llalign_of_min(ccx, llrust_ret_ty);
let llalign = uint::min(llforeign_align, llrust_align); let llalign = cmp::min(llforeign_align, llrust_align);
debug!("llrust_size={:?}", llrust_size); debug!("llrust_size={:?}", llrust_size);
base::call_memcpy(bcx, llretptr_i8, llscratch_i8, base::call_memcpy(bcx, llretptr_i8, llscratch_i8,
C_uint(ccx, llrust_size), llalign as u32); C_uint(ccx, llrust_size), llalign as u32);

View File

@ -901,7 +901,7 @@ impl<'self> Formatter<'self> {
// case where the maximum length will matter. // case where the maximum length will matter.
let char_len = s.char_len(); let char_len = s.char_len();
if char_len >= max { if char_len >= max {
let nchars = ::uint::min(max, char_len); let nchars = ::cmp::min(max, char_len);
self.buf.write(s.slice_chars(0, nchars).as_bytes()); self.buf.write(s.slice_chars(0, nchars).as_bytes());
return return
} }
@ -1036,31 +1036,26 @@ pub fn upperhex(buf: &[u8], f: &mut Formatter) {
f.pad_integral(local.slice_to(buf.len()), "0x", true); f.pad_integral(local.slice_to(buf.len()), "0x", true);
} }
// FIXME(#4375) shouldn't need an inner module
macro_rules! integer(($signed:ident, $unsigned:ident) => { macro_rules! integer(($signed:ident, $unsigned:ident) => {
mod $signed { // Signed is special because it actuall emits the negative sign,
use super::*; // nothing else should do that, however.
impl Signed for $signed {
// Signed is special because it actuall emits the negative sign, fn fmt(c: &$signed, f: &mut Formatter) {
// nothing else should do that, however. ::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
impl Signed for $signed { f.pad_integral(buf, "", *c >= 0);
fn fmt(c: &$signed, f: &mut Formatter) { })
::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
f.pad_integral(buf, "", *c >= 0);
})
}
} }
int_base!($signed, $unsigned, 2, Binary, "0b")
int_base!($signed, $unsigned, 8, Octal, "0o")
int_base!($signed, $unsigned, 16, LowerHex, "0x")
upper_hex!($signed, $unsigned)
int_base!($unsigned, $unsigned, 2, Binary, "0b")
int_base!($unsigned, $unsigned, 8, Octal, "0o")
int_base!($unsigned, $unsigned, 10, Unsigned, "")
int_base!($unsigned, $unsigned, 16, LowerHex, "0x")
upper_hex!($unsigned, $unsigned)
} }
int_base!($signed, $unsigned, 2, Binary, "0b")
int_base!($signed, $unsigned, 8, Octal, "0o")
int_base!($signed, $unsigned, 16, LowerHex, "0x")
upper_hex!($signed, $unsigned)
int_base!($unsigned, $unsigned, 2, Binary, "0b")
int_base!($unsigned, $unsigned, 8, Octal, "0o")
int_base!($unsigned, $unsigned, 10, Unsigned, "")
int_base!($unsigned, $unsigned, 16, LowerHex, "0x")
upper_hex!($unsigned, $unsigned)
}) })
integer!(int, uint) integer!(int, uint)

View File

@ -11,18 +11,19 @@
//! Operations and constants for `f32` //! Operations and constants for `f32`
#[allow(missing_doc)]; #[allow(missing_doc)];
use default::Default;
use libc::c_int;
use num::{Zero, One, strconv};
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num;
use prelude::*; use prelude::*;
use cmath::c_float_utils;
use default::Default;
use libc::{c_float, c_int};
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num::{Zero, One, strconv};
use num;
use to_str; use to_str;
use unstable::intrinsics;
pub use cmath::c_float_targ_consts::*; pub use cmath::c_float_targ_consts::*;
use self::delegated::*;
macro_rules! delegate( macro_rules! delegate(
( (
$( $(
@ -33,22 +34,14 @@ macro_rules! delegate(
) -> $rv:ty = $bound_name:path ) -> $rv:ty = $bound_name:path
),* ),*
) => ( ) => (
// An inner module is required to get the #[inline] attribute on the $(
// functions. #[inline]
mod delegated { pub fn $name($( $arg : $arg_ty ),*) -> $rv {
use cmath::c_float_utils; unsafe {
use libc::{c_float, c_int}; $bound_name($( $arg ),*)
use unstable::intrinsics;
$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
} }
)* }
} )*
) )
) )

View File

@ -12,19 +12,20 @@
#[allow(missing_doc)]; #[allow(missing_doc)];
use default::Default;
use libc::c_int;
use num::{Zero, One, strconv};
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num;
use prelude::*; use prelude::*;
use cmath::c_double_utils;
use default::Default;
use libc::{c_double, c_int};
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num::{Zero, One, strconv};
use num;
use to_str; use to_str;
use unstable::intrinsics;
pub use cmath::c_double_targ_consts::*; pub use cmath::c_double_targ_consts::*;
pub use cmp::{min, max}; pub use cmp::{min, max};
use self::delegated::*;
macro_rules! delegate( macro_rules! delegate(
( (
$( $(
@ -35,22 +36,14 @@ macro_rules! delegate(
) -> $rv:ty = $bound_name:path ) -> $rv:ty = $bound_name:path
),* ),*
) => ( ) => (
// An inner module is required to get the #[inline] attribute on the $(
// functions. #[inline]
mod delegated { pub fn $name($( $arg : $arg_ty ),*) -> $rv {
use cmath::c_double_utils; unsafe {
use libc::{c_double, c_int}; $bound_name($( $arg ),*)
use unstable::intrinsics;
$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
} }
)* }
} )*
) )
) )

View File

@ -10,11 +10,17 @@
//! Operations and constants for `i16` //! Operations and constants for `i16`
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul}; #[allow(non_uppercase_statics)];
use option::{Option, Some, None};
use unstable::intrinsics;
pub use self::generated::*; use prelude::*;
use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;
int_module!(i16, 16) int_module!(i16, 16)

View File

@ -10,11 +10,17 @@
//! Operations and constants for `i32` //! Operations and constants for `i32`
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul}; #[allow(non_uppercase_statics)];
use option::{Option, Some, None};
use unstable::intrinsics;
pub use self::generated::*; use prelude::*;
use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;
int_module!(i32, 32) int_module!(i32, 32)

View File

@ -10,14 +10,20 @@
//! Operations and constants for `i64` //! Operations and constants for `i64`
use num::{BitCount, CheckedAdd, CheckedSub}; #[allow(non_uppercase_statics)];
use prelude::*;
use default::Default;
#[cfg(target_word_size = "64")] #[cfg(target_word_size = "64")]
use num::CheckedMul; use num::CheckedMul;
use num::{BitCount, CheckedAdd, CheckedSub};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None}; use option::{Option, Some, None};
use str;
use unstable::intrinsics; use unstable::intrinsics;
pub use self::generated::*;
int_module!(i64, 64) int_module!(i64, 64)
impl BitCount for i64 { impl BitCount for i64 {

View File

@ -10,11 +10,17 @@
//! Operations and constants for `i8` //! Operations and constants for `i8`
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul}; #[allow(non_uppercase_statics)];
use option::{Option, Some, None};
use unstable::intrinsics;
pub use self::generated::*; use prelude::*;
use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;
int_module!(i8, 8) int_module!(i8, 8)

View File

@ -12,16 +12,18 @@
#[allow(non_uppercase_statics)]; #[allow(non_uppercase_statics)];
use prelude::*;
use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul}; use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None}; use option::{Option, Some, None};
use str;
use unstable::intrinsics; use unstable::intrinsics;
pub use self::generated::*; #[cfg(target_word_size = "32")] int_module!(int, 32)
#[cfg(target_word_size = "64")] int_module!(int, 64)
#[cfg(target_word_size = "32")] pub static bits: uint = 32;
#[cfg(target_word_size = "64")] pub static bits: uint = 64;
int_module!(int, super::bits)
#[cfg(target_word_size = "32")] #[cfg(target_word_size = "32")]
impl BitCount for int { impl BitCount for int {

View File

@ -8,22 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
#[macro_escape]; #[macro_escape];
#[doc(hidden)]; #[doc(hidden)];
macro_rules! int_module (($T:ty, $bits:expr) => (mod generated { macro_rules! int_module (($T:ty, $bits:expr) => (
#[allow(non_uppercase_statics)];
use default::Default;
use num::{ToStrRadix, FromStrRadix};
use num::{CheckedDiv, Zero, One, strconv};
use prelude::*;
use str;
pub use cmp::{min, max};
pub static bits : uint = $bits; pub static bits : uint = $bits;
pub static bytes : uint = ($bits / 8); pub static bytes : uint = ($bits / 8);
@ -781,4 +769,4 @@ mod tests {
} }
} }
})) ))

View File

@ -10,11 +10,18 @@
//! Operations and constants for `u16` //! Operations and constants for `u16`
use num::{CheckedAdd, CheckedSub, CheckedMul}; #[allow(non_uppercase_statics)];
use option::{Option, Some, None};
use unstable::intrinsics;
pub use self::generated::*; use prelude::*;
use default::Default;
use num::BitCount;
use num::{CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;
uint_module!(u16, i16, 16) uint_module!(u16, i16, 16)

View File

@ -10,11 +10,18 @@
//! Operations and constants for `u32` //! Operations and constants for `u32`
use num::{CheckedAdd, CheckedSub, CheckedMul}; #[allow(non_uppercase_statics)];
use option::{Option, Some, None};
use unstable::intrinsics;
pub use self::generated::*; use prelude::*;
use default::Default;
use num::BitCount;
use num::{CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;
uint_module!(u32, i32, 32) uint_module!(u32, i32, 32)

View File

@ -10,14 +10,21 @@
//! Operations and constants for `u64` //! Operations and constants for `u64`
use num::{CheckedAdd, CheckedSub}; #[allow(non_uppercase_statics)];
use prelude::*;
use default::Default;
use num::BitCount;
#[cfg(target_word_size = "64")] #[cfg(target_word_size = "64")]
use num::CheckedMul; use num::CheckedMul;
use num::{CheckedAdd, CheckedSub};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None}; use option::{Option, Some, None};
use str;
use unstable::intrinsics; use unstable::intrinsics;
pub use self::generated::*;
uint_module!(u64, i64, 64) uint_module!(u64, i64, 64)
impl CheckedAdd for u64 { impl CheckedAdd for u64 {

View File

@ -10,11 +10,18 @@
//! Operations and constants for `u8` //! Operations and constants for `u8`
use num::{CheckedAdd, CheckedSub, CheckedMul}; #[allow(non_uppercase_statics)];
use option::{Option, Some, None};
use unstable::intrinsics;
pub use self::generated::*; use prelude::*;
use default::Default;
use num::BitCount;
use num::{CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;
uint_module!(u8, i8, 8) uint_module!(u8, i8, 8)

View File

@ -10,13 +10,20 @@
//! Operations and constants for `uint` //! Operations and constants for `uint`
use num; #[allow(non_uppercase_statics)];
use num::{CheckedAdd, CheckedSub, CheckedMul};
use option::{Option, Some, None};
use unstable::intrinsics;
use mem;
pub use self::generated::*; use prelude::*;
use default::Default;
use mem;
use num::BitCount;
use num::{CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use num;
use option::{Option, Some, None};
use str;
use unstable::intrinsics;
uint_module!(uint, int, ::int::bits) uint_module!(uint, int, ::int::bits)

View File

@ -8,23 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
#[macro_escape]; #[macro_escape];
#[doc(hidden)]; #[doc(hidden)];
macro_rules! uint_module (($T:ty, $T_SIGNED:ty, $bits:expr) => (mod generated { macro_rules! uint_module (($T:ty, $T_SIGNED:ty, $bits:expr) => (
#[allow(non_uppercase_statics)];
use default::Default;
use num::BitCount;
use num::{ToStrRadix, FromStrRadix};
use num::{CheckedDiv, Zero, One, strconv};
use prelude::*;
use str;
pub use cmp::{min, max};
pub static bits : uint = $bits; pub static bits : uint = $bits;
pub static bytes : uint = ($bits / 8); pub static bytes : uint = ($bits / 8);
@ -554,4 +541,4 @@ mod tests {
} }
} }
})) ))

View File

@ -17,7 +17,6 @@ use io::stdio::StdWriter;
use io::buffered::LineBufferedWriter; use io::buffered::LineBufferedWriter;
use rt::crate_map::{ModEntry, CrateMap, iter_crate_map, get_crate_map}; use rt::crate_map::{ModEntry, CrateMap, iter_crate_map, get_crate_map};
use str::StrSlice; use str::StrSlice;
use u32;
use vec::ImmutableVector; use vec::ImmutableVector;
#[cfg(test)] use cast::transmute; #[cfg(test)] use cast::transmute;
@ -46,7 +45,7 @@ fn parse_log_level(level: &str) -> Option<u32> {
let position = log_level_names.iter().position(|&name| name == level); let position = log_level_names.iter().position(|&name| name == level);
match position { match position {
Some(position) => { Some(position) => {
log_level = Some(u32::min(MAX_LOG_LEVEL, (position + 1) as u32)) log_level = Some(::cmp::min(MAX_LOG_LEVEL, (position + 1) as u32))
}, },
_ => { _ => {
log_level = None; log_level = None;

View File

@ -13,8 +13,9 @@
#[allow(missing_doc)]; #[allow(missing_doc)];
use clone::Clone; use clone::Clone;
#[cfg(not(test))] use cmp::*;
pub use self::inner::*; #[cfg(not(test))] use default::Default;
#[cfg(not(test))] use num::Zero;
/// Method extensions to pairs where both types satisfy the `Clone` bound /// Method extensions to pairs where both types satisfy the `Clone` bound
pub trait CopyableTuple<T, U> { pub trait CopyableTuple<T, U> {
@ -86,116 +87,109 @@ macro_rules! tuple_impls {
})+ })+
} }
)+) => { )+) => {
pub mod inner { $(
use clone::Clone; pub trait $move_trait<$($T),+> {
#[cfg(not(test))] use cmp::*; $(fn $get_fn(self) -> $T;)+
#[cfg(not(test))] use default::Default; }
#[cfg(not(test))] use num::Zero;
$( impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
pub trait $move_trait<$($T),+> { $(
$(fn $get_fn(self) -> $T;)+ #[inline]
} fn $get_fn(self) -> $T {
let $move_pattern = self;
$ret
}
)+
}
impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) { pub trait $immutable_trait<$($T),+> {
$( $(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
#[inline] }
fn $get_fn(self) -> $T {
let $move_pattern = self;
$ret
}
)+
}
pub trait $immutable_trait<$($T),+> { impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+ $(
} #[inline]
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
let $ref_pattern = *self;
$ret
}
)+
}
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) { impl<$($T:Clone),+> Clone for ($($T,)+) {
$( fn clone(&self) -> ($($T,)+) {
#[inline] ($(self.$get_ref_fn().clone(),)+)
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
let $ref_pattern = *self;
$ret
}
)+
} }
}
impl<$($T:Clone),+> Clone for ($($T,)+) { #[cfg(not(test))]
fn clone(&self) -> ($($T,)+) { impl<$($T:Eq),+> Eq for ($($T,)+) {
($(self.$get_ref_fn().clone(),)+) #[inline]
} fn eq(&self, other: &($($T,)+)) -> bool {
$(*self.$get_ref_fn() == *other.$get_ref_fn())&&+
} }
#[inline]
fn ne(&self, other: &($($T,)+)) -> bool {
$(*self.$get_ref_fn() != *other.$get_ref_fn())||+
}
}
#[cfg(not(test))] #[cfg(not(test))]
impl<$($T:Eq),+> Eq for ($($T,)+) { impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
#[inline] #[inline]
fn eq(&self, other: &($($T,)+)) -> bool { fn equals(&self, other: &($($T,)+)) -> bool {
$(*self.$get_ref_fn() == *other.$get_ref_fn())&&+ $(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+
}
#[inline]
fn ne(&self, other: &($($T,)+)) -> bool {
$(*self.$get_ref_fn() != *other.$get_ref_fn())||+
}
} }
}
#[cfg(not(test))] #[cfg(not(test))]
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) { impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
#[inline] #[inline]
fn equals(&self, other: &($($T,)+)) -> bool { fn lt(&self, other: &($($T,)+)) -> bool {
$(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+ lexical_ord!(lt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
} }
#[inline]
fn le(&self, other: &($($T,)+)) -> bool {
lexical_ord!(le, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
#[inline]
fn ge(&self, other: &($($T,)+)) -> bool {
lexical_ord!(ge, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
#[inline]
fn gt(&self, other: &($($T,)+)) -> bool {
lexical_ord!(gt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
}
#[cfg(not(test))] #[cfg(not(test))]
impl<$($T:Ord + Eq),+> Ord for ($($T,)+) { impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
#[inline] #[inline]
fn lt(&self, other: &($($T,)+)) -> bool { fn cmp(&self, other: &($($T,)+)) -> Ordering {
lexical_ord!(lt, $(self.$get_ref_fn(), other.$get_ref_fn()),+) lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
#[inline]
fn le(&self, other: &($($T,)+)) -> bool {
lexical_ord!(le, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
#[inline]
fn ge(&self, other: &($($T,)+)) -> bool {
lexical_ord!(ge, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
#[inline]
fn gt(&self, other: &($($T,)+)) -> bool {
lexical_ord!(gt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
}
} }
}
#[cfg(not(test))] #[cfg(not(test))]
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) { impl<$($T:Default),+> Default for ($($T,)+) {
#[inline] #[inline]
fn cmp(&self, other: &($($T,)+)) -> Ordering { fn default() -> ($($T,)+) {
lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+) ($({ let x: $T = Default::default(); x},)+)
}
} }
}
#[cfg(not(test))] #[cfg(not(test))]
impl<$($T:Default),+> Default for ($($T,)+) { impl<$($T:Zero),+> Zero for ($($T,)+) {
#[inline] #[inline]
fn default() -> ($($T,)+) { fn zero() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+) ($({ let x: $T = Zero::zero(); x},)+)
}
} }
#[inline]
#[cfg(not(test))] fn is_zero(&self) -> bool {
impl<$($T:Zero),+> Zero for ($($T,)+) { $(self.$get_ref_fn().is_zero())&&+
#[inline]
fn zero() -> ($($T,)+) {
($({ let x: $T = Zero::zero(); x},)+)
}
#[inline]
fn is_zero(&self) -> bool {
$(self.$get_ref_fn().is_zero())&&+
}
} }
)+ }
} )+
} }
} }

View File

@ -2463,15 +2463,14 @@ impl<A> Default for @[A] {
} }
macro_rules! iterator { macro_rules! iterator {
/* 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) => {
/// An iterator for iterating over a vector.
pub struct $name<'self, T> { pub struct $name<'self, T> {
priv ptr: $ptr, priv ptr: $ptr,
priv end: $ptr, priv end: $ptr,
priv lifetime: $elem // FIXME: #5922 priv lifetime: Option<$elem> // FIXME: #5922
} }
};*/
(impl $name:ident -> $elem:ty) => {
impl<'self, T> Iterator<$elem> for $name<'self, T> { impl<'self, T> Iterator<$elem> for $name<'self, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<$elem> { fn next(&mut self) -> Option<$elem> {
@ -2502,11 +2501,7 @@ macro_rules! iterator {
(exact, Some(exact)) (exact, Some(exact))
} }
} }
}
}
macro_rules! double_ended_iterator {
(impl $name:ident -> $elem:ty) => {
impl<'self, T> DoubleEndedIterator<$elem> for $name<'self, T> { impl<'self, T> DoubleEndedIterator<$elem> for $name<'self, T> {
#[inline] #[inline]
fn next_back(&mut self) -> Option<$elem> { fn next_back(&mut self) -> Option<$elem> {
@ -2548,15 +2543,7 @@ impl<'self, T> RandomAccessIterator<&'self T> for VecIterator<'self, T> {
} }
} }
//iterator!{struct VecIterator -> *T, &'self T} iterator!{struct VecIterator -> *T, &'self T}
/// An iterator for iterating over a vector.
pub struct VecIterator<'self, T> {
priv ptr: *T,
priv end: *T,
priv lifetime: Option<&'self ()> // FIXME: #5922
}
iterator!{impl VecIterator -> &'self T}
double_ended_iterator!{impl VecIterator -> &'self T}
pub type RevIterator<'self, T> = Invert<VecIterator<'self, T>>; pub type RevIterator<'self, T> = Invert<VecIterator<'self, T>>;
impl<'self, T> ExactSize<&'self T> for VecIterator<'self, T> {} impl<'self, T> ExactSize<&'self T> for VecIterator<'self, T> {}
@ -2566,15 +2553,7 @@ impl<'self, T> Clone for VecIterator<'self, T> {
fn clone(&self) -> VecIterator<'self, T> { *self } fn clone(&self) -> VecIterator<'self, T> { *self }
} }
//iterator!{struct VecMutIterator -> *mut T, &'self mut T} iterator!{struct VecMutIterator -> *mut T, &'self mut T}
/// An iterator for mutating the elements of a vector.
pub struct VecMutIterator<'self, T> {
priv ptr: *mut T,
priv end: *mut T,
priv lifetime: Option<&'self mut ()> // FIXME: #5922
}
iterator!{impl VecMutIterator -> &'self mut T}
double_ended_iterator!{impl VecMutIterator -> &'self mut T}
pub type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>; pub type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>;
/// An iterator that moves out of a vector. /// An iterator that moves out of a vector.