about summary refs log tree commit diff
path: root/src/libcore/macros.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-11-14 09:18:10 -0800
committerJorge Aparicio <japaricious@gmail.com>2014-12-18 12:09:07 -0500
commitddb2466f6a1bb66f22824334022a4cee61c73bdc (patch)
tree9cb97d3e4c4521b56d0776e5f7bda81e62135be4 /src/libcore/macros.rs
parentc0b2885ee12b79c99ac8245edb6eebaaa8e7fef1 (diff)
downloadrust-ddb2466f6a1bb66f22824334022a4cee61c73bdc.tar.gz
rust-ddb2466f6a1bb66f22824334022a4cee61c73bdc.zip
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]
Diffstat (limited to 'src/libcore/macros.rs')
-rw-r--r--src/libcore/macros.rs39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index 9016f40b1b8..7ce1da7d2d0 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -12,7 +12,7 @@
 
 /// Entry point of task panic, for details, see std::macros
 #[macro_export]
-macro_rules! panic(
+macro_rules! panic {
     () => (
         panic!("{}", "explicit panic")
     );
@@ -44,11 +44,11 @@ macro_rules! panic(
         }
         format_args!(_run_fmt, $fmt, $($arg)*)
     });
-)
+}
 
 /// Runtime assertion, for details see std::macros
 #[macro_export]
-macro_rules! assert(
+macro_rules! assert {
     ($cond:expr) => (
         if !$cond {
             panic!(concat!("assertion failed: ", stringify!($cond)))
@@ -59,21 +59,21 @@ macro_rules! assert(
             panic!($($arg)*)
         }
     );
-)
+}
 
 /// Runtime assertion, only without `--cfg ndebug`
 #[macro_export]
-macro_rules! debug_assert(
+macro_rules! debug_assert {
     ($(a:tt)*) => ({
         if cfg!(not(ndebug)) {
             assert!($($a)*);
         }
     })
-)
+}
 
 /// Runtime assertion for equality, for details see std::macros
 #[macro_export]
-macro_rules! assert_eq(
+macro_rules! assert_eq {
     ($cond1:expr, $cond2:expr) => ({
         let c1 = $cond1;
         let c2 = $cond2;
@@ -81,46 +81,47 @@ macro_rules! assert_eq(
             panic!("expressions not equal, left: {}, right: {}", c1, c2);
         }
     })
-)
+}
 
 /// Runtime assertion for equality, only without `--cfg ndebug`
 #[macro_export]
-macro_rules! debug_assert_eq(
+macro_rules! debug_assert_eq {
     ($($a:tt)*) => ({
         if cfg!(not(ndebug)) {
             assert_eq!($($a)*);
         }
     })
-)
+}
 
 /// Runtime assertion, disableable at compile time
 #[macro_export]
-macro_rules! debug_assert(
+macro_rules! debug_assert {
     ($($arg:tt)*) => (if cfg!(not(ndebug)) { assert!($($arg)*); })
-)
+}
 
 /// Short circuiting evaluation on Err
 #[macro_export]
-macro_rules! try(
+macro_rules! try {
     ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
-)
+}
 
 /// Writing a formatted string into a writer
 #[macro_export]
-macro_rules! write(
+macro_rules! write {
     ($dst:expr, $($arg:tt)*) => ({
         let dst = &mut *$dst;
         format_args!(|args| { dst.write_fmt(args) }, $($arg)*)
     })
-)
+}
 
 /// Writing a formatted string plus a newline into a writer
 #[macro_export]
-macro_rules! writeln(
+macro_rules! writeln {
     ($dst:expr, $fmt:expr $($arg:tt)*) => (
         write!($dst, concat!($fmt, "\n") $($arg)*)
     )
-)
+}
 
 #[macro_export]
-macro_rules! unreachable( () => (panic!("unreachable code")) )
+macro_rules! unreachable { () => (panic!("unreachable code")) }
+