diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 72 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 31 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving.rs | 46 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 50 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 28 |
8 files changed, 160 insertions, 113 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6aa976691e8..c3f2eac8a2a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -323,11 +323,18 @@ struct blk_ { #[auto_encode] #[auto_decode] -type pat = {id: node_id, node: pat_, span: span}; +struct pat { + id: node_id, + node: pat_, + span: span, +} #[auto_encode] #[auto_decode] -type field_pat = {ident: ident, pat: @pat}; +struct field_pat { + ident: ident, + pat: @pat, +} #[auto_encode] #[auto_decode] @@ -637,8 +644,13 @@ enum stmt_ { // a refinement on pat. #[auto_encode] #[auto_decode] -type local_ = {is_mutbl: bool, ty: @Ty, pat: @pat, - init: Option<@expr>, id: node_id}; +struct local_ { + is_mutbl: bool, + ty: @Ty, + pat: @pat, + init: Option<@expr>, + id: node_id, +} type local = spanned<local_>; @@ -650,7 +662,11 @@ enum decl_ { decl_local(~[@local]), decl_item(@item), } #[auto_encode] #[auto_decode] -type arm = {pats: ~[@pat], guard: Option<@expr>, body: blk}; +struct arm { + pats: ~[@pat], + guard: Option<@expr>, + body: blk, +} #[auto_encode] #[auto_decode] diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 235820fdd1c..d744a3e01cc 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -312,9 +312,9 @@ fn ident_to_path(s: span, +i: ident) -> @path { } fn ident_to_pat(id: node_id, s: span, +i: ident) -> @pat { - @{id: id, - node: pat_ident(bind_by_value, ident_to_path(s, i), None), - span: s} + @ast::pat { id: id, + node: pat_ident(bind_by_value, ident_to_path(s, i), None), + span: s } } pure fn is_unguarded(a: &arm) -> bool { diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index cd2cafb3699..fcb11f42647 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -317,11 +317,14 @@ priv impl ext_ctxt { } fn binder_pat(span: span, nm: ast::ident) -> @ast::pat { - @{id: self.next_id(), - node: ast::pat_ident(ast::bind_by_ref(ast::m_imm), - self.path(span, ~[nm]), - None), - span: span} + @ast::pat { + id: self.next_id(), + node: ast::pat_ident( + ast::bind_by_ref(ast::m_imm), + self.path(span, ~[nm]), + None), + span: span, + } } fn stmt(expr: @ast::expr) -> @ast::stmt { @@ -579,12 +582,14 @@ fn mk_ser_method( let ser_inputs = ~[{ mode: ast::infer(cx.next_id()), ty: ty_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}, + pat: @ast::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(), }]; @@ -640,12 +645,14 @@ fn mk_deser_method( let deser_inputs = ~[{ mode: ast::infer(cx.next_id()), ty: ty_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}, + pat: @ast::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(), }]; @@ -967,7 +974,7 @@ fn ser_variant( ) }; - let pat = @{ + let pat = @ast::pat { id: cx.next_id(), node: pat_node, span: span, @@ -1020,7 +1027,7 @@ fn ser_variant( ] ); - { pats: ~[pat], guard: None, body: cx.expr_blk(body) } + ast::arm { pats: ~[pat], guard: None, body: cx.expr_blk(body) } } fn mk_enum_ser_body( @@ -1132,21 +1139,25 @@ fn mk_enum_deser_body( fail ~"enum variants unimplemented", }; - let pat = @{ + let pat = @ast::pat { id: cx.next_id(), node: ast::pat_lit(cx.lit_uint(span, v_idx)), span: span, }; - { + ast::arm { pats: ~[pat], guard: None, body: cx.expr_blk(body), } }; - let impossible_case = { - pats: ~[@{ id: cx.next_id(), node: ast::pat_wild, span: span}], + let impossible_case = ast::arm { + pats: ~[@ast::pat { + id: cx.next_id(), + node: ast::pat_wild, + span: span, + }], guard: None, // FIXME(#3198): proper error message @@ -1167,13 +1178,14 @@ fn mk_enum_deser_body( node: ast::ty_infer, span: span }, - 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}, + pat: @ast::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/build.rs b/src/libsyntax/ext/build.rs index df40dc1ed29..72c13747bf1 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -181,18 +181,25 @@ fn mk_glob_use(cx: ext_ctxt, sp: span, fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt { - let pat : @ast::pat = @{id: cx.next_id(), - node: ast::pat_ident(ast::bind_by_value, - mk_raw_path(sp, ~[ident]), - None), - span: sp}; + let pat = @ast::pat { + id: cx.next_id(), + node: ast::pat_ident( + ast::bind_by_value, + mk_raw_path(sp, ~[ident]), + None), + span: sp, + }; let ty : @ast::Ty = @{ id: cx.next_id(), node: ast::ty_infer, span: sp }; - let local : @ast::local = @ast::spanned { node: { is_mutbl: mutbl, - ty: ty, - pat: pat, - init: Some(ex), - id: cx.next_id()}, - span: sp}; + let local = @ast::spanned { + node: ast::local_ { + is_mutbl: mutbl, + ty: ty, + pat: pat, + init: Some(ex), + id: cx.next_id(), + }, + span: sp, + }; let decl = ast::spanned {node: ast::decl_local(~[local]), span: sp}; @ast::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } } @@ -243,7 +250,7 @@ fn mk_managed(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e)) } fn mk_pat(cx: ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat { - @{ id: cx.next_id(), node: move pat, span: span } + @ast::pat { id: cx.next_id(), node: pat, span: span } } fn mk_pat_ident(cx: ext_ctxt, span: span, ident: ast::ident) -> @ast::pat { let path = mk_raw_path(span, ~[ ident ]); diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs index 5b98868cd04..2148ad0cdb6 100644 --- a/src/libsyntax/ext/deriving.rs +++ b/src/libsyntax/ext/deriving.rs @@ -374,22 +374,17 @@ fn create_enum_variant_pattern(cx: ext_ctxt, prefix, struct_def.fields.len()); - let field_pats = dvec::DVec(); - for struct_def.fields.eachi |i, struct_field| { + let field_pats = do struct_def.fields.mapi |i, struct_field| { let ident = match struct_field.node.kind { named_field(ident, _, _) => ident, unnamed_field => { cx.span_bug(span, ~"unexpected unnamed field"); } }; - field_pats.push({ ident: ident, pat: subpats[i] }); - } - let field_pats = dvec::unwrap(move field_pats); + ast::field_pat { ident: ident, pat: subpats[i] } + }; - return build::mk_pat_struct(cx, - span, - matching_path, - move field_pats); + build::mk_pat_struct(cx, span, matching_path, field_pats) } enum_variant_kind(*) => { cx.span_unimpl(span, ~"enum variants for `deriving`"); @@ -732,7 +727,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, matching_body_expr); // Create the matching arm. - let matching_arm = { + let matching_arm = ast::arm { pats: ~[ matching_pat ], guard: None, body: move matching_body_block @@ -743,7 +738,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, // variant then there will always be a match. if enum_definition.variants.len() > 1 { // Create the nonmatching pattern. - let nonmatching_pat = @{ + let nonmatching_pat = @ast::pat { id: cx.next_id(), node: pat_wild, span: span @@ -757,12 +752,12 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, nonmatching_expr); // Create the nonmatching arm. - let nonmatching_arm = { + let nonmatching_arm = ast::arm { pats: ~[ nonmatching_pat ], guard: None, - body: move nonmatching_body_block + body: nonmatching_body_block, }; - other_arms.push(move nonmatching_arm); + other_arms.push(nonmatching_arm); } // Create the self pattern. @@ -784,10 +779,10 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, other_match_expr); // Create the self arm. - let self_arm = { + let self_arm = ast::arm { pats: ~[ self_pat ], guard: None, - body: move other_match_body_block + body: other_match_body_block, }; self_arms.push(move self_arm); } @@ -813,8 +808,7 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt, enum_definition: &enum_def) -> @method { // Create the arms of the match in the method body. - let arms = dvec::DVec(); - for enum_definition.variants.eachi |i, variant| { + let arms = do enum_definition.variants.mapi |i, variant| { // Create the matching pattern. let pat = create_enum_variant_pattern(cx, span, variant, ~"__self"); @@ -850,24 +844,22 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt, let match_body_block = build::mk_block_(cx, span, move stmts); // Create the arm. - let arm = { + ast::arm { pats: ~[ pat ], guard: None, - body: move match_body_block - }; - arms.push(move arm); - } + body: match_body_block, + } + }; // Create the method body. let self_ident = cx.ident_of(~"self"); let self_expr = build::mk_path(cx, span, ~[ self_ident ]); let self_expr = build::mk_unary(cx, span, deref, self_expr); - let arms = dvec::unwrap(move arms); - let self_match_expr = expr_match(self_expr, move arms); - let self_match_expr = build::mk_expr(cx, span, move self_match_expr); + let self_match_expr = expr_match(self_expr, arms); + let self_match_expr = build::mk_expr(cx, span, self_match_expr); let self_match_stmt = build::mk_stmt(cx, span, self_match_expr); // Create the method. - return create_iter_bytes_method(cx, span, ~[ self_match_stmt ]); + create_iter_bytes_method(cx, span, ~[ self_match_stmt ]) } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index f5b6ca953b3..29d27e53d68 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -181,15 +181,19 @@ impl ext_ctxt: ext_ctxt_ast_builder { } fn arg(name: ident, ty: @ast::Ty) -> ast::arg { - {mode: ast::infer(self.next_id()), - ty: ty, - pat: @{id: self.next_id(), + { + mode: ast::infer(self.next_id()), + ty: ty, + pat: @ast::pat { + id: self.next_id(), node: ast::pat_ident( ast::bind_by_value, ast_util::ident_to_path(dummy_sp(), name), None), - span: dummy_sp()}, - id: self.next_id()} + span: dummy_sp(), + }, + id: self.next_id(), + } } fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index ecb53072f7e..c1d5e6094fc 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -339,9 +339,11 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { } fn noop_fold_arm(a: arm, fld: ast_fold) -> arm { - return {pats: vec::map(a.pats, |x| fld.fold_pat(*x)), - guard: option::map(&a.guard, |x| fld.fold_expr(*x)), - body: fld.fold_block(a.body)}; + arm { + pats: vec::map(a.pats, |x| fld.fold_pat(*x)), + guard: option::map(&a.guard, |x| fld.fold_expr(*x)), + body: fld.fold_block(a.body), + } } fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { @@ -358,20 +360,22 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { |pats| vec::map(*pats, |x| fld.fold_pat(*x)))) } pat_rec(fields, etc) => { - let mut fs = ~[]; - for fields.each |f| { - fs.push({ident: /* FIXME (#2543) */ copy f.ident, - pat: fld.fold_pat(f.pat)}); - } + let fs = do fields.map |f| { + ast::field_pat { + ident: /* FIXME (#2543) */ copy f.ident, + pat: fld.fold_pat(f.pat), + } + }; pat_rec(fs, etc) } pat_struct(pth, fields, etc) => { let pth_ = fld.fold_path(pth); - let mut fs = ~[]; - for fields.each |f| { - fs.push({ident: /* FIXME (#2543) */ copy f.ident, - pat: fld.fold_pat(f.pat)}); - } + let fs = do fields.map |f| { + ast::field_pat { + ident: /* FIXME (#2543) */ copy f.ident, + pat: fld.fold_pat(f.pat) + } + }; pat_struct(pth_, fs, etc) } pat_tup(elts) => pat_tup(vec::map(elts, |x| fld.fold_pat(*x))), @@ -634,11 +638,13 @@ fn noop_fold_path(&&p: path, fld: ast_fold) -> path { } fn noop_fold_local(l: local_, fld: ast_fold) -> local_ { - return {is_mutbl: l.is_mutbl, - ty: fld.fold_ty(l.ty), - pat: fld.fold_pat(l.pat), - init: l.init.map(|e| fld.fold_expr(*e)), - id: fld.new_id(l.id)}; + local_ { + is_mutbl: l.is_mutbl, + ty: fld.fold_ty(l.ty), + pat: fld.fold_pat(l.pat), + init: l.init.map(|e| fld.fold_expr(*e)), + id: fld.new_id(l.id), + } } /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a @@ -731,9 +737,11 @@ impl ast_fold_fns: ast_fold { } fn fold_pat(&&x: @pat) -> @pat { let (n, s) = (self.fold_pat)(x.node, x.span, self as ast_fold); - return @{id: (self.new_id)(x.id), - node: n, - span: (self.new_span)(s)}; + @pat { + id: (self.new_id)(x.id), + node: n, + span: (self.new_span)(s), + } } fn fold_decl(&&x: @decl) -> @decl { let (n, s) = (self.fold_decl)(x.node, x.span, self as ast_fold); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b7ecbbcaa19..770c942059e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1769,7 +1769,7 @@ impl Parser { span: expr.span, }; - arms.push({pats: pats, guard: guard, body: blk}); + arms.push(ast::arm { pats: pats, guard: guard, body: blk }); } let mut hi = self.span.hi; self.bump(); @@ -1833,9 +1833,9 @@ impl Parser { let subpat = self.parse_pat(refutable); if is_tail { match subpat { - @{ node: pat_wild, _ } => (), - @{ node: pat_ident(_, _, _), _ } => (), - @{ span, _ } => self.span_fatal( + @ast::pat { node: pat_wild, _ } => (), + @ast::pat { node: pat_ident(_, _, _), _ } => (), + @ast::pat { span, _ } => self.span_fatal( span, ~"expected an identifier or `_`" ) } @@ -1881,13 +1881,13 @@ impl Parser { self.bump(); subpat = self.parse_pat(refutable); } else { - subpat = @{ + subpat = @ast::pat { id: self.get_id(), node: pat_ident(bind_infer, fieldpath, None), span: self.last_span }; } - fields.push({ident: fieldname, pat: subpat}); + fields.push(ast::field_pat { ident: fieldname, pat: subpat }); } return (fields, etc); } @@ -2092,7 +2092,7 @@ impl Parser { hi = self.span.hi; } } - return @{id: self.get_id(), node: pat, span: mk_sp(lo, hi)}; + @ast::pat { id: self.get_id(), node: pat, span: mk_sp(lo, hi) } } fn parse_pat_ident(refutable: bool, @@ -2131,9 +2131,17 @@ impl Parser { span: mk_sp(lo, lo)}; if self.eat(token::COLON) { ty = self.parse_ty(false); } let init = if allow_init { self.parse_initializer() } else { None }; - return @spanned(lo, self.last_span.hi, - {is_mutbl: is_mutbl, ty: ty, pat: pat, - init: init, id: self.get_id()}); + @spanned( + lo, + self.last_span.hi, + ast::local_ { + is_mutbl: is_mutbl, + ty: ty, + pat: pat, + init: init, + id: self.get_id(), + } + ) } fn parse_let() -> @decl { |
