summary refs log tree commit diff
path: root/src/libsyntax/print/pprust.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-07-10 10:37:05 -0700
committerBrian Anderson <banderson@mozilla.com>2012-07-31 15:41:26 -0700
commitc206d024eb31124a5d6536ce1f355c4ac0698cab (patch)
tree4c44017d0ad5a6a6921ea2675058936beb72ade6 /src/libsyntax/print/pprust.rs
parenta89ed49d3d01abbd49889832d87650b6c99ff85c (diff)
downloadrust-c206d024eb31124a5d6536ce1f355c4ac0698cab.tar.gz
rust-c206d024eb31124a5d6536ce1f355c4ac0698cab.zip
accept naked exprs with commas in pattern arms
pretty printing will use them, but indentation is slightly off
if the expr is long
Diffstat (limited to 'src/libsyntax/print/pprust.rs')
-rw-r--r--src/libsyntax/print/pprust.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index a169c4e7256..18e3b6c0790 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -6,7 +6,7 @@ import pp::{break_offset, word, printer,
             inconsistent, eof};
 import diagnostic;
 import ast::{required, provided};
-import ast_util::operator_prec;
+import ast_util::{operator_prec, lone_block_expr};
 import dvec::{dvec, extensions};
 import parse::classify::*;
 import util::interner;
@@ -1034,7 +1034,8 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
         print_maybe_parens_discrim(s, expr);
         space(s.s);
         bopen(s);
-        for arms.each |arm| {
+        let len = arms.len();
+        for arms.eachi |i, arm| {
             space(s.s);
             cbox(s, alt_indent_unit);
             ibox(s, 0u);
@@ -1050,8 +1051,19 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
               some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); }
               none { }
             }
-            print_possibly_embedded_block(s, arm.body, block_normal,
-                                          alt_indent_unit);
+            word_space(s, ~"=>");
+            alt lone_block_expr(arm.body) {
+              some(expr) => {
+                end(s); // close the ibox for the pattern
+                print_expr(s, expr);
+                if i < len - 1 { word_space(s, ~","); }
+                end(s); // close enclosing cbox
+              }
+              none => {
+                print_possibly_embedded_block(s, arm.body, block_normal,
+                                              alt_indent_unit);
+              }
+            }
         }
         bclose_(s, expr.span, alt_indent_unit);
       }