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

@@ -135,7 +135,7 @@ pub trait Default {
fn default() -> Self;
}
macro_rules! default_impl(
macro_rules! default_impl {
($t:ty, $v:expr) => {
#[stable]
impl Default for $t {
@@ -144,23 +144,24 @@ macro_rules! default_impl(
fn default() -> $t { $v }
}
}
)
}
default_impl!((), ())
default_impl!(bool, false)
default_impl!(char, '\x00')
default_impl! { (), () }
default_impl! { bool, false }
default_impl! { char, '\x00' }
default_impl!(uint, 0u)
default_impl!(u8, 0u8)
default_impl!(u16, 0u16)
default_impl!(u32, 0u32)
default_impl!(u64, 0u64)
default_impl! { uint, 0u }
default_impl! { u8, 0u8 }
default_impl! { u16, 0u16 }
default_impl! { u32, 0u32 }
default_impl! { u64, 0u64 }
default_impl!(int, 0i)
default_impl!(i8, 0i8)
default_impl!(i16, 0i16)
default_impl!(i32, 0i32)
default_impl!(i64, 0i64)
default_impl! { int, 0i }
default_impl! { i8, 0i8 }
default_impl! { i16, 0i16 }
default_impl! { i32, 0i32 }
default_impl! { i64, 0i64 }
default_impl! { f32, 0.0f32 }
default_impl! { f64, 0.0f64 }
default_impl!(f32, 0.0f32)
default_impl!(f64, 0.0f64)