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
@@ -671,8 +671,8 @@ mod tests {
|
||||
let inf: f32 = Float::infinity();
|
||||
let neg_inf: f32 = Float::neg_infinity();
|
||||
let nan: f32 = Float::nan();
|
||||
assert_eq!(match inf.frexp() { (x, _) => x }, inf)
|
||||
assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf)
|
||||
assert_eq!(match inf.frexp() { (x, _) => x }, inf);
|
||||
assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf);
|
||||
assert!(match nan.frexp() { (x, _) => x.is_nan() })
|
||||
}
|
||||
|
||||
|
||||
@@ -673,8 +673,8 @@ mod tests {
|
||||
let inf: f64 = Float::infinity();
|
||||
let neg_inf: f64 = Float::neg_infinity();
|
||||
let nan: f64 = Float::nan();
|
||||
assert_eq!(match inf.frexp() { (x, _) => x }, inf)
|
||||
assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf)
|
||||
assert_eq!(match inf.frexp() { (x, _) => x }, inf);
|
||||
assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf);
|
||||
assert!(match nan.frexp() { (x, _) => x.is_nan() })
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
#![macro_escape]
|
||||
#![doc(hidden)]
|
||||
|
||||
macro_rules! assert_approx_eq(
|
||||
macro_rules! assert_approx_eq {
|
||||
($a:expr, $b:expr) => ({
|
||||
use num::Float;
|
||||
let (a, b) = (&$a, &$b);
|
||||
assert!((*a - *b).abs() < 1.0e-6,
|
||||
"{} is not approximately equal to {}", *a, *b);
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,4 +15,4 @@
|
||||
|
||||
pub use core::i16::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
int_module!(i16)
|
||||
int_module! { i16 }
|
||||
|
||||
@@ -15,4 +15,4 @@
|
||||
|
||||
pub use core::i32::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
int_module!(i32)
|
||||
int_module! { i32 }
|
||||
|
||||
@@ -15,4 +15,4 @@
|
||||
|
||||
pub use core::i64::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
int_module!(i64)
|
||||
int_module! { i64 }
|
||||
|
||||
@@ -15,4 +15,4 @@
|
||||
|
||||
pub use core::i8::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
int_module!(i8)
|
||||
int_module! { i8 }
|
||||
|
||||
@@ -15,4 +15,4 @@
|
||||
|
||||
pub use core::int::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
int_module!(int)
|
||||
int_module! { int }
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
#![macro_escape]
|
||||
#![doc(hidden)]
|
||||
|
||||
macro_rules! int_module (($T:ty) => (
|
||||
macro_rules! int_module { ($T:ty) => (
|
||||
|
||||
))
|
||||
) }
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -17,4 +17,4 @@ pub use core::u16::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
use ops::FnOnce;
|
||||
|
||||
uint_module!(u16)
|
||||
uint_module! { u16 }
|
||||
|
||||
@@ -17,4 +17,4 @@ pub use core::u32::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
use ops::FnOnce;
|
||||
|
||||
uint_module!(u32)
|
||||
uint_module! { u32 }
|
||||
|
||||
@@ -17,4 +17,4 @@ pub use core::u64::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
use ops::FnOnce;
|
||||
|
||||
uint_module!(u64)
|
||||
uint_module! { u64 }
|
||||
|
||||
@@ -17,4 +17,4 @@ pub use core::u8::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
use ops::FnOnce;
|
||||
|
||||
uint_module!(u8)
|
||||
uint_module! { u8 }
|
||||
|
||||
@@ -17,4 +17,4 @@ pub use core::uint::{BITS, BYTES, MIN, MAX};
|
||||
|
||||
use ops::FnOnce;
|
||||
|
||||
uint_module!(uint)
|
||||
uint_module! { uint }
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#![doc(hidden)]
|
||||
#![allow(unsigned_negation)]
|
||||
|
||||
macro_rules! uint_module (($T:ty) => (
|
||||
macro_rules! uint_module { ($T:ty) => (
|
||||
|
||||
// String conversion functions and impl num -> str
|
||||
|
||||
@@ -141,4 +141,4 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
))
|
||||
) }
|
||||
|
||||
Reference in New Issue
Block a user