diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-11-14 09:18:10 -0800 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2014-12-18 12:09:07 -0500 |
| commit | ddb2466f6a1bb66f22824334022a4cee61c73bdc (patch) | |
| tree | 9cb97d3e4c4521b56d0776e5f7bda81e62135be4 /src/libstd/num/mod.rs | |
| parent | c0b2885ee12b79c99ac8245edb6eebaaa8e7fef1 (diff) | |
| download | rust-ddb2466f6a1bb66f22824334022a4cee61c73bdc.tar.gz rust-ddb2466f6a1bb66f22824334022a4cee61c73bdc.zip | |
librustc: Always parse `macro!()`/`macro![]` as expressions if not
followed by a semicolon.
This allows code like `vec![1i, 2, 3].len();` to work.
This breaks code that uses macros as statements without putting
semicolons after them, such as:
fn main() {
...
assert!(a == b)
assert!(c == d)
println(...);
}
It also breaks code that uses macros as items without semicolons:
local_data_key!(foo)
fn main() {
println("hello world")
}
Add semicolons to fix this code. Those two examples can be fixed as
follows:
fn main() {
...
assert!(a == b);
assert!(c == d);
println(...);
}
local_data_key!(foo);
fn main() {
println("hello world")
}
RFC #378.
Closes #18635.
[breaking-change]
Diffstat (limited to 'src/libstd/num/mod.rs')
| -rw-r--r-- | src/libstd/num/mod.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 9aaaceb87e6..a568aafe1ed 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -161,7 +161,7 @@ mod tests { use u64; use uint; - macro_rules! test_cast_20( + macro_rules! test_cast_20 { ($_20:expr) => ({ let _20 = $_20; @@ -204,7 +204,7 @@ mod tests { assert_eq!(_20, cast(20f32).unwrap()); assert_eq!(_20, cast(20f64).unwrap()); }) - ) + } #[test] fn test_u8_cast() { test_cast_20!(20u8) } #[test] fn test_u16_cast() { test_cast_20!(20u16) } @@ -664,7 +664,7 @@ mod tests { assert_eq!(third.checked_mul(4), None); } - macro_rules! test_next_power_of_two( + macro_rules! test_next_power_of_two { ($test_name:ident, $T:ident) => ( fn $test_name() { #![test] @@ -676,15 +676,15 @@ mod tests { } } ) - ) + } - test_next_power_of_two!(test_next_power_of_two_u8, u8) - test_next_power_of_two!(test_next_power_of_two_u16, u16) - test_next_power_of_two!(test_next_power_of_two_u32, u32) - test_next_power_of_two!(test_next_power_of_two_u64, u64) - test_next_power_of_two!(test_next_power_of_two_uint, uint) + test_next_power_of_two! { test_next_power_of_two_u8, u8 } + test_next_power_of_two! { test_next_power_of_two_u16, u16 } + test_next_power_of_two! { test_next_power_of_two_u32, u32 } + test_next_power_of_two! { test_next_power_of_two_u64, u64 } + test_next_power_of_two! { test_next_power_of_two_uint, uint } - macro_rules! test_checked_next_power_of_two( + macro_rules! test_checked_next_power_of_two { ($test_name:ident, $T:ident) => ( fn $test_name() { #![test] @@ -699,13 +699,13 @@ mod tests { assert_eq!($T::MAX.checked_next_power_of_two(), None); } ) - ) + } - test_checked_next_power_of_two!(test_checked_next_power_of_two_u8, u8) - test_checked_next_power_of_two!(test_checked_next_power_of_two_u16, u16) - test_checked_next_power_of_two!(test_checked_next_power_of_two_u32, u32) - test_checked_next_power_of_two!(test_checked_next_power_of_two_u64, u64) - test_checked_next_power_of_two!(test_checked_next_power_of_two_uint, uint) + test_checked_next_power_of_two! { test_checked_next_power_of_two_u8, u8 } + test_checked_next_power_of_two! { test_checked_next_power_of_two_u16, u16 } + test_checked_next_power_of_two! { test_checked_next_power_of_two_u32, u32 } + test_checked_next_power_of_two! { test_checked_next_power_of_two_u64, u64 } + test_checked_next_power_of_two! { test_checked_next_power_of_two_uint, uint } #[deriving(PartialEq, Show)] struct Value { x: int } @@ -759,13 +759,13 @@ mod tests { let one: T = Int::one(); range(0, exp).fold(one, |acc, _| acc * base) } - macro_rules! assert_pow( + macro_rules! assert_pow { (($num:expr, $exp:expr) => $expected:expr) => {{ let result = $num.pow($exp); assert_eq!(result, $expected); assert_eq!(result, naive_pow($num, $exp)); }} - ) + } assert_pow!((3i, 0 ) => 1); assert_pow!((5i, 1 ) => 5); assert_pow!((-4i, 2 ) => 16); |
