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,11 +1036,7 @@ 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 {
use super::*;
// Signed is special because it actuall emits the negative sign, // Signed is special because it actuall emits the negative sign,
// nothing else should do that, however. // nothing else should do that, however.
impl Signed for $signed { impl Signed for $signed {
@ -1060,7 +1056,6 @@ macro_rules! integer(($signed:ident, $unsigned:ident) => {
int_base!($unsigned, $unsigned, 10, Unsigned, "") int_base!($unsigned, $unsigned, 10, Unsigned, "")
int_base!($unsigned, $unsigned, 16, LowerHex, "0x") int_base!($unsigned, $unsigned, 16, LowerHex, "0x")
upper_hex!($unsigned, $unsigned) 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,13 +34,6 @@ 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.
mod delegated {
use cmath::c_float_utils;
use libc::{c_float, c_int};
use unstable::intrinsics;
$( $(
#[inline] #[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv { pub fn $name($( $arg : $arg_ty ),*) -> $rv {
@ -48,7 +42,6 @@ macro_rules! delegate(
} }
} }
)* )*
}
) )
) )

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,13 +36,6 @@ 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.
mod delegated {
use cmath::c_double_utils;
use libc::{c_double, c_int};
use unstable::intrinsics;
$( $(
#[inline] #[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv { pub fn $name($( $arg : $arg_ty ),*) -> $rv {
@ -50,7 +44,6 @@ macro_rules! delegate(
} }
} }
)* )*
}
) )
) )

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,12 +87,6 @@ macro_rules! tuple_impls {
})+ })+
} }
)+) => { )+) => {
pub mod inner {
use clone::Clone;
#[cfg(not(test))] use cmp::*;
#[cfg(not(test))] use default::Default;
#[cfg(not(test))] use num::Zero;
$( $(
pub trait $move_trait<$($T),+> { pub trait $move_trait<$($T),+> {
$(fn $get_fn(self) -> $T;)+ $(fn $get_fn(self) -> $T;)+
@ -197,7 +192,6 @@ macro_rules! tuple_impls {
)+ )+
} }
} }
}
// Constructs an expression that performs a lexical ordering using method $rel. // Constructs an expression that performs a lexical ordering using method $rel.
// The values are interleaved, so the macro invocation for // The values are interleaved, so the macro invocation for

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.