From 3e99309bfc318c13e4ac82cf086b26d694f9c53c Mon Sep 17 00:00:00 2001 From: John Clements Date: Thu, 3 Jul 2014 13:10:54 -0700 Subject: [PATCH] make any_pat! and u64_from_be_bytes_bench_impl! macros hygienic --- src/librustc/middle/trans/_match.rs | 8 ++++---- src/libstd/io/extensions.rs | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 655973c3d33..5b599a06925 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -796,9 +796,9 @@ fn extract_vec_elems<'a>( // matches should fit that sort of pattern or NONE (however, some of the // matches may be wildcards like _ or identifiers). macro_rules! any_pat ( - ($m:expr, $pattern:pat) => ( + ($m:expr, $col:expr, $pattern:pat) => ( ($m).iter().any(|br| { - match br.pats.get(col).node { + match br.pats.get($col).node { $pattern => true, _ => false } @@ -807,11 +807,11 @@ macro_rules! any_pat ( ) fn any_uniq_pat(m: &[Match], col: uint) -> bool { - any_pat!(m, ast::PatBox(_)) + any_pat!(m, col, ast::PatBox(_)) } fn any_region_pat(m: &[Match], col: uint) -> bool { - any_pat!(m, ast::PatRegion(_)) + any_pat!(m, col, ast::PatRegion(_)) } fn any_irrefutable_adt_pat(bcx: &Block, m: &[Match], col: uint) -> bool { diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 277aca2332d..ca3eee01575 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -508,14 +508,15 @@ mod bench { use prelude::*; use self::test::Bencher; + // why is this a macro? wouldn't an inlined function work just as well? macro_rules! u64_from_be_bytes_bench_impl( - ($size:expr, $stride:expr, $start_index:expr) => + ($b:expr, $size:expr, $stride:expr, $start_index:expr) => ({ use super::u64_from_be_bytes; let data = Vec::from_fn($stride*100+$start_index, |i| i as u8); let mut sum = 0u64; - b.iter(|| { + $b.iter(|| { let mut i = $start_index; while i < data.len() { sum += u64_from_be_bytes(data.as_slice(), i, $size); @@ -527,31 +528,31 @@ mod bench { #[bench] fn u64_from_be_bytes_4_aligned(b: &mut Bencher) { - u64_from_be_bytes_bench_impl!(4, 4, 0); + u64_from_be_bytes_bench_impl!(b, 4, 4, 0); } #[bench] fn u64_from_be_bytes_4_unaligned(b: &mut Bencher) { - u64_from_be_bytes_bench_impl!(4, 4, 1); + u64_from_be_bytes_bench_impl!(b, 4, 4, 1); } #[bench] fn u64_from_be_bytes_7_aligned(b: &mut Bencher) { - u64_from_be_bytes_bench_impl!(7, 8, 0); + u64_from_be_bytes_bench_impl!(b, 7, 8, 0); } #[bench] fn u64_from_be_bytes_7_unaligned(b: &mut Bencher) { - u64_from_be_bytes_bench_impl!(7, 8, 1); + u64_from_be_bytes_bench_impl!(b, 7, 8, 1); } #[bench] fn u64_from_be_bytes_8_aligned(b: &mut Bencher) { - u64_from_be_bytes_bench_impl!(8, 8, 0); + u64_from_be_bytes_bench_impl!(b, 8, 8, 0); } #[bench] fn u64_from_be_bytes_8_unaligned(b: &mut Bencher) { - u64_from_be_bytes_bench_impl!(8, 8, 1); + u64_from_be_bytes_bench_impl!(b, 8, 8, 1); } }