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.
This commit is contained in:
Keegan McAllister 2015-01-02 14:44:21 -08:00
parent c9f0ff3813
commit 416137eb31
76 changed files with 355 additions and 325 deletions

View file

@ -268,7 +268,7 @@ fn next(r: &mut lexer::StringReader) -> TokenAndSpan {
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 {
@ -284,7 +284,7 @@ macro_rules! matches (
ref c => assert!(c == &antlr_tok.tok, "{} is not {}", rustc_tok, antlr_tok)
}
)
);
}
matches!(
token::Literal(token::Byte(..), _),

View file

@ -2460,13 +2460,13 @@ fn test_reverse_part() {
#[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]");
@ -2486,12 +2486,12 @@ macro_rules! test_show_vec(
#[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>);

View file

@ -1838,7 +1838,9 @@ fn test_is_utf8() {
#[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],
@ -1858,7 +1860,9 @@ fn test_is_utf16() {
&[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

View file

@ -182,7 +182,7 @@ fn safe_get(xs: &[u8], i: uint, total: uint) -> u8 {
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_]);
@ -190,7 +190,7 @@ macro_rules! error(() => ({
subseqidx = i;
res.as_mut_vec().push_all(REPLACEMENT);
}
}));
})}
if byte < 128u8 {
// subseqidx handles this

View file

@ -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() { }
//! ```
//!

View file

@ -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,

View file

@ -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::*;
@ -203,4 +203,4 @@ fn test_from_str_radix() {
}
}
));
)}

View file

@ -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::*;
@ -123,4 +123,5 @@ fn test_unsigned_checked_div() {
assert!(5u.checked_div(0) == None);
}
}
));
)}

View file

@ -297,7 +297,7 @@ fn test_weighted_choice() {
// 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());
@ -309,7 +309,7 @@ macro_rules! t (
assert_eq!(wc.ind_sample(&mut rng), val)
}
}}
);
}
t!(vec!(Weighted { weight: 1, item: 10i}), [10]);

View file

@ -182,7 +182,7 @@ fn test_range_bad_limits_flipped() {
#[test]
fn test_integers() {
let mut rng = ::test::rng();
macro_rules! t (
macro_rules! t {
($($ty:ty),*) => {{
$(
let v: &[($ty, $ty)] = &[(0, 10),
@ -199,7 +199,7 @@ macro_rules! t (
}
)*
}}
);
}
t!(i8, i16, i32, i64, int,
u8, u16, u32, u64, uint)
}
@ -207,7 +207,7 @@ macro_rules! t (
#[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),
@ -225,7 +225,7 @@ macro_rules! t (
}
)*
}}
);
}
t!(f32, f64)
}

View file

@ -69,7 +69,7 @@ fn init(&mut self, use_rsl: bool) {
let mut g = a;
let mut h = a;
macro_rules! mix(
macro_rules! mix {
() => {{
a^=b<<11; d+=a; b+=c;
b^=c>>2; e+=b; c+=d;
@ -80,14 +80,14 @@ macro_rules! mix(
g^=h<<8; b+=g; h+=a;
h^=a>>9; c+=h; a+=b;
}}
);
}
for _ in range(0u, 4) {
mix!();
}
if use_rsl {
macro_rules! memloop (
macro_rules! memloop {
($arr:expr) => {{
for i in range_step(0, RAND_SIZE as uint, 8) {
a+=$arr[i ]; b+=$arr[i+1];
@ -101,7 +101,7 @@ macro_rules! memloop (
self.mem[i+6]=g; self.mem[i+7]=h;
}
}}
);
}
memloop!(self.rsl);
memloop!(self.mem);
@ -129,41 +129,42 @@ fn isaac(&mut self) {
static MIDPOINT: uint = (RAND_SIZE / 2) as uint;
macro_rules! ind (($x:expr) => {
self.mem[(($x >> 2) as uint & ((RAND_SIZE - 1) as uint))]
});
macro_rules! ind {
($x:expr) => ( self.mem[(($x >> 2) as uint & ((RAND_SIZE - 1) as uint))] )
}
let r = [(0, MIDPOINT), (MIDPOINT, 0)];
for &(mr_offset, m2_offset) in r.iter() {
macro_rules! rngstepp(
macro_rules! rngstepp {
($j:expr, $shift:expr) => {{
let base = $j;
let mix = a << $shift as uint;
let base = $j;
let mix = a << $shift as uint;
let x = self.mem[base + mr_offset];
a = (a ^ mix) + self.mem[base + m2_offset];
let y = ind!(x) + a + b;
self.mem[base + mr_offset] = y;
let x = self.mem[base + mr_offset];
a = (a ^ mix) + self.mem[base + m2_offset];
let y = ind!(x) + a + b;
self.mem[base + mr_offset] = y;
b = ind!(y >> RAND_SIZE_LEN as uint) + x;
self.rsl[base + mr_offset] = b;
}}
);
macro_rules! rngstepn(
b = ind!(y >> RAND_SIZE_LEN as uint) + x;
self.rsl[base + mr_offset] = b;
}}
}
macro_rules! rngstepn {
($j:expr, $shift:expr) => {{
let base = $j;
let mix = a >> $shift as uint;
let base = $j;
let mix = a >> $shift as uint;
let x = self.mem[base + mr_offset];
a = (a ^ mix) + self.mem[base + m2_offset];
let y = ind!(x) + a + b;
self.mem[base + mr_offset] = y;
let x = self.mem[base + mr_offset];
a = (a ^ mix) + self.mem[base + m2_offset];
let y = ind!(x) + a + b;
self.mem[base + mr_offset] = y;
b = ind!(y >> RAND_SIZE_LEN as uint) + x;
self.rsl[base + mr_offset] = b;
}}
);
b = ind!(y >> RAND_SIZE_LEN as uint) + x;
self.rsl[base + mr_offset] = b;
}}
}
for i in range_step(0u, MIDPOINT, 4) {
rngstepp!(i + 0, 13);
@ -294,15 +295,15 @@ pub fn new_unseeded() -> Isaac64Rng {
/// of `rsl` as a seed, otherwise construct one algorithmically (not
/// randomly).
fn init(&mut self, use_rsl: bool) {
macro_rules! init (
macro_rules! init {
($var:ident) => (
let mut $var = 0x9e3779b97f4a7c13;
)
);
}
init!(a); init!(b); init!(c); init!(d);
init!(e); init!(f); init!(g); init!(h);
macro_rules! mix(
macro_rules! mix {
() => {{
a-=e; f^=h>>9; h+=a;
b-=f; g^=a<<9; a+=b;
@ -313,14 +314,14 @@ macro_rules! mix(
g-=c; d^=f>>17; f+=g;
h-=d; e^=g<<14; g+=h;
}}
);
}
for _ in range(0u, 4) {
mix!();
}
if use_rsl {
macro_rules! memloop (
macro_rules! memloop {
($arr:expr) => {{
for i in range(0, RAND_SIZE_64 / 8).map(|i| i * 8) {
a+=$arr[i ]; b+=$arr[i+1];
@ -334,7 +335,7 @@ macro_rules! memloop (
self.mem[i+6]=g; self.mem[i+7]=h;
}
}}
);
}
memloop!(self.rsl);
memloop!(self.mem);
@ -359,49 +360,51 @@ fn isaac64(&mut self) {
let mut b = self.b + self.c;
const MIDPOINT: uint = RAND_SIZE_64 / 2;
const MP_VEC: [(uint, uint); 2] = [(0,MIDPOINT), (MIDPOINT, 0)];
macro_rules! ind (
macro_rules! ind {
($x:expr) => {
*self.mem.get_unchecked(($x as uint >> 3) & (RAND_SIZE_64 - 1))
}
);
}
for &(mr_offset, m2_offset) in MP_VEC.iter() {
for base in range(0, MIDPOINT / 4).map(|i| i * 4) {
macro_rules! rngstepp(
macro_rules! rngstepp {
($j:expr, $shift:expr) => {{
let base = base + $j;
let mix = a ^ (a << $shift as uint);
let mix = if $j == 0 {!mix} else {mix};
let base = base + $j;
let mix = a ^ (a << $shift as uint);
let mix = if $j == 0 {!mix} else {mix};
unsafe {
let x = *self.mem.get_unchecked(base + mr_offset);
a = mix + *self.mem.get_unchecked(base + m2_offset);
let y = ind!(x) + a + b;
*self.mem.get_unchecked_mut(base + mr_offset) = y;
unsafe {
let x = *self.mem.get_unchecked(base + mr_offset);
a = mix + *self.mem.get_unchecked(base + m2_offset);
let y = ind!(x) + a + b;
*self.mem.get_unchecked_mut(base + mr_offset) = y;
b = ind!(y >> RAND_SIZE_64_LEN) + x;
*self.rsl.get_unchecked_mut(base + mr_offset) = b;
}
}}
);
macro_rules! rngstepn(
b = ind!(y >> RAND_SIZE_64_LEN) + x;
*self.rsl.get_unchecked_mut(base + mr_offset) = b;
}
}}
}
macro_rules! rngstepn {
($j:expr, $shift:expr) => {{
let base = base + $j;
let mix = a ^ (a >> $shift as uint);
let mix = if $j == 0 {!mix} else {mix};
let base = base + $j;
let mix = a ^ (a >> $shift as uint);
let mix = if $j == 0 {!mix} else {mix};
unsafe {
let x = *self.mem.get_unchecked(base + mr_offset);
a = mix + *self.mem.get_unchecked(base + m2_offset);
let y = ind!(x) + a + b;
*self.mem.get_unchecked_mut(base + mr_offset) = y;
unsafe {
let x = *self.mem.get_unchecked(base + mr_offset);
a = mix + *self.mem.get_unchecked(base + m2_offset);
let y = ind!(x) + a + b;
*self.mem.get_unchecked_mut(base + mr_offset) = y;
b = ind!(y >> RAND_SIZE_64_LEN) + x;
*self.rsl.get_unchecked_mut(base + mr_offset) = b;
}
}}
}
b = ind!(y >> RAND_SIZE_64_LEN) + x;
*self.rsl.get_unchecked_mut(base + mr_offset) = b;
}
}}
);
rngstepp!(0u, 21);
rngstepn!(1u, 5);
rngstepp!(2u, 12);

View file

@ -167,21 +167,27 @@ fn register_renamed(&mut self, old_name: &str, new_name: &str) {
}
pub fn register_builtin(&mut self, sess: Option<&Session>) {
macro_rules! add_builtin ( ( $sess:ident, $($name:ident),*, ) => (
{$(
self.register_pass($sess, false, box builtin::$name as LintPassObject);
)*}
));
macro_rules! add_builtin {
($sess:ident, $($name:ident),*,) => (
{$(
self.register_pass($sess, false, box builtin::$name as LintPassObject);
)*}
)
}
macro_rules! add_builtin_with_new ( ( $sess:ident, $($name:ident),*, ) => (
{$(
self.register_pass($sess, false, box builtin::$name::new() as LintPassObject);
)*}
));
macro_rules! add_builtin_with_new {
($sess:ident, $($name:ident),*,) => (
{$(
self.register_pass($sess, false, box builtin::$name::new() as LintPassObject);
)*}
)
}
macro_rules! add_lint_group ( ( $sess:ident, $name:expr, $($lint:ident),* ) => (
self.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]);
));
macro_rules! add_lint_group {
($sess:ident, $name:expr, $($lint:ident),*) => (
self.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]);
)
}
add_builtin!(sess,
HardwiredLints,

View file

@ -503,7 +503,7 @@ fn fromb(b: bool) -> Result<const_val, String> { Ok(const_int(b as i64)) }
"target type not found for const cast")
});
macro_rules! define_casts(
macro_rules! define_casts {
($val:ident, {
$($ty_pat:pat => (
$intermediate_ty:ty,
@ -524,7 +524,7 @@ macro_rules! define_casts(
},)*
_ => Err("can't cast this type".to_string())
})
);
}
eval_const_expr_partial(tcx, &**base)
.and_then(|val| define_casts!(val, {

View file

@ -6237,8 +6237,8 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
return state.result();
fn helper<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh, state: &mut sip::SipState) {
macro_rules! byte( ($b:expr) => { ($b as u8).hash(state) } );
macro_rules! hash( ($e:expr) => { $e.hash(state) } );
macro_rules! byte { ($b:expr) => { ($b as u8).hash(state) } }
macro_rules! hash { ($e:expr) => { $e.hash(state) } }
let region = |&: state: &mut sip::SipState, r: Region| {
match r {

View file

@ -346,12 +346,12 @@ fn sigma1(x: u32) -> u32 {
// Sha-512 and Sha-256 use basically the same calculations which are implemented
// by these macros. Inlining the calculations seems to result in better generated code.
macro_rules! schedule_round( ($t:expr) => (
macro_rules! schedule_round { ($t:expr) => (
w[$t] = sigma1(w[$t - 2]) + w[$t - 7] + sigma0(w[$t - 15]) + w[$t - 16];
)
);
}
macro_rules! sha2_round(
macro_rules! sha2_round {
($A:ident, $B:ident, $C:ident, $D:ident,
$E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => (
{
@ -360,7 +360,7 @@ macro_rules! sha2_round(
$H += sum0($A) + maj($A, $B, $C);
}
)
);
}
read_u32v_be(w.slice_mut(0, 16), data);

View file

@ -239,7 +239,7 @@ pub fn from_json(obj: Json) -> Target {
options: Default::default(),
};
macro_rules! key (
macro_rules! key {
($key_name:ident) => ( {
let name = (stringify!($key_name)).replace("_", "-");
obj.find(name[]).map(|o| o.as_string()
@ -257,7 +257,7 @@ macro_rules! key (
)
);
} );
);
}
key!(cpu);
key!(linker);
@ -305,7 +305,7 @@ fn load_file(path: &Path) -> Result<Target, String> {
}
// this would use a match if stringify! were allowed in pattern position
macro_rules! load_specific (
macro_rules! load_specific {
( $($name:ident),+ ) => (
{
let target = target.replace("-", "_");
@ -326,7 +326,7 @@ macro_rules! load_specific (
}
}
)
);
}
load_specific!(
x86_64_unknown_linux_gnu,

View file

@ -741,7 +741,7 @@ pub fn report_overbig_object(&self, obj: Ty<'tcx>) -> ! {
}
fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef> {
macro_rules! ifn (
macro_rules! ifn {
($name:expr fn() -> $ret:expr) => (
if *key == $name {
let f = base::decl_cdecl_fn(
@ -759,10 +759,10 @@ macro_rules! ifn (
return Some(f);
}
)
);
macro_rules! mk_struct (
}
macro_rules! mk_struct {
($($field_ty:expr),*) => (Type::struct_(ccx, &[$($field_ty),*], false))
);
}
let i8p = Type::i8p(ccx);
let void = Type::void(ccx);
@ -883,7 +883,7 @@ macro_rules! mk_struct (
// Some intrinsics were introduced in later versions of LLVM, but they have
// fallbacks in libc or libm and such. Currently, all of these intrinsics
// were introduced in LLVM 3.4, so we case on that.
macro_rules! compatible_ifn (
macro_rules! compatible_ifn {
($name:expr, $cname:ident ($($arg:expr),*) -> $ret:expr) => (
if unsafe { llvm::LLVMVersionMinor() >= 4 } {
// The `if key == $name` is already in ifn!
@ -896,7 +896,7 @@ macro_rules! compatible_ifn (
return Some(f);
}
)
);
}
compatible_ifn!("llvm.copysign.f32", copysignf(t_f32, t_f32) -> t_f32);
compatible_ifn!("llvm.copysign.f64", copysign(t_f64, t_f64) -> t_f64);

View file

@ -558,7 +558,7 @@ macro_rules! t {
t!(b"foo/\xFFbar", filename_display, "\u{FFFD}bar");
t!(b"/", filename_display, "");
macro_rules! t(
macro_rules! t {
($path:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -573,7 +573,7 @@ macro_rules! t(
assert!(mo.as_slice() == $exp);
}
)
);
}
t!("foo", "foo");
t!(b"foo\x80", "foo\u{FFFD}");
@ -585,7 +585,7 @@ macro_rules! t(
#[test]
fn test_display() {
macro_rules! t(
macro_rules! t {
($path:expr, $exp:expr, $expf:expr) => (
{
let path = Path::new($path);
@ -595,7 +595,7 @@ macro_rules! t(
assert!(f == $expf);
}
)
);
}
t!(b"foo", "foo", "foo");
t!(b"foo/bar", "foo/bar", "bar");
@ -608,7 +608,7 @@ macro_rules! t(
#[test]
fn test_components() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $op:ident, $exp:expr) => (
{
let path = Path::new($path);
@ -629,7 +629,7 @@ macro_rules! t(
assert!(path.$op() == $exp);
}
);
);
}
t!(v: b"a/b/c", filename, Some(b"c"));
t!(v: b"a/b/c\xFF", filename, Some(b"c\xFF"));
@ -692,7 +692,7 @@ macro_rules! t(
#[test]
fn test_push() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $join:expr) => (
{
let path = $path;
@ -703,7 +703,7 @@ macro_rules! t(
assert!(p1 == p2.join(join));
}
)
);
}
t!(s: "a/b/c", "..");
t!(s: "/a/b/c", "d");
@ -713,7 +713,7 @@ macro_rules! t(
#[test]
fn test_push_path() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $push:expr, $exp:expr) => (
{
let mut p = Path::new($path);
@ -722,7 +722,7 @@ macro_rules! t(
assert!(p.as_str() == Some($exp));
}
)
);
}
t!(s: "a/b/c", "d", "a/b/c/d");
t!(s: "/a/b/c", "d", "/a/b/c/d");
@ -734,7 +734,7 @@ macro_rules! t(
#[test]
fn test_push_many() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $push:expr, $exp:expr) => (
{
let mut p = Path::new($path);
@ -749,7 +749,7 @@ macro_rules! t(
assert!(p.as_vec() == $exp);
}
)
);
}
t!(s: "a/b/c", ["d", "e"], "a/b/c/d/e");
t!(s: "a/b/c", ["d", "/e"], "/e");
@ -762,7 +762,7 @@ macro_rules! t(
#[test]
fn test_pop() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $left:expr, $right:expr) => (
{
let mut p = Path::new($path);
@ -779,7 +779,7 @@ macro_rules! t(
assert!(result == $right);
}
)
);
}
t!(b: b"a/b/c", b"a/b", true);
t!(b: b"a", b".", true);
@ -818,7 +818,7 @@ fn test_join() {
#[test]
fn test_join_path() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $join:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -827,7 +827,7 @@ macro_rules! t(
assert!(res.as_str() == Some($exp));
}
)
);
}
t!(s: "a/b/c", "..", "a/b");
t!(s: "/a/b/c", "d", "/a/b/c/d");
@ -839,7 +839,7 @@ macro_rules! t(
#[test]
fn test_join_many() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $join:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -854,7 +854,7 @@ macro_rules! t(
assert!(res.as_vec() == $exp);
}
)
);
}
t!(s: "a/b/c", ["d", "e"], "a/b/c/d/e");
t!(s: "a/b/c", ["..", "d"], "a/b/d");
@ -917,7 +917,7 @@ fn test_with_helpers() {
#[test]
fn test_setters() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $set:ident, $with:ident, $arg:expr) => (
{
let path = $path;
@ -938,7 +938,7 @@ macro_rules! t(
assert!(p1 == p2.$with(arg));
}
)
);
}
t!(v: b"a/b/c", set_filename, with_filename, b"d");
t!(v: b"/", set_filename, with_filename, b"foo");
@ -961,7 +961,7 @@ macro_rules! t(
#[test]
fn test_getters() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => (
{
let path = $path;
@ -992,7 +992,7 @@ macro_rules! t(
assert!(path.extension() == $ext);
}
)
);
}
t!(v: Path::new(b"a/b/c"), Some(b"c"), b"a/b", Some(b"c"), None);
t!(v: Path::new(b"a/b/\xFF"), Some(b"\xFF"), b"a/b", Some(b"\xFF"), None);
@ -1031,7 +1031,7 @@ fn test_dir_path() {
#[test]
fn test_is_absolute() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $abs:expr, $rel:expr) => (
{
let path = Path::new($path);
@ -1039,7 +1039,7 @@ macro_rules! t(
assert_eq!(path.is_relative(), $rel);
}
)
);
}
t!(s: "a/b/c", false, true);
t!(s: "/a/b/c", true, false);
t!(s: "a", false, true);
@ -1052,7 +1052,7 @@ macro_rules! t(
#[test]
fn test_is_ancestor_of() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $dest:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -1060,7 +1060,7 @@ macro_rules! t(
assert_eq!(path.is_ancestor_of(&dest), $exp);
}
)
);
}
t!(s: "a/b/c", "a/b/c/d", true);
t!(s: "a/b/c", "a/b/c", true);
@ -1086,7 +1086,7 @@ macro_rules! t(
#[test]
fn test_ends_with_path() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $child:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -1101,7 +1101,7 @@ macro_rules! t(
assert_eq!(path.ends_with_path(&child), $exp);
}
)
);
}
t!(s: "a/b/c", "c", true);
t!(s: "a/b/c", "d", false);
@ -1125,7 +1125,7 @@ macro_rules! t(
#[test]
fn test_path_relative_from() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $other:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -1134,7 +1134,7 @@ macro_rules! t(
assert_eq!(res.as_ref().and_then(|x| x.as_str()), $exp);
}
)
);
}
t!(s: "a/b/c", "a/b", Some("c"));
t!(s: "a/b/c", "a/b/d", Some("../c"));
@ -1170,7 +1170,7 @@ macro_rules! t(
#[test]
fn test_components_iter() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -1196,7 +1196,7 @@ macro_rules! t(
assert_eq!(comps, exp)
}
)
);
}
t!(b: b"a/b/c", [b"a", b"b", b"c"]);
t!(b: b"/\xFF/a/\x80", [b"\xFF", b"a", b"\x80"]);
@ -1216,7 +1216,7 @@ macro_rules! t(
#[test]
fn test_str_components() {
macro_rules! t(
macro_rules! t {
(b: $arg:expr, $exp:expr) => (
{
let path = Path::new($arg);
@ -1228,7 +1228,7 @@ macro_rules! t(
assert_eq!(comps, exp);
}
)
);
}
t!(b: b"a/b/c", [Some("a"), Some("b"), Some("c")]);
t!(b: b"/\xFF/a/\x80", [None, Some("a"), None]);

View file

@ -1149,7 +1149,7 @@ macro_rules! t {
#[test]
fn test_parse_prefix() {
macro_rules! t(
macro_rules! t {
($path:expr, $exp:expr) => (
{
let path = $path;
@ -1159,7 +1159,7 @@ macro_rules! t(
"parse_prefix(\"{}\"): expected {}, found {}", path, exp, res);
}
)
);
}
t!("\\\\SERVER\\share\\foo", Some(UNCPrefix(6,5)));
t!("\\\\", None);
@ -1348,7 +1348,7 @@ fn test_display_str() {
#[test]
fn test_display() {
macro_rules! t(
macro_rules! t {
($path:expr, $exp:expr, $expf:expr) => (
{
let path = Path::new($path);
@ -1358,7 +1358,7 @@ macro_rules! t(
assert_eq!(f, $expf);
}
)
);
}
t!("foo", "foo", "foo");
t!("foo\\bar", "foo\\bar", "bar");
@ -1367,7 +1367,7 @@ macro_rules! t(
#[test]
fn test_components() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $op:ident, $exp:expr) => (
{
let path = $path;
@ -1390,7 +1390,7 @@ macro_rules! t(
assert!(path.$op() == $exp);
}
)
);
}
t!(v: b"a\\b\\c", filename, Some(b"c"));
t!(s: "a\\b\\c", filename_str, "c");
@ -1490,7 +1490,7 @@ macro_rules! t(
#[test]
fn test_push() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $join:expr) => (
{
let path = $path;
@ -1501,7 +1501,7 @@ macro_rules! t(
assert!(p1 == p2.join(join));
}
)
);
}
t!(s: "a\\b\\c", "..");
t!(s: "\\a\\b\\c", "d");
@ -1525,7 +1525,7 @@ macro_rules! t(
#[test]
fn test_push_path() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $push:expr, $exp:expr) => (
{
let mut p = Path::new($path);
@ -1534,7 +1534,7 @@ macro_rules! t(
assert_eq!(p.as_str(), Some($exp));
}
)
);
}
t!(s: "a\\b\\c", "d", "a\\b\\c\\d");
t!(s: "\\a\\b\\c", "d", "\\a\\b\\c\\d");
@ -1577,7 +1577,7 @@ macro_rules! t(
#[test]
fn test_push_many() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $push:expr, $exp:expr) => (
{
let mut p = Path::new($path);
@ -1592,7 +1592,7 @@ macro_rules! t(
assert_eq!(p.as_vec(), $exp);
}
)
);
}
t!(s: "a\\b\\c", ["d", "e"], "a\\b\\c\\d\\e");
t!(s: "a\\b\\c", ["d", "\\e"], "\\e");
@ -1606,7 +1606,7 @@ macro_rules! t(
#[test]
fn test_pop() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $left:expr, $right:expr) => (
{
let pstr = $path;
@ -1627,7 +1627,7 @@ macro_rules! t(
assert!(result == $right);
}
)
);
}
t!(s: "a\\b\\c", "a\\b", true);
t!(s: "a", ".", true);
@ -1695,7 +1695,7 @@ fn test_join() {
#[test]
fn test_join_path() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $join:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -1704,7 +1704,7 @@ macro_rules! t(
assert_eq!(res.as_str(), Some($exp));
}
)
);
}
t!(s: "a\\b\\c", "..", "a\\b");
t!(s: "\\a\\b\\c", "d", "\\a\\b\\c\\d");
@ -1718,7 +1718,7 @@ macro_rules! t(
#[test]
fn test_join_many() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $join:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -1733,7 +1733,7 @@ macro_rules! t(
assert_eq!(res.as_vec(), $exp);
}
)
);
}
t!(s: "a\\b\\c", ["d", "e"], "a\\b\\c\\d\\e");
t!(s: "a\\b\\c", ["..", "d"], "a\\b\\d");
@ -1746,7 +1746,7 @@ macro_rules! t(
#[test]
fn test_with_helpers() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $op:ident, $arg:expr, $res:expr) => (
{
let pstr = $path;
@ -1759,7 +1759,7 @@ macro_rules! t(
pstr, stringify!($op), arg, exp, res.as_str().unwrap());
}
)
);
}
t!(s: "a\\b\\c", with_filename, "d", "a\\b\\d");
t!(s: ".", with_filename, "foo", "foo");
@ -1831,7 +1831,7 @@ macro_rules! t(
#[test]
fn test_setters() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $set:ident, $with:ident, $arg:expr) => (
{
let path = $path;
@ -1852,7 +1852,7 @@ macro_rules! t(
assert!(p1 == p2.$with(arg));
}
)
);
}
t!(v: b"a\\b\\c", set_filename, with_filename, b"d");
t!(v: b"\\", set_filename, with_filename, b"foo");
@ -1876,7 +1876,7 @@ macro_rules! t(
#[test]
fn test_getters() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => (
{
let path = $path;
@ -1907,7 +1907,7 @@ macro_rules! t(
assert!(path.extension() == $ext);
}
)
);
}
t!(v: Path::new(b"a\\b\\c"), Some(b"c"), b"a\\b", Some(b"c"), None);
t!(s: Path::new("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None);
@ -1942,7 +1942,7 @@ fn test_dir_path() {
#[test]
fn test_is_absolute() {
macro_rules! t(
macro_rules! t {
($path:expr, $abs:expr, $vol:expr, $cwd:expr, $rel:expr) => (
{
let path = Path::new($path);
@ -1961,7 +1961,7 @@ macro_rules! t(
path.as_str().unwrap(), rel, b);
}
)
);
}
t!("a\\b\\c", false, false, false, true);
t!("\\a\\b\\c", false, true, false, false);
t!("a", false, false, false, true);
@ -1982,7 +1982,7 @@ macro_rules! t(
#[test]
fn test_is_ancestor_of() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $dest:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -1994,7 +1994,7 @@ macro_rules! t(
path.as_str().unwrap(), dest.as_str().unwrap(), exp, res);
}
)
);
}
t!(s: "a\\b\\c", "a\\b\\c\\d", true);
t!(s: "a\\b\\c", "a\\b\\c", true);
@ -2085,7 +2085,7 @@ macro_rules! t(
#[test]
fn test_ends_with_path() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $child:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -2093,7 +2093,7 @@ macro_rules! t(
assert_eq!(path.ends_with_path(&child), $exp);
}
);
);
}
t!(s: "a\\b\\c", "c", true);
t!(s: "a\\b\\c", "d", false);
@ -2117,7 +2117,7 @@ macro_rules! t(
#[test]
fn test_path_relative_from() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $other:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -2130,7 +2130,7 @@ macro_rules! t(
res.as_ref().and_then(|x| x.as_str()));
}
)
);
}
t!(s: "a\\b\\c", "a\\b", Some("c"));
t!(s: "a\\b\\c", "a\\b\\d", Some("..\\c"));
@ -2251,7 +2251,7 @@ macro_rules! t(
#[test]
fn test_str_components() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -2265,7 +2265,7 @@ macro_rules! t(
assert_eq!(comps, exp);
}
);
);
}
t!(s: b"a\\b\\c", ["a", "b", "c"]);
t!(s: "a\\b\\c", ["a", "b", "c"]);
@ -2309,7 +2309,7 @@ macro_rules! t(
#[test]
fn test_components_iter() {
macro_rules! t(
macro_rules! t {
(s: $path:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -2321,7 +2321,7 @@ macro_rules! t(
assert_eq!(comps, exp);
}
)
);
}
t!(s: "a\\b\\c", [b"a", b"b", b"c"]);
t!(s: ".", [b"."]);
@ -2330,7 +2330,7 @@ macro_rules! t(
#[test]
fn test_make_non_verbatim() {
macro_rules! t(
macro_rules! t {
($path:expr, $exp:expr) => (
{
let path = Path::new($path);
@ -2339,7 +2339,7 @@ macro_rules! t(
assert!(make_non_verbatim(&path) == exp);
}
)
);
}
t!(r"\a\b\c", Some(r"\a\b\c"));
t!(r"a\b\c", Some(r"a\b\c"));

View file

@ -61,7 +61,7 @@ fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
cx, span, substr)
}
macro_rules! md (
macro_rules! md {
($name:expr, $f:ident) => { {
let inline = cx.meta_word(span, InternedString::new("inline"));
let attrs = vec!(cx.attribute(span, inline));
@ -77,7 +77,7 @@ macro_rules! md (
})
}
} }
);
}
let trait_def = TraitDef {
span: span,

View file

@ -27,7 +27,7 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
push: F) where
F: FnOnce(P<Item>),
{
macro_rules! md (
macro_rules! md {
($name:expr, $op:expr, $equal:expr) => { {
let inline = cx.meta_word(span, InternedString::new("inline"));
let attrs = vec!(cx.attribute(span, inline));
@ -43,7 +43,7 @@ macro_rules! md (
})
}
} }
);
}
let ordering_ty = Literal(Path::new(vec!["std", "cmp", "Ordering"]));
let ret_ty = Literal(Path::new_(vec!["std", "option", "Option"],

View file

@ -71,9 +71,11 @@ pub fn expand_meta_derive(cx: &mut ExtCtxt,
MetaNameValue(ref tname, _) |
MetaList(ref tname, _) |
MetaWord(ref tname) => {
macro_rules! expand(($func:path) => ($func(cx, titem.span,
&**titem, item,
|i| push.call_mut((i,)))));
macro_rules! expand {
($func:path) => ($func(cx, titem.span, &**titem, item,
|i| push.call_mut((i,))))
}
match tname.get() {
"Clone" => expand!(clone::expand_deriving_clone),

View file

@ -38,8 +38,8 @@ impl<'a> ParserAnyMacro<'a> {
/// Make sure we don't have any tokens left to parse, so we don't
/// silently drop anything. `allow_semi` is so that "optional"
/// semicolons at the end of normal expressions aren't complained
/// about e.g. the semicolon in `macro_rules! kapow( () => {
/// panic!(); } )` doesn't get picked up by .parse_expr(), but it's
/// about e.g. the semicolon in `macro_rules! kapow { () => {
/// panic!(); } }` doesn't get picked up by .parse_expr(), but it's
/// allowed to be there.
fn ensure_complete_parse(&self, allow_semi: bool) {
let mut parser = self.parser.borrow_mut();

View file

@ -160,12 +160,12 @@
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
pub fn parse(file: &mut io::Reader, longnames: bool)
-> Result<Box<TermInfo>, String> {
macro_rules! try( ($e:expr) => (
macro_rules! try { ($e:expr) => (
match $e {
Ok(e) => e,
Err(e) => return Err(format!("{}", e))
}
) );
) }
let bnames;
let snames;

View file

@ -180,16 +180,16 @@ pub enum Enum {
pub struct LockedTupleStruct(pub int);
#[macro_export]
macro_rules! macro_test(
macro_rules! macro_test {
() => (deprecated());
);
}
#[macro_export]
macro_rules! macro_test_arg(
macro_rules! macro_test_arg {
($func:expr) => ($func);
);
}
#[macro_export]
macro_rules! macro_test_arg_nested(
macro_rules! macro_test_arg_nested {
($func:ident) => (macro_test_arg!($func()));
);
}

View file

@ -11,6 +11,6 @@
#![feature(macro_rules)]
#[macro_export]
macro_rules! make_a_5(
macro_rules! make_a_5 {
() => (5)
);
}

View file

@ -24,9 +24,9 @@
use rustc::plugin::Registry;
#[macro_export]
macro_rules! exported_macro (() => (2i));
macro_rules! exported_macro { () => (2i) }
macro_rules! unexported_macro (() => (3i));
macro_rules! unexported_macro { () => (3i) }
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {

View file

@ -12,7 +12,7 @@
pub mod inner {
#[macro_export]
macro_rules! foo(
macro_rules! foo {
() => (1)
);
}
}

View file

@ -28,11 +28,12 @@ fn main() {
let argv = os::args();
let _tests = argv.slice(1, argv.len());
macro_rules! bench (
macro_rules! bench {
($id:ident) =>
(maybe_run_test(argv.as_slice(),
stringify!($id).to_string(),
$id)));
$id))
}
bench!(shift_push);
bench!(read_line);

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
macro_rules! foo(() => ());
macro_rules! foo { () => () }
//~^ ERROR: macro definitions are not stable enough for use
fn main() {}

View file

@ -10,11 +10,9 @@
#![feature(macro_rules)]
macro_rules! recursive(
() => (
recursive!() //~ ERROR recursion limit reached while expanding the macro `recursive`
)
);
macro_rules! recursive {
() => (recursive!()) //~ ERROR recursion limit reached while expanding the macro `recursive`
}
fn main() {
recursive!()

View file

@ -17,7 +17,7 @@
#![feature(macro_rules)]
macro_rules! f(() => (n))
macro_rules! f { () => (n) }
fn main() -> (){
for n in range(0i, 1) {

View file

@ -12,11 +12,11 @@
// error-pattern: unexpected token
macro_rules! e(
macro_rules! e {
($inp:ident) => (
$nonexistent
);
);
}
fn main() {
e!(foo);

View file

@ -12,7 +12,7 @@
#![feature(macro_rules)]
macro_rules! test ( () => { fn foo() -> int { 1i; } } );
macro_rules! test { () => { fn foo() -> int { 1i; } } }
//~^ ERROR not all control paths return a value
//~^^ HELP consider removing this semicolon

View file

@ -10,9 +10,9 @@
#![feature(macro_rules)]
macro_rules! test ( ($nm:ident,
macro_rules! test { ($nm:ident,
#[$a:meta],
$i:item) => (mod $nm { #![$a] $i }); );
$i:item) => (mod $nm { #![$a] $i }); }
test!(a,
#[cfg(qux)],

View file

@ -10,7 +10,7 @@
#![feature(macro_rules)]
macro_rules! test ( ($a, $b) => (()); ); //~ ERROR Cannot transcribe
macro_rules! test { ($a, $b) => (()); } //~ ERROR Cannot transcribe
fn main() {
test!()

View file

@ -10,9 +10,9 @@
#![feature(macro_rules)]
macro_rules! test ( ($nm:ident,
macro_rules! test { ($nm:ident,
#[$a:meta],
$i:item) => (mod $nm { #[$a] $i }); );
$i:item) => (mod $nm { #[$a] $i }); }
test!(a,
#[cfg(qux)],

View file

@ -12,4 +12,3 @@ macro_rules! foo() //~ ERROR semicolon
fn main() {
}

View file

@ -12,9 +12,9 @@
#![feature(macro_rules)]
macro_rules! make_method ( ($name:ident) => (
fn $name(&self) { }
));
macro_rules! make_method {
($name:ident) => ( fn $name(&self) { } )
}
struct S;

View file

@ -10,7 +10,7 @@
#![feature(macro_rules)]
macro_rules! foo ( () => ( x ) );
macro_rules! foo { () => ( x ) }
fn main() {
let foo!() = 2;

View file

@ -24,12 +24,12 @@ pub enum Bar {
impl Foo {
fn elaborate_stm(&mut self, s: Box<Bar>) -> Box<Bar> {
macro_rules! declare(
macro_rules! declare {
($id:expr, $rest:expr) => ({
self.check_id($id);
box Bar::Bar2($id, $rest)
})
);
}
match s {
box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)),
_ => panic!()

View file

@ -61,7 +61,7 @@ fn drop(&mut self) {
}
}
macro_rules! end_of_block(
macro_rules! end_of_block {
($pat:pat, $expr:expr) => (
{
println!("end_of_block({})", stringify!({let $pat = $expr;}));
@ -74,9 +74,9 @@ macro_rules! end_of_block(
check_flags(1);
}
)
);
}
macro_rules! end_of_stmt(
macro_rules! end_of_stmt {
($pat:pat, $expr:expr) => (
{
println!("end_of_stmt({})", stringify!($expr));
@ -91,7 +91,7 @@ macro_rules! end_of_stmt(
check_flags(0);
}
)
);
}
pub fn main() {

View file

@ -10,14 +10,14 @@
#![feature(macro_rules)]
macro_rules! assert_approx_eq(
macro_rules! assert_approx_eq {
($a:expr, $b:expr) => ({
use std::num::Float;
let (a, b) = (&$a, &$b);
assert!((*a - *b).abs() < 1.0e-6,
"{} is not approximately equal to {}", *a, *b);
})
);
}
static A: int = -4 + 3;
static A2: uint = 3 + 3;

View file

@ -26,9 +26,9 @@
use std::sync::mpsc::channel;
use std::thread::Thread;
macro_rules! succeed( ($e:expr) => (
macro_rules! succeed { ($e:expr) => (
match $e { Ok(..) => {}, Err(e) => panic!("panic: {}", e) }
) );
) }
fn test_destroy_once() {
let mut p = sleeper();

View file

@ -10,14 +10,14 @@
#![feature(macro_rules)]
macro_rules! define_vec (
macro_rules! define_vec {
() => (
mod foo {
#[derive(PartialEq)]
pub struct bar;
}
)
);
}
define_vec!();

View file

@ -15,7 +15,9 @@
use std::num::strconv::SignFormat::{SignAll, SignNeg};
use std::num::strconv::float_to_str_common as to_string;
macro_rules! t(($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_string()); } });
macro_rules! t {
($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_string()); } }
}
pub fn main() {
// Basic usage

View file

@ -27,13 +27,13 @@
*/
use HTMLFragment::{tag, text};
macro_rules! html (
macro_rules! html {
( $($body:tt)* ) => (
parse_node!( []; []; $($body)* )
)
);
}
macro_rules! parse_node (
macro_rules! parse_node {
(
[:$head:ident ($(:$head_nodes:expr),*)
$(:$tags:ident ($(:$tag_nodes:expr),*))*];
@ -85,7 +85,7 @@ macro_rules! parse_node (
);
( []; [:$e:expr]; ) => ( $e );
);
}
pub fn main() {
let _page = html! (

View file

@ -37,7 +37,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
macro_rules! t(($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) });
macro_rules! t {
($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) }
}
pub fn main() {
// Various edge cases without formats

View file

@ -11,14 +11,14 @@
#![feature(globs, macro_rules, intrinsics)]
macro_rules! assert_approx_eq(
macro_rules! assert_approx_eq {
($a:expr, $b:expr) => ({
use std::num::Float;
let (a, b) = (&$a, &$b);
assert!((*a - *b).abs() < 1.0e-6,
"{} is not approximately equal to {}", *a, *b);
})
);
}
mod rusti {
extern "rust-intrinsic" {

View file

@ -12,7 +12,9 @@
#![feature(macro_rules)]
macro_rules! third(($e:expr)=>({let x = 2; $e[x]}));
macro_rules! third {
($e:expr) => ({let x = 2; $e[x]})
}
fn main() {
let x = vec!(10u,11u,12u,13u);

View file

@ -10,11 +10,13 @@
#![feature(macro_rules)]
macro_rules! inner (
($e:pat ) => ($e));
macro_rules! inner {
($e:pat ) => ($e)
}
macro_rules! outer (
($e:pat ) => (inner!($e)));
macro_rules! outer {
($e:pat ) => (inner!($e))
}
fn main() {
let outer!(g1) = 13i;

View file

@ -10,7 +10,7 @@
#![feature(macro_rules)]
macro_rules! print_hd_tl (
macro_rules! print_hd_tl {
($field_hd:ident, $($field_tl:ident),+) => ({
print!("{}", stringify!($field_hd));
print!("::[");
@ -21,7 +21,7 @@ macro_rules! print_hd_tl (
// FIXME: #9970
print!("{}", "]\n");
})
);
}
pub fn main() {
print_hd_tl!(x, y, z, w)

View file

@ -27,7 +27,7 @@ trait Test {
fn get_mut(&mut self) -> &mut FooBar;
}
macro_rules! generate_test(($type_:path, $slf:ident, $field:expr) => (
macro_rules! generate_test { ($type_:path, $slf:ident, $field:expr) => (
impl Test for $type_ {
fn get_immut(&$slf) -> &FooBar {
&$field as &FooBar
@ -37,7 +37,7 @@ fn get_mut(&mut $slf) -> &mut FooBar {
&mut $field as &mut FooBar
}
}
));
)}
generate_test!(Foo, self, self.bar);

View file

@ -10,13 +10,13 @@
#![feature(macro_rules)]
macro_rules! sty(
macro_rules! sty {
($t:ty) => (stringify!($t))
);
}
macro_rules! spath(
macro_rules! spath {
($t:path) => (stringify!($t))
);
}
fn main() {
assert_eq!(sty!(int), "int");

View file

@ -20,7 +20,7 @@ enum T {
B(uint)
}
macro_rules! test(
macro_rules! test {
($id:ident, $e:expr) => (
fn foo(t: T) -> int {
match t {
@ -29,7 +29,7 @@ fn foo(t: T) -> int {
}
}
)
);
}
test!(y, 10 + (y as int));

View file

@ -10,14 +10,14 @@
#![feature(macro_rules)]
macro_rules! silly_macro(
macro_rules! silly_macro {
() => (
pub mod Qux {
pub struct Foo { x : u8 }
pub fn bar(_foo : Foo) {}
}
);
);
}
silly_macro!();

View file

@ -19,8 +19,8 @@ impl bomb for S { fn boom(&self, _: Ident) { } }
pub struct Ident { name: uint }
// macro_rules! int3( () => ( unsafe { asm!( "int3" ); } ) )
macro_rules! int3( () => ( { } ) );
// macro_rules! int3 { () => ( unsafe { asm!( "int3" ); } ) }
macro_rules! int3 { () => ( { } ) }
fn Ident_new() -> Ident {
int3!();

View file

@ -12,7 +12,9 @@
#![feature(macro_rules)]
macro_rules! f((v: $x:expr) => ( println!("{}", $x) ))
macro_rules! f {
(v: $x:expr) => ( println!("{}", $x) )
}
fn main () {
let v = 5;

View file

@ -13,7 +13,9 @@
#![feature(macro_rules)]
// shouldn't affect evaluation of $ex:
macro_rules! bad_macro (($ex:expr) => ({(|_x| { $ex }) (9) }))
macro_rules! bad_macro {
($ex:expr) => ({(|_x| { $ex }) (9) })
}
fn takes_x(_x : int) {
assert_eq!(bad_macro!(_x),8);

View file

@ -11,7 +11,10 @@
#![feature(macro_rules)]
// shouldn't affect evaluation of $ex:
macro_rules! bad_macro (($ex:expr) => ({let _x = 9i; $ex}));
macro_rules! bad_macro {
($ex:expr) => ({let _x = 9i; $ex})
}
pub fn main() {
let _x = 8i;
assert_eq!(bad_macro!(_x),8i)

View file

@ -14,12 +14,12 @@
pub fn main() {
macro_rules! mylambda_tt(
macro_rules! mylambda_tt {
($x:ident, $body:expr) => ({
fn f($x: int) -> int { return $body; };
f
})
);
}
assert!(mylambda_tt!(y, y * 2)(8) == 16);
}

View file

@ -10,7 +10,7 @@
#![feature(macro_rules)]
macro_rules! overly_complicated (
macro_rules! overly_complicated {
($fnname:ident, $arg:ident, $ty:ty, $body:block, $val:expr, $pat:pat, $res:path) =>
({
fn $fnname($arg: $ty) -> Option<$ty> $body
@ -22,7 +22,7 @@ fn $fnname($arg: $ty) -> Option<$ty> $body
}
})
);
}
pub fn main() {
assert!(overly_complicated!(f, x, Option<uint>, { return Some(x); },

View file

@ -10,9 +10,9 @@
#![feature(macro_rules)]
macro_rules! four (
macro_rules! four {
() => (4)
);
}
fn main() {
let _x: [u16; four!()];

View file

@ -12,7 +12,7 @@
#![feature(macro_rules)]
macro_rules! make_foo(
macro_rules! make_foo {
() => (
struct Foo;
@ -20,7 +20,7 @@ impl Foo {
fn bar(&self) {}
}
)
);
}
make_foo!();

View file

@ -10,15 +10,15 @@
#![feature(macro_rules)]
macro_rules! list (
macro_rules! list {
( ($($id:ident),*) ) => (());
( [$($id:ident),*] ) => (());
( {$($id:ident),*} ) => (());
);
}
macro_rules! tt_list (
macro_rules! tt_list {
( ($($tt:tt),*) ) => (());
);
}
pub fn main() {
list!( () );

View file

@ -10,12 +10,12 @@
#![feature(macro_rules)]
macro_rules! higher_order (
macro_rules! higher_order {
(subst $lhs:tt => $rhs:tt) => ({
macro_rules! anon ( $lhs => $rhs );
macro_rules! anon { $lhs => $rhs }
anon!(1u, 2u, "foo")
});
);
}
fn main() {
let val = higher_order!(subst ($x:expr, $y:expr, $foo:expr) => (($x + $y, $foo)));

View file

@ -10,35 +10,35 @@
#![feature(macro_rules)]
macro_rules! mypat(
macro_rules! mypat {
() => (
Some('y')
)
);
}
macro_rules! char_x(
macro_rules! char_x {
() => (
'x'
)
);
}
macro_rules! some(
macro_rules! some {
($x:pat) => (
Some($x)
)
);
}
macro_rules! indirect(
macro_rules! indirect {
() => (
some!(char_x!())
)
);
}
macro_rules! ident_pat(
macro_rules! ident_pat {
($x:ident) => (
$x
)
);
}
fn f(c: Option<char>) -> uint {
match c {

View file

@ -12,21 +12,21 @@
#![feature(macro_rules)]
macro_rules! myfn(
macro_rules! myfn {
( $f:ident, ( $( $x:ident ),* ), $body:block ) => (
fn $f( $( $x : int),* ) -> int $body
)
);
}
myfn!(add, (a,b), { return a+b; } );
pub fn main() {
macro_rules! mylet(
macro_rules! mylet {
($x:ident, $val:expr) => (
let $x = $val;
)
);
}
mylet!(y, 8i*2);
assert_eq!(y, 16i);
@ -35,9 +35,9 @@ macro_rules! mylet(
assert_eq!(mult(2, add(4,4)), 16);
macro_rules! actually_an_expr_macro (
macro_rules! actually_an_expr_macro {
() => ( 16i )
);
}
assert_eq!({ actually_an_expr_macro!() }, 16i);

View file

@ -13,10 +13,10 @@
#![feature(macro_rules)]
#[cfg(foo)]
macro_rules! foo( () => (1i) );
macro_rules! foo { () => (1i) }
#[cfg(not(foo))]
macro_rules! foo( () => (2i) );
macro_rules! foo { () => (2i) }
pub fn main() {
assert_eq!(foo!(), 1i);

View file

@ -11,10 +11,10 @@
#![feature(macro_rules)]
#[cfg(foo)]
macro_rules! foo( () => (1i) );
macro_rules! foo { () => (1i) }
#[cfg(not(foo))]
macro_rules! foo( () => (2i) );
macro_rules! foo { () => (2i) }
pub fn main() {
assert_eq!(foo!(), 2i);

View file

@ -12,7 +12,7 @@
use std::thread::Thread;
macro_rules! expr (($e: expr) => { $e });
macro_rules! expr { ($e: expr) => { $e } }
macro_rules! spawn {
($($code: tt)*) => {

View file

@ -14,13 +14,13 @@ enum Foo {
B { b1: int, bb1: int},
}
macro_rules! match_inside_expansion(
macro_rules! match_inside_expansion {
() => (
match (Foo::B { b1:29 , bb1: 100}) {
Foo::B { b1:b2 , bb1:bb2 } => b2+bb2
}
)
);
}
pub fn main() {
assert_eq!(match_inside_expansion!(),129);

View file

@ -13,9 +13,9 @@
#![feature(macro_rules)]
// shouldn't affect evaluation of $ex.
macro_rules! bad_macro (($ex:expr) => (
macro_rules! bad_macro { ($ex:expr) => (
{match 9 {_x => $ex}}
))
)}
fn main() {
match 8 {

View file

@ -10,7 +10,7 @@
#![feature(macro_rules)]
macro_rules! quote_tokens ( () => (()) );
macro_rules! quote_tokens { () => (()) }
pub fn main() {
quote_tokens!();

View file

@ -21,7 +21,7 @@ pub fn where_am_i() -> String {
}
}
macro_rules! indirect_line( () => ( line!() ) );
macro_rules! indirect_line { () => ( line!() ) }
pub fn main() {
assert_eq!(line!(), 27);

View file

@ -20,7 +20,7 @@ enum T {
// doesn't cause capture. Making this macro hygienic (as I've done)
// could very well make this test case completely pointless....
macro_rules! test(
macro_rules! test {
($id1:ident, $id2:ident, $e:expr) => (
fn foo(a:T, b:T) -> T {
match (a, b) {
@ -30,7 +30,7 @@ fn foo(a:T, b:T) -> T {
}
}
)
);
}
test!(x,y,x + y);