about summary refs log tree commit diff
path: root/src/librustsyntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-05-03 14:42:34 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-05-03 14:42:34 -0700
commitcfa09d35a355dee59008306f98330ff0472eb09d (patch)
treee9b157de0a53e056ebd63db17557e4af1ac17ef1 /src/librustsyntax
parent1ba4ca4c4a0153578e812baf5f7f5554d079de40 (diff)
downloadrust-cfa09d35a355dee59008306f98330ff0472eb09d.tar.gz
rust-cfa09d35a355dee59008306f98330ff0472eb09d.zip
Revert "allow fn exprs to omit arg types"
This reverts commit 1ba4ca4c4a0153578e812baf5f7f5554d079de40.
Diffstat (limited to 'src/librustsyntax')
-rw-r--r--src/librustsyntax/parse/parser.rs15
-rw-r--r--src/librustsyntax/print/pprust.rs41
2 files changed, 31 insertions, 25 deletions
diff --git a/src/librustsyntax/parse/parser.rs b/src/librustsyntax/parse/parser.rs
index 7eb537d8cfe..0c681900dd5 100644
--- a/src/librustsyntax/parse/parser.rs
+++ b/src/librustsyntax/parse/parser.rs
@@ -1206,7 +1206,7 @@ fn parse_capture_clause(p: parser) -> @ast::capture_clause {
 fn parse_fn_expr(p: parser, proto: ast::proto) -> @ast::expr {
     let lo = p.last_span.lo;
     let capture_clause = parse_capture_clause(p);
-    let decl = parse_fn_decl(p, ast::impure_fn, parse_fn_block_arg);
+    let decl = parse_fn_decl(p, ast::impure_fn);
     let body = parse_block(p);
     ret mk_expr(p, lo, body.span.hi,
                 ast::expr_fn(proto, decl, body, capture_clause));
@@ -1699,12 +1699,11 @@ fn parse_ty_params(p: parser) -> [ast::ty_param] {
     } else { [] }
 }
 
-fn parse_fn_decl(p: parser, purity: ast::purity,
-                 parse_arg_fn: fn(parser) -> ast::arg)
+fn parse_fn_decl(p: parser, purity: ast::purity)
     -> ast::fn_decl {
     let inputs: ast::spanned<[ast::arg]> =
         parse_seq(token::LPAREN, token::RPAREN, seq_sep(token::COMMA),
-                  parse_arg_fn, p);
+                  parse_arg, p);
     // Use the args list to translate each bound variable
     // mentioned in a constraint to an arg index.
     // Seems weird to do this in the parser, but I'm not sure how else to.
@@ -1761,7 +1760,7 @@ fn parse_item_fn(p: parser, purity: ast::purity,
                  attrs: [ast::attribute]) -> @ast::item {
     let lo = p.last_span.lo;
     let t = parse_fn_header(p);
-    let decl = parse_fn_decl(p, purity, parse_arg);
+    let decl = parse_fn_decl(p, purity);
     let (inner_attrs, body) = parse_inner_attrs_and_block(p, true);
     let attrs = attrs + inner_attrs;
     ret mk_item(p, lo, body.span.hi, t.ident,
@@ -1786,7 +1785,7 @@ fn parse_method(p: parser, pr: ast::privacy) -> @ast::method {
     let lo = p.span.lo, pur = parse_fn_purity(p);
     let ident = parse_method_name(p);
     let tps = parse_ty_params(p);
-    let decl = parse_fn_decl(p, pur, parse_arg);
+    let decl = parse_fn_decl(p, pur);
     let (inner_attrs, body) = parse_inner_attrs_and_block(p, true);
     let attrs = attrs + inner_attrs;
     @{ident: ident, attrs: attrs, tps: tps, decl: decl, body: body,
@@ -1970,7 +1969,7 @@ fn parse_class_item(p:parser, class_name_with_tps: @ast::path)
         let lo = p.last_span.lo;
         // Can ctors have attrs?
             // result type is always the type of the class
-        let decl_ = parse_fn_decl(p, ast::impure_fn, parse_arg);
+        let decl_ = parse_fn_decl(p, ast::impure_fn);
         let decl = {output: @{id: p.get_id(),
                       node: ast::ty_path(class_name_with_tps, p.get_id()),
                       span: decl_.output.span}
@@ -2049,7 +2048,7 @@ fn parse_item_native_fn(p: parser, attrs: [ast::attribute],
                         purity: ast::purity) -> @ast::native_item {
     let lo = p.last_span.lo;
     let t = parse_fn_header(p);
-    let decl = parse_fn_decl(p, purity, parse_arg);
+    let decl = parse_fn_decl(p, purity);
     let mut hi = p.span.hi;
     expect(p, token::SEMI);
     ret @{ident: t.ident,
diff --git a/src/librustsyntax/print/pprust.rs b/src/librustsyntax/print/pprust.rs
index c6417ab01f4..b50f4f341a7 100644
--- a/src/librustsyntax/print/pprust.rs
+++ b/src/librustsyntax/print/pprust.rs
@@ -1351,6 +1351,13 @@ fn print_cap_clause(s: ps, cap_clause: ast::capture_clause) {
 
 fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl) {
     popen(s);
+    fn print_arg(s: ps, x: ast::arg) {
+        ibox(s, indent_unit);
+        print_arg_mode(s, x.mode);
+        word_space(s, x.ident + ":");
+        print_type(s, x.ty);
+        end(s);
+    }
     commasep(s, inconsistent, decl.inputs, print_arg);
     pclose(s);
     word(s.s, constrs_str(decl.constraints, {|c|
@@ -1367,6 +1374,16 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl) {
 
 fn print_fn_block_args(s: ps, decl: ast::fn_decl) {
     word(s.s, "|");
+    fn print_arg(s: ps, x: ast::arg) {
+        ibox(s, indent_unit);
+        print_arg_mode(s, x.mode);
+        word(s.s, x.ident);
+        if x.ty.node != ast::ty_infer {
+            word_space(s, ":");
+            print_type(s, x.ty);
+        }
+        end(s);
+    }
     commasep(s, inconsistent, decl.inputs, print_arg);
     word(s.s, "|");
     if decl.output.node != ast::ty_infer {
@@ -1524,23 +1541,6 @@ fn print_mt(s: ps, mt: ast::mt) {
     print_type(s, mt.ty);
 }
 
-fn print_arg(s: ps, input: ast::arg) {
-    ibox(s, indent_unit);
-    print_arg_mode(s, input.mode);
-    alt input.ty.node {
-      ast::ty_infer {
-        word(s.s, input.ident);
-      }
-      _ {
-        if str::len(input.ident) > 0u {
-            word_space(s, input.ident + ":");
-        }
-        print_type(s, input.ty);
-      }
-    }
-    end(s);
-}
-
 fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
                decl: ast::fn_decl, id: option<ast::ident>,
                tps: option<[ast::ty_param]>) {
@@ -1550,6 +1550,13 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
     alt tps { some(tps) { print_type_params(s, tps); } _ { } }
     zerobreak(s.s);
     popen(s);
+    fn print_arg(s: ps, input: ast::arg) {
+        print_arg_mode(s, input.mode);
+        if str::len(input.ident) > 0u {
+            word_space(s, input.ident + ":");
+        }
+        print_type(s, input.ty);
+    }
     commasep(s, inconsistent, decl.inputs, print_arg);
     pclose(s);
     maybe_print_comment(s, decl.output.span.lo);