Skip to content

Commit c8759f6

Browse files
committed
auto merge of #12090 : bjz/rust/unimplemented, r=cmr
Adds a standardised placeholder for marking unfinished code.
2 parents 3551851 + 8192f55 commit c8759f6

File tree

3 files changed

+105
-58
lines changed

3 files changed

+105
-58
lines changed

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)