Skip to content

Commit 8192f55

Browse files
committed
Clean up formatting in macros module
1 parent 1e55cae commit 8192f55

File tree

1 file changed

+74
-58
lines changed

1 file changed

+74
-58
lines changed

src/libstd/macros.rs

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,33 @@ macro_rules! log(
2020
}
2121
})
2222
)
23+
2324
#[macro_export]
24-
macro_rules! error( ($($arg:tt)*) => (log!(1u32, $($arg)*)) )
25+
macro_rules! error(
26+
($($arg:tt)*) => (log!(1u32, $($arg)*))
27+
)
28+
2529
#[macro_export]
26-
macro_rules! warn ( ($($arg:tt)*) => (log!(2u32, $($arg)*)) )
30+
macro_rules! warn(
31+
($($arg:tt)*) => (log!(2u32, $($arg)*))
32+
)
33+
2734
#[macro_export]
28-
macro_rules! info ( ($($arg:tt)*) => (log!(3u32, $($arg)*)) )
35+
macro_rules! info(
36+
($($arg:tt)*) => (log!(3u32, $($arg)*))
37+
)
38+
2939
#[macro_export]
30-
macro_rules! debug( ($($arg:tt)*) => (
31-
if cfg!(not(ndebug)) { log!(4u32, $($arg)*) }
32-
))
40+
macro_rules! debug(
41+
($($arg:tt)*) => (if cfg!(not(ndebug)) { log!(4u32, $($arg)*) })
42+
)
3343

3444
#[macro_export]
3545
macro_rules! log_enabled(
36-
($lvl:expr) => ( {
46+
($lvl:expr) => ({
3747
let lvl = $lvl;
3848
lvl <= __log_level() && (lvl != 4 || cfg!(not(ndebug)))
39-
} )
49+
})
4050
)
4151

4252
#[macro_export]
@@ -47,54 +57,50 @@ macro_rules! fail(
4757
($msg:expr) => (
4858
::std::rt::begin_unwind($msg, file!(), line!())
4959
);
50-
($fmt:expr, $($arg:tt)*) => (
51-
{
52-
// a closure can't have return type !, so we need a full
53-
// function to pass to format_args!, *and* we need the
54-
// file and line numbers right here; so an inner bare fn
55-
// is our only choice.
56-
#[inline]
57-
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
58-
::std::rt::begin_unwind_fmt(fmt, file!(), line!())
59-
}
60-
format_args!(run_fmt, $fmt, $($arg)*)
60+
($fmt:expr, $($arg:tt)*) => ({
61+
// a closure can't have return type !, so we need a full
62+
// function to pass to format_args!, *and* we need the
63+
// file and line numbers right here; so an inner bare fn
64+
// is our only choice.
65+
#[inline]
66+
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
67+
::std::rt::begin_unwind_fmt(fmt, file!(), line!())
6168
}
62-
)
69+
format_args!(run_fmt, $fmt, $($arg)*)
70+
});
6371
)
6472

6573
#[macro_export]
6674
macro_rules! assert(
67-
($cond:expr) => {
75+
($cond:expr) => (
6876
if !$cond {
6977
fail!("assertion failed: {:s}", stringify!($cond))
7078
}
71-
};
72-
($cond:expr, $msg:expr) => {
79+
);
80+
($cond:expr, $msg:expr) => (
7381
if !$cond {
7482
fail!($msg)
7583
}
76-
};
77-
($cond:expr, $( $arg:expr ),+) => {
84+
);
85+
($cond:expr, $($arg:expr),+) => (
7886
if !$cond {
79-
fail!( $($arg),+ )
87+
fail!($($arg),+)
8088
}
81-
}
89+
);
8290
)
8391

8492
#[macro_export]
85-
macro_rules! assert_eq (
86-
($given:expr , $expected:expr) => (
87-
{
88-
let given_val = &($given);
89-
let expected_val = &($expected);
90-
// check both directions of equality....
91-
if !((*given_val == *expected_val) &&
92-
(*expected_val == *given_val)) {
93-
fail!("assertion failed: `(left == right) && (right == left)` \
94-
(left: `{:?}`, right: `{:?}`)", *given_val, *expected_val)
95-
}
93+
macro_rules! assert_eq(
94+
($given:expr , $expected:expr) => ({
95+
let given_val = &($given);
96+
let expected_val = &($expected);
97+
// check both directions of equality....
98+
if !((*given_val == *expected_val) &&
99+
(*expected_val == *given_val)) {
100+
fail!("assertion failed: `(left == right) && (right == left)` \
101+
(left: `{:?}`, right: `{:?}`)", *given_val, *expected_val)
96102
}
97-
)
103+
})
98104
)
99105

100106
/// A utility macro for indicating unreachable code. It will fail if
@@ -103,7 +109,7 @@ macro_rules! assert_eq (
103109
///
104110
/// # Example
105111
///
106-
/// ```rust
112+
/// ~~~rust
107113
/// fn choose_weighted_item(v: &[Item]) -> Item {
108114
/// assert!(!v.is_empty());
109115
/// let mut so_far = 0u;
@@ -117,11 +123,11 @@ macro_rules! assert_eq (
117123
/// // type checker that it isn't possible to get down here
118124
/// unreachable!();
119125
/// }
120-
/// ```
126+
/// ~~~
121127
#[macro_export]
122-
macro_rules! unreachable (() => (
123-
fail!("internal error: entered unreachable code");
124-
))
128+
macro_rules! unreachable(
129+
() => (fail!("internal error: entered unreachable code"))
130+
)
125131

126132
/// A standardised placeholder for marking unfinished code. It fails with the
127133
/// message `"not yet implemented"` when executed.
@@ -131,37 +137,47 @@ macro_rules! unimplemented(
131137
)
132138

133139
#[macro_export]
134-
macro_rules! format(($($arg:tt)*) => (
135-
format_args!(::std::fmt::format, $($arg)*)
136-
))
140+
macro_rules! format(
141+
($($arg:tt)*) => (
142+
format_args!(::std::fmt::format, $($arg)*)
143+
)
144+
)
145+
137146
#[macro_export]
138-
macro_rules! write(($dst:expr, $($arg:tt)*) => (
139-
format_args!(|args| { ::std::fmt::write($dst, args) }, $($arg)*)
140-
))
147+
macro_rules! write(
148+
($dst:expr, $($arg:tt)*) => (
149+
format_args!(|args| { ::std::fmt::write($dst, args) }, $($arg)*)
150+
)
151+
)
152+
141153
#[macro_export]
142-
macro_rules! writeln(($dst:expr, $($arg:tt)*) => (
143-
format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*)
144-
))
154+
macro_rules! writeln(
155+
($dst:expr, $($arg:tt)*) => (
156+
format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*)
157+
)
158+
)
159+
145160
#[macro_export]
146-
macro_rules! print (
161+
macro_rules! print(
147162
($($arg:tt)*) => (format_args!(::std::io::stdio::print_args, $($arg)*))
148163
)
164+
149165
#[macro_export]
150-
macro_rules! println (
166+
macro_rules! println(
151167
($($arg:tt)*) => (format_args!(::std::io::stdio::println_args, $($arg)*))
152168
)
153169

154170
#[macro_export]
155-
macro_rules! local_data_key (
171+
macro_rules! local_data_key(
156172
($name:ident: $ty:ty) => (
157173
static $name: ::std::local_data::Key<$ty> = &::std::local_data::Key;
158174
);
159175
(pub $name:ident: $ty:ty) => (
160176
pub static $name: ::std::local_data::Key<$ty> = &::std::local_data::Key;
161-
)
177+
);
162178
)
163179

164180
#[macro_export]
165-
macro_rules! if_ok (
181+
macro_rules! if_ok(
166182
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
167183
)

0 commit comments

Comments
 (0)