Removed a few macro-expanding-to-module workarounds
Also documented a few issues
This commit is contained in:
parent
bf6964ecb6
commit
90f9eb3b1e
@ -1036,31 +1036,26 @@ pub fn upperhex(buf: &[u8], f: &mut Formatter) {
|
||||
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) => {
|
||||
mod $signed {
|
||||
use super::*;
|
||||
|
||||
// Signed is special because it actuall emits the negative sign,
|
||||
// nothing else should do that, however.
|
||||
impl Signed for $signed {
|
||||
fn fmt(c: &$signed, f: &mut Formatter) {
|
||||
::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
|
||||
f.pad_integral(buf, "", *c >= 0);
|
||||
})
|
||||
}
|
||||
// Signed is special because it actuall emits the negative sign,
|
||||
// nothing else should do that, however.
|
||||
impl Signed for $signed {
|
||||
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)
|
||||
|
@ -11,18 +11,19 @@
|
||||
//! Operations and constants for `f32`
|
||||
#[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 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 unstable::intrinsics;
|
||||
|
||||
pub use cmath::c_float_targ_consts::*;
|
||||
|
||||
use self::delegated::*;
|
||||
|
||||
macro_rules! delegate(
|
||||
(
|
||||
$(
|
||||
@ -33,22 +34,14 @@ macro_rules! delegate(
|
||||
) -> $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]
|
||||
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
|
||||
unsafe {
|
||||
$bound_name($( $arg ),*)
|
||||
}
|
||||
$(
|
||||
#[inline]
|
||||
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
|
||||
unsafe {
|
||||
$bound_name($( $arg ),*)
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
)*
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -12,19 +12,20 @@
|
||||
|
||||
#[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 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 unstable::intrinsics;
|
||||
|
||||
pub use cmath::c_double_targ_consts::*;
|
||||
pub use cmp::{min, max};
|
||||
|
||||
use self::delegated::*;
|
||||
|
||||
macro_rules! delegate(
|
||||
(
|
||||
$(
|
||||
@ -35,22 +36,14 @@ macro_rules! delegate(
|
||||
) -> $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]
|
||||
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
|
||||
unsafe {
|
||||
$bound_name($( $arg ),*)
|
||||
}
|
||||
$(
|
||||
#[inline]
|
||||
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
|
||||
unsafe {
|
||||
$bound_name($( $arg ),*)
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
)*
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -8,7 +8,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
|
||||
// FIXME(#4375): This shouldn't have to be a nested module named 'generated'...
|
||||
// FIXME(#10716): ... but now that we could solve that, the import lines and
|
||||
// attributes still prevent a removal of that module.
|
||||
|
||||
#[macro_escape];
|
||||
#[doc(hidden)];
|
||||
|
@ -8,7 +8,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
|
||||
// FIXME(#4375): This shouldn't have to be a nested module named 'generated'...
|
||||
// FIXME(#10716): ... but now that we could solve that, the import lines and
|
||||
// attributes still prevent a removal of that module.
|
||||
|
||||
#[macro_escape];
|
||||
#[doc(hidden)];
|
||||
|
@ -13,8 +13,9 @@
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use clone::Clone;
|
||||
|
||||
pub use self::inner::*;
|
||||
#[cfg(not(test))] use cmp::*;
|
||||
#[cfg(not(test))] use default::Default;
|
||||
#[cfg(not(test))] use num::Zero;
|
||||
|
||||
/// Method extensions to pairs where both types satisfy the `Clone` bound
|
||||
pub trait CopyableTuple<T, U> {
|
||||
@ -86,116 +87,109 @@ 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),+> {
|
||||
$(fn $get_fn(self) -> $T;)+
|
||||
}
|
||||
|
||||
$(
|
||||
pub trait $move_trait<$($T),+> {
|
||||
$(fn $get_fn(self) -> $T;)+
|
||||
}
|
||||
impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
|
||||
$(
|
||||
#[inline]
|
||||
fn $get_fn(self) -> $T {
|
||||
let $move_pattern = self;
|
||||
$ret
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
||||
impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
|
||||
$(
|
||||
#[inline]
|
||||
fn $get_fn(self) -> $T {
|
||||
let $move_pattern = self;
|
||||
$ret
|
||||
}
|
||||
)+
|
||||
}
|
||||
pub trait $immutable_trait<$($T),+> {
|
||||
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
|
||||
}
|
||||
|
||||
pub trait $immutable_trait<$($T),+> {
|
||||
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
|
||||
}
|
||||
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
|
||||
$(
|
||||
#[inline]
|
||||
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
|
||||
let $ref_pattern = *self;
|
||||
$ret
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
||||
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
|
||||
$(
|
||||
#[inline]
|
||||
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
|
||||
let $ref_pattern = *self;
|
||||
$ret
|
||||
}
|
||||
)+
|
||||
impl<$($T:Clone),+> Clone for ($($T,)+) {
|
||||
fn clone(&self) -> ($($T,)+) {
|
||||
($(self.$get_ref_fn().clone(),)+)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($T:Clone),+> Clone for ($($T,)+) {
|
||||
fn clone(&self) -> ($($T,)+) {
|
||||
($(self.$get_ref_fn().clone(),)+)
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:Eq),+> Eq for ($($T,)+) {
|
||||
#[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))]
|
||||
impl<$($T:Eq),+> Eq for ($($T,)+) {
|
||||
#[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))]
|
||||
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
|
||||
#[inline]
|
||||
fn equals(&self, other: &($($T,)+)) -> bool {
|
||||
$(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
|
||||
#[inline]
|
||||
fn equals(&self, other: &($($T,)+)) -> bool {
|
||||
$(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
|
||||
#[inline]
|
||||
fn lt(&self, other: &($($T,)+)) -> bool {
|
||||
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))]
|
||||
impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
|
||||
#[inline]
|
||||
fn lt(&self, other: &($($T,)+)) -> bool {
|
||||
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))]
|
||||
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &($($T,)+)) -> Ordering {
|
||||
lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &($($T,)+)) -> Ordering {
|
||||
lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:Default),+> Default for ($($T,)+) {
|
||||
#[inline]
|
||||
fn default() -> ($($T,)+) {
|
||||
($({ let x: $T = Default::default(); x},)+)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:Default),+> Default for ($($T,)+) {
|
||||
#[inline]
|
||||
fn default() -> ($($T,)+) {
|
||||
($({ let x: $T = Default::default(); x},)+)
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:Zero),+> Zero for ($($T,)+) {
|
||||
#[inline]
|
||||
fn zero() -> ($($T,)+) {
|
||||
($({ let x: $T = Zero::zero(); x},)+)
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl<$($T:Zero),+> Zero for ($($T,)+) {
|
||||
#[inline]
|
||||
fn zero() -> ($($T,)+) {
|
||||
($({ let x: $T = Zero::zero(); x},)+)
|
||||
}
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
$(self.$get_ref_fn().is_zero())&&+
|
||||
}
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
$(self.$get_ref_fn().is_zero())&&+
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2463,15 +2463,14 @@ impl<A> Default for @[A] {
|
||||
}
|
||||
|
||||
macro_rules! iterator {
|
||||
/* FIXME: #4375 Cannot attach documentation/attributes to a macro generated struct.
|
||||
(struct $name:ident -> $ptr:ty, $elem:ty) => {
|
||||
/// An iterator for iterating over a vector.
|
||||
pub struct $name<'self, T> {
|
||||
priv ptr: $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> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<$elem> {
|
||||
@ -2502,11 +2501,7 @@ macro_rules! iterator {
|
||||
(exact, Some(exact))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! double_ended_iterator {
|
||||
(impl $name:ident -> $elem:ty) => {
|
||||
impl<'self, T> DoubleEndedIterator<$elem> for $name<'self, T> {
|
||||
#[inline]
|
||||
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}
|
||||
/// 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}
|
||||
iterator!{struct VecIterator -> *T, &'self T}
|
||||
pub type RevIterator<'self, T> = Invert<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 }
|
||||
}
|
||||
|
||||
//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}
|
||||
iterator!{struct VecMutIterator -> *mut T, &'self mut T}
|
||||
pub type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>;
|
||||
|
||||
/// An iterator that moves out of a vector.
|
||||
|
Loading…
x
Reference in New Issue
Block a user