Skip to content

Commit

Permalink
Modernize macro_rules! invocations
Browse files Browse the repository at this point in the history
macro_rules! is like an item that defines a macro.  Other items don't have a
trailing semicolon, or use a paren-delimited body.

If there's an argument for matching the invocation syntax, e.g. parentheses for
an expr macro, then I think that applies more strongly to the *inner*
delimiters on the LHS, wrapping the individual argument patterns.
  • Loading branch information
Keegan McAllister committed Jan 6, 2015
1 parent c9f0ff3 commit 416137e
Show file tree
Hide file tree
Showing 76 changed files with 361 additions and 331 deletions.
4 changes: 2 additions & 2 deletions src/grammar/verify.rs
Expand Up @@ -268,7 +268,7 @@ fn main() {
assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok,
antlr_tok);

macro_rules! matches (
macro_rules! matches {
( $($x:pat),+ ) => (
match rustc_tok.tok {
$($x => match antlr_tok.tok {
Expand All @@ -284,7 +284,7 @@ fn main() {
ref c => assert!(c == &antlr_tok.tok, "{} is not {}", rustc_tok, antlr_tok)
}
)
);
}

matches!(
token::Literal(token::Byte(..), _),
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/slice.rs
Expand Up @@ -2460,13 +2460,13 @@ mod tests {

#[test]
fn test_show() {
macro_rules! test_show_vec(
macro_rules! test_show_vec {
($x:expr, $x_str:expr) => ({
let (x, x_str) = ($x, $x_str);
assert_eq!(format!("{}", x), x_str);
assert_eq!(format!("{}", x.as_slice()), x_str);
})
);
}
let empty: Vec<int> = vec![];
test_show_vec!(empty, "[]");
test_show_vec!(vec![1i], "[1]");
Expand All @@ -2486,12 +2486,12 @@ mod tests {

#[test]
fn test_vec_default() {
macro_rules! t (
macro_rules! t {
($ty:ty) => {{
let v: $ty = Default::default();
assert!(v.is_empty());
}}
);
}

t!(&[int]);
t!(Vec<int>);
Expand Down
8 changes: 6 additions & 2 deletions src/libcollections/str.rs
Expand Up @@ -1838,7 +1838,9 @@ mod tests {
#[test]
fn test_is_utf16() {
use unicode::str::is_utf16;
macro_rules! pos ( ($($e:expr),*) => { { $(assert!(is_utf16($e));)* } });
macro_rules! pos {
($($e:expr),*) => { { $(assert!(is_utf16($e));)* } }
}

// non-surrogates
pos!(&[0x0000],
Expand All @@ -1858,7 +1860,9 @@ mod tests {
&[0x0067, 0xd8ff, 0xddb7, 0x000f, 0xd900, 0xdc80]);

// negative tests
macro_rules! neg ( ($($e:expr),*) => { { $(assert!(!is_utf16($e));)* } });
macro_rules! neg {
($($e:expr),*) => { { $(assert!(!is_utf16($e));)* } }
}

neg!(
// surrogate + regular unit
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/string.rs
Expand Up @@ -182,15 +182,15 @@ impl String {
let byte = unsafe_get(v, i);
i += 1;

macro_rules! error(() => ({
macro_rules! error { () => ({
unsafe {
if subseqidx != i_ {
res.as_mut_vec().push_all(v[subseqidx..i_]);
}
subseqidx = i;
res.as_mut_vec().push_all(REPLACEMENT);
}
}));
})}

if byte < 128u8 {
// subseqidx handles this
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/result.rs
Expand Up @@ -220,9 +220,9 @@
//!
//! ```
//! # #![feature(macro_rules)]
//! macro_rules! try(
//! macro_rules! try {
//! ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
//! );
//! }
//! # fn main() { }
//! ```
//!
Expand Down
9 changes: 5 additions & 4 deletions src/libcore/str/mod.rs
Expand Up @@ -948,17 +948,18 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter<u8>)
let old = *iter;

// restore the iterator we had at the start of this codepoint.
macro_rules! err (() => { {
macro_rules! err { () => {{
*iter = old;
return Err(Utf8Error::InvalidByte(whole.len() - iter.as_slice().len()))
} });
macro_rules! next ( () => {
}}}

macro_rules! next { () => {
match iter.next() {
Some(a) => *a,
// we needed data, but there was none: error!
None => return Err(Utf8Error::TooShort),
}
});
}}

let first = match iter.next() {
Some(&b) => b,
Expand Down
4 changes: 2 additions & 2 deletions src/libcoretest/num/int_macros.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

macro_rules! int_module (($T:ty, $T_i:ident) => (
macro_rules! int_module { ($T:ty, $T_i:ident) => (
#[cfg(test)]
mod tests {
use core::$T_i::*;
Expand Down Expand Up @@ -203,4 +203,4 @@ mod tests {
}
}

));
)}
5 changes: 3 additions & 2 deletions src/libcoretest/num/uint_macros.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

macro_rules! uint_module (($T:ty, $T_i:ident) => (
macro_rules! uint_module { ($T:ty, $T_i:ident) => (
#[cfg(test)]
mod tests {
use core::$T_i::*;
Expand Down Expand Up @@ -123,4 +123,5 @@ mod tests {
assert!(5u.checked_div(0) == None);
}
}
));

)}
4 changes: 2 additions & 2 deletions src/librand/distributions/mod.rs
Expand Up @@ -297,7 +297,7 @@ mod tests {
// it doesn't do weird things to the RNG (so 0 maps to 0, 1 to
// 1, internally; modulo a modulo operation).

macro_rules! t (
macro_rules! t {
($items:expr, $expected:expr) => {{
let mut items = $items;
let wc = WeightedChoice::new(items.as_mut_slice());
Expand All @@ -309,7 +309,7 @@ mod tests {
assert_eq!(wc.ind_sample(&mut rng), val)
}
}}
);
}

t!(vec!(Weighted { weight: 1, item: 10i}), [10]);

Expand Down
8 changes: 4 additions & 4 deletions src/librand/distributions/range.rs
Expand Up @@ -182,7 +182,7 @@ mod tests {
#[test]
fn test_integers() {
let mut rng = ::test::rng();
macro_rules! t (
macro_rules! t {
($($ty:ty),*) => {{
$(
let v: &[($ty, $ty)] = &[(0, 10),
Expand All @@ -199,15 +199,15 @@ mod tests {
}
)*
}}
);
}
t!(i8, i16, i32, i64, int,
u8, u16, u32, u64, uint)
}

#[test]
fn test_floats() {
let mut rng = ::test::rng();
macro_rules! t (
macro_rules! t {
($($ty:ty),*) => {{
$(
let v: &[($ty, $ty)] = &[(0.0, 100.0),
Expand All @@ -225,7 +225,7 @@ mod tests {
}
)*
}}
);
}

t!(f32, f64)
}
Expand Down

0 comments on commit 416137e

Please sign in to comment.