]> git.lizzy.rs Git - rust.git/commitdiff
Allow macro-expanded macros in trailing expression positions to expand into statements:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Tue, 5 Jul 2016 08:21:25 +0000 (08:21 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Wed, 13 Jul 2016 04:49:32 +0000 (04:49 +0000)
```rust
macro_rules! m { () => { let x = 1; x } }
macro_rules! n { () => {
    m!() //< This can now expand into statements
}}
fn main() { n!(); }
```

and revert needless fallout fixes.

src/libsyntax/parse/parser.rs
src/test/run-pass/simd-intrinsic-generic-cast.rs

index b2cbe252344f778a8a01e1e61b32b2ee3b0802ce..454320337edcb97801805255ad7f4709895db329 100644 (file)
@@ -4066,7 +4066,8 @@ fn parse_block_tail(&mut self, lo: BytePos, s: BlockCheckMode) -> PResult<'a, P<
     /// (or the lack thereof) -- c.f. `parse_stmt`.
     pub fn finish_parsing_statement(&mut self, mut stmt: Stmt) -> PResult<'a, Stmt> {
         if let StmtKind::Mac(mac) = stmt.node {
-            if mac.1 != MacStmtStyle::NoBraces || self.token == token::Semi {
+            if mac.1 != MacStmtStyle::NoBraces ||
+               self.token == token::Semi || self.token == token::Eof {
                 stmt.node = StmtKind::Mac(mac);
             } else {
                 let (mac, _style, attrs) = mac.unwrap();
index 74c0f39e2e3c54405db47bba5c92bd51019e12f3..a20dd3ef72a54cd831eebf714931095419dd00ad 100644 (file)
@@ -113,7 +113,7 @@ macro_rules! tests {
         // product macro
         ($from: ident $(, $from_: ident)*: $($to: ident),*) => {
             fn $from() { unsafe { $( test!($from, $to); )* } }
-            tests!($($from_),*: $($to),*);
+            tests!($($from_),*: $($to),*)
         };
         ($($types: ident),*) => {{
             tests!($($types),* : $($types),*);