Skip to content

Commit 416137e

Browse files
author
Keegan McAllister
committed
Modernize macro_rules! invocations
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.
1 parent c9f0ff3 commit 416137e

File tree

76 files changed

+361
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+361
-331
lines changed

src/grammar/verify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn main() {
268268
assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok,
269269
antlr_tok);
270270

271-
macro_rules! matches (
271+
macro_rules! matches {
272272
( $($x:pat),+ ) => (
273273
match rustc_tok.tok {
274274
$($x => match antlr_tok.tok {
@@ -284,7 +284,7 @@ fn main() {
284284
ref c => assert!(c == &antlr_tok.tok, "{} is not {}", rustc_tok, antlr_tok)
285285
}
286286
)
287-
);
287+
}
288288

289289
matches!(
290290
token::Literal(token::Byte(..), _),

src/libcollections/slice.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,13 +2460,13 @@ mod tests {
24602460

24612461
#[test]
24622462
fn test_show() {
2463-
macro_rules! test_show_vec(
2463+
macro_rules! test_show_vec {
24642464
($x:expr, $x_str:expr) => ({
24652465
let (x, x_str) = ($x, $x_str);
24662466
assert_eq!(format!("{}", x), x_str);
24672467
assert_eq!(format!("{}", x.as_slice()), x_str);
24682468
})
2469-
);
2469+
}
24702470
let empty: Vec<int> = vec![];
24712471
test_show_vec!(empty, "[]");
24722472
test_show_vec!(vec![1i], "[1]");
@@ -2486,12 +2486,12 @@ mod tests {
24862486

24872487
#[test]
24882488
fn test_vec_default() {
2489-
macro_rules! t (
2489+
macro_rules! t {
24902490
($ty:ty) => {{
24912491
let v: $ty = Default::default();
24922492
assert!(v.is_empty());
24932493
}}
2494-
);
2494+
}
24952495

24962496
t!(&[int]);
24972497
t!(Vec<int>);

src/libcollections/str.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,9 @@ mod tests {
18381838
#[test]
18391839
fn test_is_utf16() {
18401840
use unicode::str::is_utf16;
1841-
macro_rules! pos ( ($($e:expr),*) => { { $(assert!(is_utf16($e));)* } });
1841+
macro_rules! pos {
1842+
($($e:expr),*) => { { $(assert!(is_utf16($e));)* } }
1843+
}
18421844

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

18601862
// negative tests
1861-
macro_rules! neg ( ($($e:expr),*) => { { $(assert!(!is_utf16($e));)* } });
1863+
macro_rules! neg {
1864+
($($e:expr),*) => { { $(assert!(!is_utf16($e));)* } }
1865+
}
18621866

18631867
neg!(
18641868
// surrogate + regular unit

src/libcollections/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ impl String {
182182
let byte = unsafe_get(v, i);
183183
i += 1;
184184

185-
macro_rules! error(() => ({
185+
macro_rules! error { () => ({
186186
unsafe {
187187
if subseqidx != i_ {
188188
res.as_mut_vec().push_all(v[subseqidx..i_]);
189189
}
190190
subseqidx = i;
191191
res.as_mut_vec().push_all(REPLACEMENT);
192192
}
193-
}));
193+
})}
194194

195195
if byte < 128u8 {
196196
// subseqidx handles this

src/libcore/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@
220220
//!
221221
//! ```
222222
//! # #![feature(macro_rules)]
223-
//! macro_rules! try(
223+
//! macro_rules! try {
224224
//! ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
225-
//! );
225+
//! }
226226
//! # fn main() { }
227227
//! ```
228228
//!

src/libcore/str/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,17 +948,18 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter<u8>)
948948
let old = *iter;
949949

950950
// restore the iterator we had at the start of this codepoint.
951-
macro_rules! err (() => { {
951+
macro_rules! err { () => {{
952952
*iter = old;
953953
return Err(Utf8Error::InvalidByte(whole.len() - iter.as_slice().len()))
954-
} });
955-
macro_rules! next ( () => {
954+
}}}
955+
956+
macro_rules! next { () => {
956957
match iter.next() {
957958
Some(a) => *a,
958959
// we needed data, but there was none: error!
959960
None => return Err(Utf8Error::TooShort),
960961
}
961-
});
962+
}}
962963

963964
let first = match iter.next() {
964965
Some(&b) => b,

src/libcoretest/num/int_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
macro_rules! int_module (($T:ty, $T_i:ident) => (
11+
macro_rules! int_module { ($T:ty, $T_i:ident) => (
1212
#[cfg(test)]
1313
mod tests {
1414
use core::$T_i::*;
@@ -203,4 +203,4 @@ mod tests {
203203
}
204204
}
205205

206-
));
206+
)}

src/libcoretest/num/uint_macros.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
macro_rules! uint_module (($T:ty, $T_i:ident) => (
11+
macro_rules! uint_module { ($T:ty, $T_i:ident) => (
1212
#[cfg(test)]
1313
mod tests {
1414
use core::$T_i::*;
@@ -123,4 +123,5 @@ mod tests {
123123
assert!(5u.checked_div(0) == None);
124124
}
125125
}
126-
));
126+
127+
)}

src/librand/distributions/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ mod tests {
297297
// it doesn't do weird things to the RNG (so 0 maps to 0, 1 to
298298
// 1, internally; modulo a modulo operation).
299299

300-
macro_rules! t (
300+
macro_rules! t {
301301
($items:expr, $expected:expr) => {{
302302
let mut items = $items;
303303
let wc = WeightedChoice::new(items.as_mut_slice());
@@ -309,7 +309,7 @@ mod tests {
309309
assert_eq!(wc.ind_sample(&mut rng), val)
310310
}
311311
}}
312-
);
312+
}
313313

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

src/librand/distributions/range.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod tests {
182182
#[test]
183183
fn test_integers() {
184184
let mut rng = ::test::rng();
185-
macro_rules! t (
185+
macro_rules! t {
186186
($($ty:ty),*) => {{
187187
$(
188188
let v: &[($ty, $ty)] = &[(0, 10),
@@ -199,15 +199,15 @@ mod tests {
199199
}
200200
)*
201201
}}
202-
);
202+
}
203203
t!(i8, i16, i32, i64, int,
204204
u8, u16, u32, u64, uint)
205205
}
206206

207207
#[test]
208208
fn test_floats() {
209209
let mut rng = ::test::rng();
210-
macro_rules! t (
210+
macro_rules! t {
211211
($($ty:ty),*) => {{
212212
$(
213213
let v: &[($ty, $ty)] = &[(0.0, 100.0),
@@ -225,7 +225,7 @@ mod tests {
225225
}
226226
)*
227227
}}
228-
);
228+
}
229229

230230
t!(f32, f64)
231231
}

0 commit comments

Comments
 (0)