Skip to content

Commit 9573703

Browse files
committed
---
yaml --- r: 149013 b: refs/heads/try2 c: cba7ac5 h: refs/heads/master i: 149011: 60580d9 v: v3
1 parent 2f17834 commit 9573703

File tree

4 files changed

+106
-59
lines changed

4 files changed

+106
-59
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ee3fa68fed13e7b8cde523e4bc73b9a07d082212
8+
refs/heads/try2: cba7ac5e014e7e225a4e226f15e9c05563d6e4a9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/macros.rs

Lines changed: 81 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,44 +123,61 @@ macro_rules! assert_eq (
117123
/// // type checker that it isn't possible to get down here
118124
/// unreachable!();
119125
/// }
120-
/// ```
126+
/// ~~~
127+
#[macro_export]
128+
macro_rules! unreachable(
129+
() => (fail!("internal error: entered unreachable code"))
130+
)
131+
132+
/// A standardised placeholder for marking unfinished code. It fails with the
133+
/// message `"not yet implemented"` when executed.
121134
#[macro_export]
122-
macro_rules! unreachable (() => (
123-
fail!("internal error: entered unreachable code");
124-
))
135+
macro_rules! unimplemented(
136+
() => (fail!("not yet implemented"))
137+
)
125138

126139
#[macro_export]
127-
macro_rules! format(($($arg:tt)*) => (
128-
format_args!(::std::fmt::format, $($arg)*)
129-
))
140+
macro_rules! format(
141+
($($arg:tt)*) => (
142+
format_args!(::std::fmt::format, $($arg)*)
143+
)
144+
)
145+
130146
#[macro_export]
131-
macro_rules! write(($dst:expr, $($arg:tt)*) => (
132-
format_args!(|args| { ::std::fmt::write($dst, args) }, $($arg)*)
133-
))
147+
macro_rules! write(
148+
($dst:expr, $($arg:tt)*) => (
149+
format_args!(|args| { ::std::fmt::write($dst, args) }, $($arg)*)
150+
)
151+
)
152+
134153
#[macro_export]
135-
macro_rules! writeln(($dst:expr, $($arg:tt)*) => (
136-
format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*)
137-
))
154+
macro_rules! writeln(
155+
($dst:expr, $($arg:tt)*) => (
156+
format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*)
157+
)
158+
)
159+
138160
#[macro_export]
139-
macro_rules! print (
161+
macro_rules! print(
140162
($($arg:tt)*) => (format_args!(::std::io::stdio::print_args, $($arg)*))
141163
)
164+
142165
#[macro_export]
143-
macro_rules! println (
166+
macro_rules! println(
144167
($($arg:tt)*) => (format_args!(::std::io::stdio::println_args, $($arg)*))
145168
)
146169

147170
#[macro_export]
148-
macro_rules! local_data_key (
171+
macro_rules! local_data_key(
149172
($name:ident: $ty:ty) => (
150173
static $name: ::std::local_data::Key<$ty> = &::std::local_data::Key;
151174
);
152175
(pub $name:ident: $ty:ty) => (
153176
pub static $name: ::std::local_data::Key<$ty> = &::std::local_data::Key;
154-
)
177+
);
155178
)
156179

157180
#[macro_export]
158-
macro_rules! if_ok (
181+
macro_rules! if_ok(
159182
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
160183
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:not yet implemented
12+
fn main() { unimplemented!() }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:internal error: entered unreachable code
12+
fn main() { unreachable!() }

0 commit comments

Comments
 (0)