summary refs log tree commit diff
path: root/src/libsyntax/print
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-03-03 18:41:47 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2014-03-03 22:48:42 +1100
commitc3b904704031047ef9e1f7906d3faee15778ffe5 (patch)
treec5effad359313654e966bdac21a1b6767010c94f /src/libsyntax/print
parent3f3425a5550e7d8b58d782425b09eab20b91c1c0 (diff)
downloadrust-c3b904704031047ef9e1f7906d3faee15778ffe5.tar.gz
rust-c3b904704031047ef9e1f7906d3faee15778ffe5.zip
syntax: make match arms store the expr directly.
Previously `ast::Arm` was always storing a single `ast::Expr` wrapped in an
`ast::Block` (for historical reasons, AIUI), so we might as just store
that expr directly.

Closes #3085.
Diffstat (limited to 'src/libsyntax/print')
-rw-r--r--src/libsyntax/print/pprust.rs44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index ec8c474d194..e8c32d07c74 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1352,38 +1352,22 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> {
             }
             try!(word_space(s, "=>"));
 
-            // Extract the expression from the extra block the parser adds
-            // in the case of foo => expr
-            if arm.body.view_items.is_empty() &&
-                arm.body.stmts.is_empty() &&
-                arm.body.rules == ast::DefaultBlock &&
-                arm.body.expr.is_some()
-            {
-                match arm.body.expr {
-                    Some(expr) => {
-                        match expr.node {
-                            ast::ExprBlock(blk) => {
-                                // the block will close the pattern's ibox
-                                try!(print_block_unclosed_indent(
-                                    s, blk, indent_unit));
-                            }
-                            _ => {
-                                try!(end(s)); // close the ibox for the pattern
-                                try!(print_expr(s, expr));
-                            }
-                        }
-                        if !expr_is_simple_block(expr)
-                            && i < len - 1 {
-                            try!(word(&mut s.s, ","));
-                        }
-                        try!(end(s)); // close enclosing cbox
-                    }
-                    None => fail!()
+            match arm.body.node {
+                ast::ExprBlock(blk) => {
+                    // the block will close the pattern's ibox
+                    try!(print_block_unclosed_indent(
+                                s, blk, indent_unit));
                 }
-            } else {
-                // the block will close the pattern's ibox
-                try!(print_block_unclosed_indent(s, arm.body, indent_unit));
+                _ => {
+                    try!(end(s)); // close the ibox for the pattern
+                    try!(print_expr(s, arm.body));
+                }
+            }
+            if !expr_is_simple_block(expr)
+                && i < len - 1 {
+                try!(word(&mut s.s, ","));
             }
+            try!(end(s)); // close enclosing cbox
         }
         try!(bclose_(s, expr.span, indent_unit));
       }