1
Fork 0

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

@ -1970,7 +1970,7 @@ impl Decoder {
}
}
macro_rules! expect(
macro_rules! expect {
($e:expr, Null) => ({
match $e {
Json::Null => Ok(()),
@ -1987,7 +1987,7 @@ macro_rules! expect(
}
}
})
)
}
macro_rules! read_primitive {
($name:ident, $ty:ty) => {
@ -2020,16 +2020,16 @@ impl ::Decoder<DecoderError> for Decoder {
expect!(self.pop(), Null)
}
read_primitive!(read_uint, uint)
read_primitive!(read_u8, u8)
read_primitive!(read_u16, u16)
read_primitive!(read_u32, u32)
read_primitive!(read_u64, u64)
read_primitive!(read_int, int)
read_primitive!(read_i8, i8)
read_primitive!(read_i16, i16)
read_primitive!(read_i32, i32)
read_primitive!(read_i64, i64)
read_primitive! { read_uint, uint }
read_primitive! { read_u8, u8 }
read_primitive! { read_u16, u16 }
read_primitive! { read_u32, u32 }
read_primitive! { read_u64, u64 }
read_primitive! { read_int, int }
read_primitive! { read_i8, i8 }
read_primitive! { read_i16, i16 }
read_primitive! { read_i32, i32 }
read_primitive! { read_i64, i64 }
fn read_f32(&mut self) -> DecodeResult<f32> { self.read_f64().map(|x| x as f32) }
@ -2298,25 +2298,25 @@ pub trait ToJson for Sized? {
fn to_json(&self) -> Json;
}
macro_rules! to_json_impl_i64(
macro_rules! to_json_impl_i64 {
($($t:ty), +) => (
$(impl ToJson for $t {
fn to_json(&self) -> Json { Json::I64(*self as i64) }
})+
)
)
}
to_json_impl_i64!(int, i8, i16, i32, i64)
to_json_impl_i64! { int, i8, i16, i32, i64 }
macro_rules! to_json_impl_u64(
macro_rules! to_json_impl_u64 {
($($t:ty), +) => (
$(impl ToJson for $t {
fn to_json(&self) -> Json { Json::U64(*self as u64) }
})+
)
)
}
to_json_impl_u64!(uint, u8, u16, u32, u64)
to_json_impl_u64! { uint, u8, u16, u32, u64 }
impl ToJson for Json {
fn to_json(&self) -> Json { self.clone() }
@ -2730,7 +2730,7 @@ mod tests {
);
}
macro_rules! check_encoder_for_simple(
macro_rules! check_encoder_for_simple {
($value:expr, $expected:expr) => ({
let s = with_str_writer(|writer| {
let mut encoder = Encoder::new(writer);
@ -2744,7 +2744,7 @@ mod tests {
});
assert_eq!(s, $expected);
})
)
}
#[test]
fn test_write_some() {
@ -2948,7 +2948,7 @@ mod tests {
#[test]
fn test_decode_tuple() {
let t: (uint, uint, uint) = super::decode("[1, 2, 3]").unwrap();
assert_eq!(t, (1u, 2, 3))
assert_eq!(t, (1u, 2, 3));
let t: (uint, string::String) = super::decode("[1, \"two\"]").unwrap();
assert_eq!(t, (1u, "two".into_string()));