Skip to content

Commit 90f9eb3

Browse files
committed
Removed a few macro-expanding-to-module workarounds
Also documented a few issues
1 parent bf6964e commit 90f9eb3

File tree

7 files changed

+143
-185
lines changed

7 files changed

+143
-185
lines changed

src/libstd/fmt/mod.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -1036,31 +1036,26 @@ pub fn upperhex(buf: &[u8], f: &mut Formatter) {
10361036
f.pad_integral(local.slice_to(buf.len()), "0x", true);
10371037
}
10381038

1039-
// FIXME(#4375) shouldn't need an inner module
10401039
macro_rules! integer(($signed:ident, $unsigned:ident) => {
1041-
mod $signed {
1042-
use super::*;
1043-
1044-
// Signed is special because it actuall emits the negative sign,
1045-
// nothing else should do that, however.
1046-
impl Signed for $signed {
1047-
fn fmt(c: &$signed, f: &mut Formatter) {
1048-
::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
1049-
f.pad_integral(buf, "", *c >= 0);
1050-
})
1051-
}
1040+
// Signed is special because it actuall emits the negative sign,
1041+
// nothing else should do that, however.
1042+
impl Signed for $signed {
1043+
fn fmt(c: &$signed, f: &mut Formatter) {
1044+
::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
1045+
f.pad_integral(buf, "", *c >= 0);
1046+
})
10521047
}
1053-
int_base!($signed, $unsigned, 2, Binary, "0b")
1054-
int_base!($signed, $unsigned, 8, Octal, "0o")
1055-
int_base!($signed, $unsigned, 16, LowerHex, "0x")
1056-
upper_hex!($signed, $unsigned)
1057-
1058-
int_base!($unsigned, $unsigned, 2, Binary, "0b")
1059-
int_base!($unsigned, $unsigned, 8, Octal, "0o")
1060-
int_base!($unsigned, $unsigned, 10, Unsigned, "")
1061-
int_base!($unsigned, $unsigned, 16, LowerHex, "0x")
1062-
upper_hex!($unsigned, $unsigned)
10631048
}
1049+
int_base!($signed, $unsigned, 2, Binary, "0b")
1050+
int_base!($signed, $unsigned, 8, Octal, "0o")
1051+
int_base!($signed, $unsigned, 16, LowerHex, "0x")
1052+
upper_hex!($signed, $unsigned)
1053+
1054+
int_base!($unsigned, $unsigned, 2, Binary, "0b")
1055+
int_base!($unsigned, $unsigned, 8, Octal, "0o")
1056+
int_base!($unsigned, $unsigned, 10, Unsigned, "")
1057+
int_base!($unsigned, $unsigned, 16, LowerHex, "0x")
1058+
upper_hex!($unsigned, $unsigned)
10641059
})
10651060

10661061
integer!(int, uint)

src/libstd/num/f32.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
//! Operations and constants for `f32`
1212
#[allow(missing_doc)];
1313

14+
use prelude::*;
15+
16+
use cmath::c_float_utils;
1417
use default::Default;
15-
use libc::c_int;
16-
use num::{Zero, One, strconv};
18+
use libc::{c_float, c_int};
1719
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
20+
use num::{Zero, One, strconv};
1821
use num;
19-
use prelude::*;
2022
use to_str;
23+
use unstable::intrinsics;
2124

2225
pub use cmath::c_float_targ_consts::*;
2326

24-
use self::delegated::*;
25-
2627
macro_rules! delegate(
2728
(
2829
$(
@@ -33,22 +34,14 @@ macro_rules! delegate(
3334
) -> $rv:ty = $bound_name:path
3435
),*
3536
) => (
36-
// An inner module is required to get the #[inline] attribute on the
37-
// functions.
38-
mod delegated {
39-
use cmath::c_float_utils;
40-
use libc::{c_float, c_int};
41-
use unstable::intrinsics;
42-
43-
$(
44-
#[inline]
45-
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
46-
unsafe {
47-
$bound_name($( $arg ),*)
48-
}
37+
$(
38+
#[inline]
39+
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
40+
unsafe {
41+
$bound_name($( $arg ),*)
4942
}
50-
)*
51-
}
43+
}
44+
)*
5245
)
5346
)
5447

src/libstd/num/f64.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
1313
#[allow(missing_doc)];
1414

15+
use prelude::*;
16+
17+
use cmath::c_double_utils;
1518
use default::Default;
16-
use libc::c_int;
17-
use num::{Zero, One, strconv};
19+
use libc::{c_double, c_int};
1820
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
21+
use num::{Zero, One, strconv};
1922
use num;
20-
use prelude::*;
2123
use to_str;
24+
use unstable::intrinsics;
2225

2326
pub use cmath::c_double_targ_consts::*;
2427
pub use cmp::{min, max};
2528

26-
use self::delegated::*;
27-
2829
macro_rules! delegate(
2930
(
3031
$(
@@ -35,22 +36,14 @@ macro_rules! delegate(
3536
) -> $rv:ty = $bound_name:path
3637
),*
3738
) => (
38-
// An inner module is required to get the #[inline] attribute on the
39-
// functions.
40-
mod delegated {
41-
use cmath::c_double_utils;
42-
use libc::{c_double, c_int};
43-
use unstable::intrinsics;
44-
45-
$(
46-
#[inline]
47-
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
48-
unsafe {
49-
$bound_name($( $arg ),*)
50-
}
39+
$(
40+
#[inline]
41+
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
42+
unsafe {
43+
$bound_name($( $arg ),*)
5144
}
52-
)*
53-
}
45+
}
46+
)*
5447
)
5548
)
5649

src/libstd/num/int_macros.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
11+
// FIXME(#4375): This shouldn't have to be a nested module named 'generated'...
12+
// FIXME(#10716): ... but now that we could solve that, the import lines and
13+
// attributes still prevent a removal of that module.
1214

1315
#[macro_escape];
1416
#[doc(hidden)];

src/libstd/num/uint_macros.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
11+
// FIXME(#4375): This shouldn't have to be a nested module named 'generated'...
12+
// FIXME(#10716): ... but now that we could solve that, the import lines and
13+
// attributes still prevent a removal of that module.
1214

1315
#[macro_escape];
1416
#[doc(hidden)];

src/libstd/tuple.rs

+89-95
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#[allow(missing_doc)];
1414

1515
use clone::Clone;
16-
17-
pub use self::inner::*;
16+
#[cfg(not(test))] use cmp::*;
17+
#[cfg(not(test))] use default::Default;
18+
#[cfg(not(test))] use num::Zero;
1819

1920
/// Method extensions to pairs where both types satisfy the `Clone` bound
2021
pub trait CopyableTuple<T, U> {
@@ -86,116 +87,109 @@ macro_rules! tuple_impls {
8687
})+
8788
}
8889
)+) => {
89-
pub mod inner {
90-
use clone::Clone;
91-
#[cfg(not(test))] use cmp::*;
92-
#[cfg(not(test))] use default::Default;
93-
#[cfg(not(test))] use num::Zero;
94-
95-
$(
96-
pub trait $move_trait<$($T),+> {
97-
$(fn $get_fn(self) -> $T;)+
98-
}
90+
$(
91+
pub trait $move_trait<$($T),+> {
92+
$(fn $get_fn(self) -> $T;)+
93+
}
9994

100-
impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
101-
$(
102-
#[inline]
103-
fn $get_fn(self) -> $T {
104-
let $move_pattern = self;
105-
$ret
106-
}
107-
)+
108-
}
109-
110-
pub trait $immutable_trait<$($T),+> {
111-
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
112-
}
95+
impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
96+
$(
97+
#[inline]
98+
fn $get_fn(self) -> $T {
99+
let $move_pattern = self;
100+
$ret
101+
}
102+
)+
103+
}
113104

114-
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
115-
$(
116-
#[inline]
117-
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
118-
let $ref_pattern = *self;
119-
$ret
120-
}
121-
)+
122-
}
105+
pub trait $immutable_trait<$($T),+> {
106+
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
107+
}
123108

124-
impl<$($T:Clone),+> Clone for ($($T,)+) {
125-
fn clone(&self) -> ($($T,)+) {
126-
($(self.$get_ref_fn().clone(),)+)
109+
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
110+
$(
111+
#[inline]
112+
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
113+
let $ref_pattern = *self;
114+
$ret
127115
}
116+
)+
117+
}
118+
119+
impl<$($T:Clone),+> Clone for ($($T,)+) {
120+
fn clone(&self) -> ($($T,)+) {
121+
($(self.$get_ref_fn().clone(),)+)
128122
}
123+
}
129124

130-
#[cfg(not(test))]
131-
impl<$($T:Eq),+> Eq for ($($T,)+) {
132-
#[inline]
133-
fn eq(&self, other: &($($T,)+)) -> bool {
134-
$(*self.$get_ref_fn() == *other.$get_ref_fn())&&+
135-
}
136-
#[inline]
137-
fn ne(&self, other: &($($T,)+)) -> bool {
138-
$(*self.$get_ref_fn() != *other.$get_ref_fn())||+
139-
}
125+
#[cfg(not(test))]
126+
impl<$($T:Eq),+> Eq for ($($T,)+) {
127+
#[inline]
128+
fn eq(&self, other: &($($T,)+)) -> bool {
129+
$(*self.$get_ref_fn() == *other.$get_ref_fn())&&+
130+
}
131+
#[inline]
132+
fn ne(&self, other: &($($T,)+)) -> bool {
133+
$(*self.$get_ref_fn() != *other.$get_ref_fn())||+
140134
}
135+
}
141136

142-
#[cfg(not(test))]
143-
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
144-
#[inline]
145-
fn equals(&self, other: &($($T,)+)) -> bool {
146-
$(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+
147-
}
137+
#[cfg(not(test))]
138+
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
139+
#[inline]
140+
fn equals(&self, other: &($($T,)+)) -> bool {
141+
$(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+
148142
}
143+
}
149144

150-
#[cfg(not(test))]
151-
impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
152-
#[inline]
153-
fn lt(&self, other: &($($T,)+)) -> bool {
154-
lexical_ord!(lt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
155-
}
156-
#[inline]
157-
fn le(&self, other: &($($T,)+)) -> bool {
158-
lexical_ord!(le, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
159-
}
160-
#[inline]
161-
fn ge(&self, other: &($($T,)+)) -> bool {
162-
lexical_ord!(ge, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
163-
}
164-
#[inline]
165-
fn gt(&self, other: &($($T,)+)) -> bool {
166-
lexical_ord!(gt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
167-
}
145+
#[cfg(not(test))]
146+
impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
147+
#[inline]
148+
fn lt(&self, other: &($($T,)+)) -> bool {
149+
lexical_ord!(lt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
150+
}
151+
#[inline]
152+
fn le(&self, other: &($($T,)+)) -> bool {
153+
lexical_ord!(le, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
154+
}
155+
#[inline]
156+
fn ge(&self, other: &($($T,)+)) -> bool {
157+
lexical_ord!(ge, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
168158
}
159+
#[inline]
160+
fn gt(&self, other: &($($T,)+)) -> bool {
161+
lexical_ord!(gt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
162+
}
163+
}
169164

170-
#[cfg(not(test))]
171-
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
172-
#[inline]
173-
fn cmp(&self, other: &($($T,)+)) -> Ordering {
174-
lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
175-
}
165+
#[cfg(not(test))]
166+
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
167+
#[inline]
168+
fn cmp(&self, other: &($($T,)+)) -> Ordering {
169+
lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
176170
}
171+
}
177172

178-
#[cfg(not(test))]
179-
impl<$($T:Default),+> Default for ($($T,)+) {
180-
#[inline]
181-
fn default() -> ($($T,)+) {
182-
($({ let x: $T = Default::default(); x},)+)
183-
}
173+
#[cfg(not(test))]
174+
impl<$($T:Default),+> Default for ($($T,)+) {
175+
#[inline]
176+
fn default() -> ($($T,)+) {
177+
($({ let x: $T = Default::default(); x},)+)
184178
}
179+
}
185180

186-
#[cfg(not(test))]
187-
impl<$($T:Zero),+> Zero for ($($T,)+) {
188-
#[inline]
189-
fn zero() -> ($($T,)+) {
190-
($({ let x: $T = Zero::zero(); x},)+)
191-
}
192-
#[inline]
193-
fn is_zero(&self) -> bool {
194-
$(self.$get_ref_fn().is_zero())&&+
195-
}
181+
#[cfg(not(test))]
182+
impl<$($T:Zero),+> Zero for ($($T,)+) {
183+
#[inline]
184+
fn zero() -> ($($T,)+) {
185+
($({ let x: $T = Zero::zero(); x},)+)
196186
}
197-
)+
198-
}
187+
#[inline]
188+
fn is_zero(&self) -> bool {
189+
$(self.$get_ref_fn().is_zero())&&+
190+
}
191+
}
192+
)+
199193
}
200194
}
201195

0 commit comments

Comments
 (0)