about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-25 16:23:43 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-25 16:24:06 -0800
commit2999479a2dcb10019558d64c2045fdee31841d31 (patch)
tree331200932427d412f7d406d992212f91cea564dc /src/comp
parent08c6cb5f708efa7484ca27d6b14b86d6ae58b692 (diff)
downloadrust-2999479a2dcb10019558d64c2045fdee31841d31.tar.gz
rust-2999479a2dcb10019558d64c2045fdee31841d31.zip
rustc: Allow attributes on enum variants. Closes #1663
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/syntax/ast.rs4
-rw-r--r--src/comp/syntax/fold.rs9
-rw-r--r--src/comp/syntax/parse/parser.rs6
-rw-r--r--src/comp/syntax/print/pprust.rs1
4 files changed, 16 insertions, 4 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 7f7f6d76bc1..e37116d53f5 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -418,8 +418,8 @@ type native_mod =
 
 type variant_arg = {ty: @ty, id: node_id};
 
-type variant_ = {name: ident, args: [variant_arg], id: node_id,
-                 disr_expr: option::t<@expr>};
+type variant_ = {name: ident, attrs: [attribute], args: [variant_arg],
+                 id: node_id, disr_expr: option::t<@expr>};
 
 type variant = spanned<variant_>;
 
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index d2019930b4a..7e2cd136a28 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -441,11 +441,18 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
     }
     let fold_variant_arg = bind fold_variant_arg_(_, fld);
     let args = vec::map(v.args, fold_variant_arg);
+
+    let fold_meta_item = bind fold_meta_item_(_, fld);
+    let fold_attribute = bind fold_attribute_(_, fold_meta_item);
+    let attrs = vec::map(v.attrs, fold_attribute);
+
     let de = alt v.disr_expr {
       some(e) {some(fld.fold_expr(e))}
       none {none}
     };
-    ret {name: v.name, args: args, id: v.id,
+    ret {name: v.name,
+         attrs: attrs,
+         args: args, id: v.id,
          disr_expr: de};
 }
 
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 4d8acc6fa44..a66b223175c 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -2042,6 +2042,7 @@ fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
         let variant =
             spanned(ty.span.lo, ty.span.hi,
                     {name: id,
+                     attrs: [],
                      args: [{ty: ty, id: p.get_id()}],
                      id: p.get_id(),
                      disr_expr: none});
@@ -2049,9 +2050,11 @@ fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
                     ast::item_enum([variant], ty_params), attrs);
     }
     expect(p, token::LBRACE);
+
     let all_nullary = true, have_disr = false;
 
     while p.token != token::RBRACE {
+        let variant_attrs = parse_outer_attributes(p);
         let vlo = p.span.lo;
         let ident = parse_value_ident(p);
         let args = [], disr_expr = none;
@@ -2068,7 +2071,8 @@ fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
             disr_expr = some(parse_expr(p));
         }
 
-        let vr = {name: ident, args: args, id: p.get_id(),
+        let vr = {name: ident, attrs: variant_attrs,
+                  args: args, id: p.get_id(),
                   disr_expr: disr_expr};
         variants += [spanned(vlo, p.last_span.hi, vr)];
 
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index bdfc06b403b..9e6b25aa2fc 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -434,6 +434,7 @@ fn print_item(s: ps, &&item: @ast::item) {
             for v: ast::variant in variants {
                 space_if_not_bol(s);
                 maybe_print_comment(s, v.span.lo);
+                print_outer_attributes(s, v.node.attrs);
                 ibox(s, indent_unit);
                 word(s.s, v.node.name);
                 if vec::len(v.node.args) > 0u {