summary refs log tree commit diff
path: root/src/libsyntax/print/pprust.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-10-28 15:22:49 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-10-29 10:34:17 -0700
commit7e77bf17694e31c741fe3a31c7eca5437d9cb6d5 (patch)
tree07fbf75c901955bc5b527929785e544829da92b0 /src/libsyntax/print/pprust.rs
parente6650c87a3800264a043b7f129e6a4841c4cc3f7 (diff)
downloadrust-7e77bf17694e31c741fe3a31c7eca5437d9cb6d5.tar.gz
rust-7e77bf17694e31c741fe3a31c7eca5437d9cb6d5.zip
librustc: Implement the `proc` type as sugar for `~once fn` and `proc`
notation for closures, and disable the feature gate for `once fn` if
used with the `~` sigil.
Diffstat (limited to 'src/libsyntax/print/pprust.rs')
-rw-r--r--src/libsyntax/print/pprust.rs61
1 files changed, 55 insertions, 6 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index f3090c7dd16..33bdcdd1b03 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1350,6 +1350,33 @@ pub fn print_expr(s: @ps, expr: &ast::Expr) {
         // empty box to satisfy the close.
         ibox(s, 0);
       }
+      ast::ExprProc(ref decl, ref body) => {
+        // in do/for blocks we don't want to show an empty
+        // argument list, but at this point we don't know which
+        // we are inside.
+        //
+        // if !decl.inputs.is_empty() {
+        print_proc_args(s, decl);
+        space(s.s);
+        // }
+        assert!(body.stmts.is_empty());
+        assert!(body.expr.is_some());
+        // we extract the block, so as not to create another set of boxes
+        match body.expr.unwrap().node {
+            ast::ExprBlock(ref blk) => {
+                print_block_unclosed(s, blk);
+            }
+            _ => {
+                // this is a bare expression
+                print_expr(s, body.expr.unwrap());
+                end(s); // need to close a box
+            }
+        }
+        // a box will be closed by print_expr, but we didn't want an overall
+        // wrapper so we closed the corresponding opening. so create an
+        // empty box to satisfy the close.
+        ibox(s, 0);
+      }
       ast::ExprDoBody(body) => {
         print_expr(s, body);
       }
@@ -1777,6 +1804,24 @@ pub fn print_fn_block_args(s: @ps, decl: &ast::fn_decl) {
     maybe_print_comment(s, decl.output.span.lo);
 }
 
+pub fn print_proc_args(s: @ps, decl: &ast::fn_decl) {
+    word(s.s, "proc");
+    word(s.s, "(");
+    print_fn_args(s, decl, None);
+    word(s.s, ")");
+
+    match decl.output.node {
+        ast::ty_infer => {}
+        _ => {
+            space_if_not_bol(s);
+            word_space(s, "->");
+            print_type(s, &decl.output);
+        }
+    }
+
+    maybe_print_comment(s, decl.output.span.lo);
+}
+
 pub fn print_bounds(s: @ps, bounds: &OptVec<ast::TyParamBound>,
                     print_colon_anyway: bool) {
     if !bounds.is_empty() {
@@ -1968,12 +2013,16 @@ pub fn print_ty_fn(s: @ps,
 
     // Duplicates the logic in `print_fn_header_info()`.  This is because that
     // function prints the sigil in the wrong place.  That should be fixed.
-    print_extern_opt_abis(s, opt_abis);
-    print_opt_sigil(s, opt_sigil);
-    print_opt_lifetime(s, opt_region);
-    print_purity(s, purity);
-    print_onceness(s, onceness);
-    word(s.s, "fn");
+    if opt_sigil == Some(ast::OwnedSigil) && onceness == ast::Once {
+        word(s.s, "proc");
+    } else {
+        print_extern_opt_abis(s, opt_abis);
+        print_opt_sigil(s, opt_sigil);
+        print_opt_lifetime(s, opt_region);
+        print_purity(s, purity);
+        print_onceness(s, onceness);
+        word(s.s, "fn");
+    }
     match id { Some(id) => { word(s.s, " "); print_ident(s, id); } _ => () }
     do opt_bounds.as_ref().map |bounds| { print_bounds(s, bounds, true); };
     match generics { Some(g) => print_generics(s, g), _ => () }