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]
This commit is contained in:
committed by
Jorge Aparicio
parent
c0b2885ee1
commit
ddb2466f6a
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user