diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-11-06 18:41:06 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-11-07 19:29:30 -0800 |
| commit | 0fc952372a1010bc567b1c183105e4fd3f395af0 (patch) | |
| tree | 4cf44e50cf87c1a151dfc17a543710e7df5218fc /src/libsyntax/ext | |
| parent | b223c9c4651ee2f4b8fe2af0136e657a0893caa4 (diff) | |
rustc: Support irrefutable patterns in function arguments. r=nmatsakis
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/auto_serialize.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 9 |
3 files changed, 36 insertions, 12 deletions
diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 707787e78b9..39e94291d8b 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -515,7 +515,12 @@ fn mk_ser_method( let ser_inputs = ~[{ mode: ast::infer(cx.next_id()), ty: ty_s, - ident: cx.ident_of(~"__s"), + pat: @{id: cx.next_id(), + node: ast::pat_ident( + ast::bind_by_value, + ast_util::ident_to_path(span, cx.ident_of(~"__s")), + None), + span: span}, id: cx.next_id(), }]; @@ -570,7 +575,12 @@ fn mk_deser_method( let deser_inputs = ~[{ mode: ast::infer(cx.next_id()), ty: ty_d, - ident: cx.ident_of(~"__d"), + pat: @{id: cx.next_id(), + node: ast::pat_ident( + ast::bind_by_value, + ast_util::ident_to_path(span, cx.ident_of(~"__d")), + None), + span: span}, id: cx.next_id(), }]; @@ -1087,7 +1097,13 @@ fn mk_enum_deser_body( node: ast::ty_infer, span: span }, - ident: cx.ident_of(~"i"), + pat: @{id: cx.next_id(), + node: ast::pat_ident( + ast::bind_by_value, + ast_util::ident_to_path(span, + cx.ident_of(~"i")), + None), + span: span}, id: cx.next_id(), }], output: @{ diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 5b4cc23ce09..ddf58ce0fef 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -234,24 +234,27 @@ fn mk_ctxt(parse_sess: parse::parse_sess, move ((move imp) as ext_ctxt) } -fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str { +fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { match expr.node { ast::expr_lit(l) => match l.node { ast::lit_str(s) => return *s, - _ => cx.span_fatal(l.span, error) + _ => cx.span_fatal(l.span, err_msg) }, - _ => cx.span_fatal(expr.span, error) + _ => cx.span_fatal(expr.span, err_msg) } } -fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident { +fn expr_to_ident(cx: ext_ctxt, + expr: @ast::expr, + err_msg: ~str) -> ast::ident { match expr.node { ast::expr_path(p) => { if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { - cx.span_fatal(expr.span, error); - } else { return p.idents[0]; } + cx.span_fatal(expr.span, err_msg); + } + return p.idents[0]; } - _ => cx.span_fatal(expr.span, error) + _ => cx.span_fatal(expr.span, err_msg) } } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 632b3b93af9..f03adb90f0b 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -4,7 +4,7 @@ // something smarter. use ast::{ident, node_id}; -use ast_util::respan; +use ast_util::{ident_to_path, respan}; use codemap::span; use ext::base::mk_ctxt; @@ -178,7 +178,12 @@ impl ext_ctxt: ext_ctxt_ast_builder { fn arg(name: ident, ty: @ast::Ty) -> ast::arg { {mode: ast::infer(self.next_id()), ty: ty, - ident: name, + pat: @{id: self.next_id(), + node: ast::pat_ident( + ast::bind_by_value, + ast_util::ident_to_path(self.empty_span(), name), + None), + span: self.empty_span()}, id: self.next_id()} } |
