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:
Patrick Walton
2014-11-14 09:18:10 -08:00
committed by Jorge Aparicio
parent c0b2885ee1
commit ddb2466f6a
222 changed files with 2330 additions and 2039 deletions

View File

@@ -458,61 +458,61 @@ macro_rules! uint_impl {
/// consistency with the other `bswap` intrinsics.
unsafe fn bswap8(x: u8) -> u8 { x }
uint_impl!(u8 = u8, 8,
uint_impl! { u8 = u8, 8,
intrinsics::ctpop8,
intrinsics::ctlz8,
intrinsics::cttz8,
bswap8,
intrinsics::u8_add_with_overflow,
intrinsics::u8_sub_with_overflow,
intrinsics::u8_mul_with_overflow)
intrinsics::u8_mul_with_overflow }
uint_impl!(u16 = u16, 16,
uint_impl! { u16 = u16, 16,
intrinsics::ctpop16,
intrinsics::ctlz16,
intrinsics::cttz16,
intrinsics::bswap16,
intrinsics::u16_add_with_overflow,
intrinsics::u16_sub_with_overflow,
intrinsics::u16_mul_with_overflow)
intrinsics::u16_mul_with_overflow }
uint_impl!(u32 = u32, 32,
uint_impl! { u32 = u32, 32,
intrinsics::ctpop32,
intrinsics::ctlz32,
intrinsics::cttz32,
intrinsics::bswap32,
intrinsics::u32_add_with_overflow,
intrinsics::u32_sub_with_overflow,
intrinsics::u32_mul_with_overflow)
intrinsics::u32_mul_with_overflow }
uint_impl!(u64 = u64, 64,
uint_impl! { u64 = u64, 64,
intrinsics::ctpop64,
intrinsics::ctlz64,
intrinsics::cttz64,
intrinsics::bswap64,
intrinsics::u64_add_with_overflow,
intrinsics::u64_sub_with_overflow,
intrinsics::u64_mul_with_overflow)
intrinsics::u64_mul_with_overflow }
#[cfg(target_word_size = "32")]
uint_impl!(uint = u32, 32,
uint_impl! { uint = u32, 32,
intrinsics::ctpop32,
intrinsics::ctlz32,
intrinsics::cttz32,
intrinsics::bswap32,
intrinsics::u32_add_with_overflow,
intrinsics::u32_sub_with_overflow,
intrinsics::u32_mul_with_overflow)
intrinsics::u32_mul_with_overflow }
#[cfg(target_word_size = "64")]
uint_impl!(uint = u64, 64,
uint_impl! { uint = u64, 64,
intrinsics::ctpop64,
intrinsics::ctlz64,
intrinsics::cttz64,
intrinsics::bswap64,
intrinsics::u64_add_with_overflow,
intrinsics::u64_sub_with_overflow,
intrinsics::u64_mul_with_overflow)
intrinsics::u64_mul_with_overflow }
macro_rules! int_impl {
($T:ty = $ActualT:ty, $UnsignedT:ty, $BITS:expr,
@@ -579,37 +579,37 @@ macro_rules! int_impl {
}
}
int_impl!(i8 = i8, u8, 8,
int_impl! { i8 = i8, u8, 8,
intrinsics::i8_add_with_overflow,
intrinsics::i8_sub_with_overflow,
intrinsics::i8_mul_with_overflow)
intrinsics::i8_mul_with_overflow }
int_impl!(i16 = i16, u16, 16,
int_impl! { i16 = i16, u16, 16,
intrinsics::i16_add_with_overflow,
intrinsics::i16_sub_with_overflow,
intrinsics::i16_mul_with_overflow)
intrinsics::i16_mul_with_overflow }
int_impl!(i32 = i32, u32, 32,
int_impl! { i32 = i32, u32, 32,
intrinsics::i32_add_with_overflow,
intrinsics::i32_sub_with_overflow,
intrinsics::i32_mul_with_overflow)
intrinsics::i32_mul_with_overflow }
int_impl!(i64 = i64, u64, 64,
int_impl! { i64 = i64, u64, 64,
intrinsics::i64_add_with_overflow,
intrinsics::i64_sub_with_overflow,
intrinsics::i64_mul_with_overflow)
intrinsics::i64_mul_with_overflow }
#[cfg(target_word_size = "32")]
int_impl!(int = i32, u32, 32,
int_impl! { int = i32, u32, 32,
intrinsics::i32_add_with_overflow,
intrinsics::i32_sub_with_overflow,
intrinsics::i32_mul_with_overflow)
intrinsics::i32_mul_with_overflow }
#[cfg(target_word_size = "64")]
int_impl!(int = i64, u64, 64,
int_impl! { int = i64, u64, 64,
intrinsics::i64_add_with_overflow,
intrinsics::i64_sub_with_overflow,
intrinsics::i64_mul_with_overflow)
intrinsics::i64_mul_with_overflow }
/// A built-in two's complement integer.
#[unstable = "recently settled as part of numerics reform"]
@@ -663,11 +663,11 @@ macro_rules! signed_int_impl {
}
}
signed_int_impl!(i8)
signed_int_impl!(i16)
signed_int_impl!(i32)
signed_int_impl!(i64)
signed_int_impl!(int)
signed_int_impl! { i8 }
signed_int_impl! { i16 }
signed_int_impl! { i32 }
signed_int_impl! { i64 }
signed_int_impl! { int }
/// A built-in unsigned integer.
#[unstable = "recently settled as part of numerics reform"]
@@ -791,7 +791,7 @@ pub trait ToPrimitive {
}
}
macro_rules! impl_to_primitive_int_to_int(
macro_rules! impl_to_primitive_int_to_int {
($SrcT:ty, $DstT:ty, $slf:expr) => (
{
if size_of::<$SrcT>() <= size_of::<$DstT>() {
@@ -808,9 +808,9 @@ macro_rules! impl_to_primitive_int_to_int(
}
}
)
)
}
macro_rules! impl_to_primitive_int_to_uint(
macro_rules! impl_to_primitive_int_to_uint {
($SrcT:ty, $DstT:ty, $slf:expr) => (
{
let zero: $SrcT = Int::zero();
@@ -822,9 +822,9 @@ macro_rules! impl_to_primitive_int_to_uint(
}
}
)
)
}
macro_rules! impl_to_primitive_int(
macro_rules! impl_to_primitive_int {
($T:ty) => (
impl ToPrimitive for $T {
#[inline]
@@ -855,15 +855,15 @@ macro_rules! impl_to_primitive_int(
fn to_f64(&self) -> Option<f64> { Some(*self as f64) }
}
)
)
}
impl_to_primitive_int!(int)
impl_to_primitive_int!(i8)
impl_to_primitive_int!(i16)
impl_to_primitive_int!(i32)
impl_to_primitive_int!(i64)
impl_to_primitive_int! { int }
impl_to_primitive_int! { i8 }
impl_to_primitive_int! { i16 }
impl_to_primitive_int! { i32 }
impl_to_primitive_int! { i64 }
macro_rules! impl_to_primitive_uint_to_int(
macro_rules! impl_to_primitive_uint_to_int {
($DstT:ty, $slf:expr) => (
{
let max_value: $DstT = Int::max_value();
@@ -874,9 +874,9 @@ macro_rules! impl_to_primitive_uint_to_int(
}
}
)
)
}
macro_rules! impl_to_primitive_uint_to_uint(
macro_rules! impl_to_primitive_uint_to_uint {
($SrcT:ty, $DstT:ty, $slf:expr) => (
{
if size_of::<$SrcT>() <= size_of::<$DstT>() {
@@ -892,9 +892,9 @@ macro_rules! impl_to_primitive_uint_to_uint(
}
}
)
)
}
macro_rules! impl_to_primitive_uint(
macro_rules! impl_to_primitive_uint {
($T:ty) => (
impl ToPrimitive for $T {
#[inline]
@@ -925,15 +925,15 @@ macro_rules! impl_to_primitive_uint(
fn to_f64(&self) -> Option<f64> { Some(*self as f64) }
}
)
)
}
impl_to_primitive_uint!(uint)
impl_to_primitive_uint!(u8)
impl_to_primitive_uint!(u16)
impl_to_primitive_uint!(u32)
impl_to_primitive_uint!(u64)
impl_to_primitive_uint! { uint }
impl_to_primitive_uint! { u8 }
impl_to_primitive_uint! { u16 }
impl_to_primitive_uint! { u32 }
impl_to_primitive_uint! { u64 }
macro_rules! impl_to_primitive_float_to_float(
macro_rules! impl_to_primitive_float_to_float {
($SrcT:ty, $DstT:ty, $slf:expr) => (
if size_of::<$SrcT>() <= size_of::<$DstT>() {
Some($slf as $DstT)
@@ -947,9 +947,9 @@ macro_rules! impl_to_primitive_float_to_float(
}
}
)
)
}
macro_rules! impl_to_primitive_float(
macro_rules! impl_to_primitive_float {
($T:ty) => (
impl ToPrimitive for $T {
#[inline]
@@ -980,10 +980,10 @@ macro_rules! impl_to_primitive_float(
fn to_f64(&self) -> Option<f64> { impl_to_primitive_float_to_float!($T, f64, *self) }
}
)
)
}
impl_to_primitive_float!(f32)
impl_to_primitive_float!(f64)
impl_to_primitive_float! { f32 }
impl_to_primitive_float! { f64 }
/// A generic trait for converting a number to a value.
#[experimental = "trait is likely to be removed"]
@@ -1139,7 +1139,7 @@ pub fn from_f64<A: FromPrimitive>(n: f64) -> Option<A> {
FromPrimitive::from_f64(n)
}
macro_rules! impl_from_primitive(
macro_rules! impl_from_primitive {
($T:ty, $to_ty:ident) => (
impl FromPrimitive for $T {
#[inline] fn from_int(n: int) -> Option<$T> { n.$to_ty() }
@@ -1158,20 +1158,20 @@ macro_rules! impl_from_primitive(
#[inline] fn from_f64(n: f64) -> Option<$T> { n.$to_ty() }
}
)
)
}
impl_from_primitive!(int, to_int)
impl_from_primitive!(i8, to_i8)
impl_from_primitive!(i16, to_i16)
impl_from_primitive!(i32, to_i32)
impl_from_primitive!(i64, to_i64)
impl_from_primitive!(uint, to_uint)
impl_from_primitive!(u8, to_u8)
impl_from_primitive!(u16, to_u16)
impl_from_primitive!(u32, to_u32)
impl_from_primitive!(u64, to_u64)
impl_from_primitive!(f32, to_f32)
impl_from_primitive!(f64, to_f64)
impl_from_primitive! { int, to_int }
impl_from_primitive! { i8, to_i8 }
impl_from_primitive! { i16, to_i16 }
impl_from_primitive! { i32, to_i32 }
impl_from_primitive! { i64, to_i64 }
impl_from_primitive! { uint, to_uint }
impl_from_primitive! { u8, to_u8 }
impl_from_primitive! { u16, to_u16 }
impl_from_primitive! { u32, to_u32 }
impl_from_primitive! { u64, to_u64 }
impl_from_primitive! { f32, to_f32 }
impl_from_primitive! { f64, to_f64 }
/// Cast from one machine scalar to another.
///
@@ -1198,7 +1198,7 @@ pub trait NumCast: ToPrimitive {
fn from<T: ToPrimitive>(n: T) -> Option<Self>;
}
macro_rules! impl_num_cast(
macro_rules! impl_num_cast {
($T:ty, $conv:ident) => (
impl NumCast for $T {
#[inline]
@@ -1209,20 +1209,20 @@ macro_rules! impl_num_cast(
}
}
)
)
}
impl_num_cast!(u8, to_u8)
impl_num_cast!(u16, to_u16)
impl_num_cast!(u32, to_u32)
impl_num_cast!(u64, to_u64)
impl_num_cast!(uint, to_uint)
impl_num_cast!(i8, to_i8)
impl_num_cast!(i16, to_i16)
impl_num_cast!(i32, to_i32)
impl_num_cast!(i64, to_i64)
impl_num_cast!(int, to_int)
impl_num_cast!(f32, to_f32)
impl_num_cast!(f64, to_f64)
impl_num_cast! { u8, to_u8 }
impl_num_cast! { u16, to_u16 }
impl_num_cast! { u32, to_u32 }
impl_num_cast! { u64, to_u64 }
impl_num_cast! { uint, to_uint }
impl_num_cast! { i8, to_i8 }
impl_num_cast! { i16, to_i16 }
impl_num_cast! { i32, to_i32 }
impl_num_cast! { i64, to_i64 }
impl_num_cast! { int, to_int }
impl_num_cast! { f32, to_f32 }
impl_num_cast! { f64, to_f64 }
/// Used for representing the classification of floating point numbers
#[deriving(PartialEq, Show)]
@@ -1638,8 +1638,8 @@ macro_rules! from_str_radix_float_impl {
}
}
}
from_str_radix_float_impl!(f32)
from_str_radix_float_impl!(f64)
from_str_radix_float_impl! { f32 }
from_str_radix_float_impl! { f64 }
macro_rules! from_str_radix_int_impl {
($T:ty) => {
@@ -1705,16 +1705,16 @@ macro_rules! from_str_radix_int_impl {
}
}
}
from_str_radix_int_impl!(int)
from_str_radix_int_impl!(i8)
from_str_radix_int_impl!(i16)
from_str_radix_int_impl!(i32)
from_str_radix_int_impl!(i64)
from_str_radix_int_impl!(uint)
from_str_radix_int_impl!(u8)
from_str_radix_int_impl!(u16)
from_str_radix_int_impl!(u32)
from_str_radix_int_impl!(u64)
from_str_radix_int_impl! { int }
from_str_radix_int_impl! { i8 }
from_str_radix_int_impl! { i16 }
from_str_radix_int_impl! { i32 }
from_str_radix_int_impl! { i64 }
from_str_radix_int_impl! { uint }
from_str_radix_int_impl! { u8 }
from_str_radix_int_impl! { u16 }
from_str_radix_int_impl! { u32 }
from_str_radix_int_impl! { u64 }
// DEPRECATED
@@ -1733,17 +1733,17 @@ pub trait Num: PartialEq + Zero + One
+ Mul<Self,Self>
+ Div<Self,Self>
+ Rem<Self,Self> {}
trait_impl!(Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
trait_impl! { Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
#[deprecated = "Generalised unsigned numbers are no longer supported"]
#[allow(deprecated)]
pub trait Unsigned: Num {}
trait_impl!(Unsigned for uint u8 u16 u32 u64)
trait_impl! { Unsigned for uint u8 u16 u32 u64 }
#[deprecated = "Use `Float` or `Int`"]
#[allow(deprecated)]
pub trait Primitive: Copy + Clone + Num + NumCast + PartialOrd {}
trait_impl!(Primitive for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
trait_impl! { Primitive for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
#[deprecated = "The generic `Zero` trait will be removed soon."]
pub trait Zero: Add<Self, Self> {
@@ -1763,18 +1763,18 @@ macro_rules! zero_impl {
}
}
}
zero_impl!(uint, 0u)
zero_impl!(u8, 0u8)
zero_impl!(u16, 0u16)
zero_impl!(u32, 0u32)
zero_impl!(u64, 0u64)
zero_impl!(int, 0i)
zero_impl!(i8, 0i8)
zero_impl!(i16, 0i16)
zero_impl!(i32, 0i32)
zero_impl!(i64, 0i64)
zero_impl!(f32, 0.0f32)
zero_impl!(f64, 0.0f64)
zero_impl! { uint, 0u }
zero_impl! { u8, 0u8 }
zero_impl! { u16, 0u16 }
zero_impl! { u32, 0u32 }
zero_impl! { u64, 0u64 }
zero_impl! { int, 0i }
zero_impl! { i8, 0i8 }
zero_impl! { i16, 0i16 }
zero_impl! { i32, 0i32 }
zero_impl! { i64, 0i64 }
zero_impl! { f32, 0.0f32 }
zero_impl! { f64, 0.0f64 }
#[deprecated = "The generic `One` trait will be removed soon."]
pub trait One: Mul<Self, Self> {
@@ -1791,18 +1791,18 @@ macro_rules! one_impl {
}
}
}
one_impl!(uint, 1u)
one_impl!(u8, 1u8)
one_impl!(u16, 1u16)
one_impl!(u32, 1u32)
one_impl!(u64, 1u64)
one_impl!(int, 1i)
one_impl!(i8, 1i8)
one_impl!(i16, 1i16)
one_impl!(i32, 1i32)
one_impl!(i64, 1i64)
one_impl!(f32, 1.0f32)
one_impl!(f64, 1.0f64)
one_impl! { uint, 1u }
one_impl! { u8, 1u8 }
one_impl! { u16, 1u16 }
one_impl! { u32, 1u32 }
one_impl! { u64, 1u64 }
one_impl! { int, 1i }
one_impl! { i8, 1i8 }
one_impl! { i16, 1i16 }
one_impl! { i32, 1i32 }
one_impl! { i64, 1i64 }
one_impl! { f32, 1.0f32 }
one_impl! { f64, 1.0f64 }
#[deprecated = "Use `UnsignedInt::next_power_of_two`"]
pub fn next_power_of_two<T: UnsignedInt>(n: T) -> T {
@@ -1835,15 +1835,15 @@ macro_rules! bounded_impl {
}
};
}
bounded_impl!(uint, uint::MIN, uint::MAX)
bounded_impl!(u8, u8::MIN, u8::MAX)
bounded_impl!(u16, u16::MIN, u16::MAX)
bounded_impl!(u32, u32::MIN, u32::MAX)
bounded_impl!(u64, u64::MIN, u64::MAX)
bounded_impl!(int, int::MIN, int::MAX)
bounded_impl!(i8, i8::MIN, i8::MAX)
bounded_impl!(i16, i16::MIN, i16::MAX)
bounded_impl!(i32, i32::MIN, i32::MAX)
bounded_impl!(i64, i64::MIN, i64::MAX)
bounded_impl!(f32, f32::MIN_VALUE, f32::MAX_VALUE)
bounded_impl!(f64, f64::MIN_VALUE, f64::MAX_VALUE)
bounded_impl! { uint, uint::MIN, uint::MAX }
bounded_impl! { u8, u8::MIN, u8::MAX }
bounded_impl! { u16, u16::MIN, u16::MAX }
bounded_impl! { u32, u32::MIN, u32::MAX }
bounded_impl! { u64, u64::MIN, u64::MAX }
bounded_impl! { int, int::MIN, int::MAX }
bounded_impl! { i8, i8::MIN, i8::MAX }
bounded_impl! { i16, i16::MIN, i16::MAX }
bounded_impl! { i32, i32::MIN, i32::MAX }
bounded_impl! { i64, i64::MIN, i64::MAX }
bounded_impl! { f32, f32::MIN_VALUE, f32::MAX_VALUE }
bounded_impl! { f64, f64::MIN_VALUE, f64::MAX_VALUE }