diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-02-17 10:59:09 -0800 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-02-19 10:02:51 -0800 |
| commit | bc62bd378251d6dd60f2999cd8c853a75a4e8d02 (patch) | |
| tree | 7f27b1abaab38625605525514b542f38d5968a11 /src/libsyntax/ext | |
| parent | 59ba4fc1042bb83dc6899462649d70a0141ff8ca (diff) | |
| download | rust-bc62bd378251d6dd60f2999cd8c853a75a4e8d02.tar.gz rust-bc62bd378251d6dd60f2999cd8c853a75a4e8d02.zip | |
libsyntax: make enum variants take refs
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 34 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/check.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/pipec.rs | 27 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 11 |
4 files changed, 42 insertions, 44 deletions
diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 9c0550c9875..2809d1dcc56 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -127,24 +127,24 @@ pub fn expand_auto_encode( do vec::flat_map(in_items) |item| { if item.attrs.any(is_auto_encode) { match item.node { - ast::item_struct(@ast::struct_def { fields, _}, tps) => { + ast::item_struct(ref struct_def, ref tps) => { let ser_impl = mk_struct_ser_impl( cx, item.span, item.ident, - fields, - tps + struct_def.fields, + *tps ); ~[filter_attrs(*item), ser_impl] }, - ast::item_enum(ref enum_def, tps) => { + ast::item_enum(ref enum_def, ref tps) => { let ser_impl = mk_enum_ser_impl( cx, item.span, item.ident, - (*enum_def), - tps + *enum_def, + *tps ); ~[filter_attrs(*item), ser_impl] @@ -182,24 +182,24 @@ pub fn expand_auto_decode( do vec::flat_map(in_items) |item| { if item.attrs.any(is_auto_decode) { match item.node { - ast::item_struct(@ast::struct_def { fields, _}, tps) => { + ast::item_struct(ref struct_def, ref tps) => { let deser_impl = mk_struct_deser_impl( cx, item.span, item.ident, - fields, - tps + struct_def.fields, + *tps ); ~[filter_attrs(*item), deser_impl] }, - ast::item_enum(ref enum_def, tps) => { + ast::item_enum(ref enum_def, ref tps) => { let deser_impl = mk_enum_deser_impl( cx, item.span, item.ident, - (*enum_def), - tps + *enum_def, + *tps ); ~[filter_attrs(*item), deser_impl] @@ -410,7 +410,7 @@ fn mk_impl( ident: ast::ident, ty_param: ast::ty_param, path: @ast::path, - tps: ~[ast::ty_param], + tps: &[ast::ty_param], f: fn(@ast::Ty) -> @ast::method ) -> @ast::item { // All the type parameters need to bound to the trait. @@ -458,7 +458,7 @@ fn mk_ser_impl( cx: ext_ctxt, span: span, ident: ast::ident, - tps: ~[ast::ty_param], + tps: &[ast::ty_param], body: @ast::expr ) -> @ast::item { // Make a path to the std::serialize::Encodable typaram. @@ -666,8 +666,8 @@ fn mk_struct_ser_impl( cx: ext_ctxt, span: span, ident: ast::ident, - fields: ~[@ast::struct_field], - tps: ~[ast::ty_param] + fields: &[@ast::struct_field], + tps: &[ast::ty_param] ) -> @ast::item { let fields = do mk_struct_fields(fields).mapi |idx, field| { // ast for `|| self.$(name).encode(__s)` @@ -808,7 +808,7 @@ struct field { mutbl: ast::mutability, } -fn mk_struct_fields(fields: ~[@ast::struct_field]) -> ~[field] { +fn mk_struct_fields(fields: &[@ast::struct_field]) -> ~[field] { do fields.map |field| { let (ident, mutbl) = match field.node.kind { ast::named_field(ident, mutbl, _) => (ident, mutbl), diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index 4676b5ed393..cc42a0992cb 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -54,27 +54,27 @@ pub impl proto::visitor<(), (), ()> for ext_ctxt { fn visit_message(&self, name: ~str, _span: span, _tys: &[@ast::Ty], this: state, next: Option<next_state>) { match next { - Some(next_state { state: ref next, tys: next_tys }) => { + Some(ref next_state) => { let proto = this.proto; - if !proto.has_state((*next)) { + if !proto.has_state(next_state.state) { // This should be a span fatal, but then we need to // track span information. self.span_err( - proto.get_state((*next)).span, + proto.get_state(next_state.state).span, fmt!("message %s steps to undefined state, %s", - name, (*next))); + name, next_state.state)); } else { - let next = proto.get_state((*next)); + let next = proto.get_state(next_state.state); - if next.ty_params.len() != next_tys.len() { + if next.ty_params.len() != next_state.tys.len() { self.span_err( next.span, // use a real span fmt!("message %s target (%s) \ needs %u type parameters, but got %u", name, next.name, next.ty_params.len(), - next_tys.len())); + next_state.tys.len())); } } } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 77164803caa..48bd8b03297 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -50,16 +50,13 @@ pub impl gen_send for message { fn gen_send(&self, cx: ext_ctxt, try: bool) -> @ast::item { debug!("pipec: gen_send"); match *self { - message(ref _id, span, tys, this, - Some(next_state {state: ref next, tys: next_tys})) => { + message(ref _id, span, ref tys, this, Some(ref next_state)) => { debug!("pipec: next state exists"); - let next = this.proto.get_state((*next)); - assert next_tys.len() == next.ty_params.len(); + let next = this.proto.get_state(next_state.state); + assert next_state.tys.len() == next.ty_params.len(); let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str())); - let args_ast = (arg_names, tys).map( - |n, t| cx.arg(*n, *t) - ); + let args_ast = (arg_names, *tys).map(|n, t| cx.arg(*n, *t)); let pipe_ty = cx.ty_path_ast_builder( path(~[this.data_name()], span) @@ -119,7 +116,7 @@ pub impl gen_send for message { let mut rty = cx.ty_path_ast_builder(path(~[next.data_name()], span) - .add_tys(next_tys)); + .add_tys(next_state.tys)); if try { rty = cx.ty_option(rty); } @@ -134,13 +131,13 @@ pub impl gen_send for message { cx.expr_block(body)) } - message(ref _id, span, tys, this, None) => { + message(ref _id, span, ref tys, this, None) => { debug!("pipec: no next state"); let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str())); - let args_ast = (arg_names, tys).map( - |n, t| cx.arg(cx.ident_of(*n), *t) - ); + let args_ast = do (arg_names, *tys).map |n, t| { + cx.arg(cx.ident_of(*n), *t) + }; let args_ast = vec::append( ~[cx.arg(cx.ident_of(~"pipe"), @@ -219,8 +216,8 @@ pub impl to_type_decls for state { let message(name, span, tys, this, next) = *m; let tys = match next { - Some(next_state { state: ref next, tys: next_tys }) => { - let next = this.proto.get_state((*next)); + Some(ref next_state) => { + let next = this.proto.get_state((next_state.state)); let next_name = cx.str_of(next.data_name()); let dir = match this.dir { @@ -232,7 +229,7 @@ pub impl to_type_decls for state { cx.ty_path_ast_builder( path(~[cx.ident_of(dir), cx.ident_of(next_name)], span) - .add_tys(next_tys))) + .add_tys(next_state.tys))) } None => tys }; diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 3e7a84240e4..dd0dfd8e443 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -59,12 +59,13 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, arg_reader as reader, argument_gram); // Extract the arguments: - let lhses:~[@named_match] = match argument_map.get(&lhs_nm) { - @matched_seq(s, _) => s, - _ => cx.span_bug(sp, ~"wrong-structured lhs") + let lhses = match argument_map.get(&lhs_nm) { + @matched_seq(ref s, _) => /* FIXME (#2543) */ copy *s, + _ => cx.span_bug(sp, ~"wrong-structured lhs") }; - let rhses:~[@named_match] = match argument_map.get(&rhs_nm) { - @matched_seq(s, _) => s, + + let rhses = match argument_map.get(&rhs_nm) { + @matched_seq(ref s, _) => /* FIXME (#2543) */ copy *s, _ => cx.span_bug(sp, ~"wrong-structured rhs") }; |
