Skip to content

Commit fc1fdcf

Browse files
committed
---
yaml --- r: 54263 b: refs/heads/dist-snap c: e2ba58c h: refs/heads/master i: 54261: 36a3cbe 54259: 199ff26 54255: e4979bd v: v3
1 parent 51e33b6 commit fc1fdcf

File tree

21 files changed

+161
-38
lines changed

21 files changed

+161
-38
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: 44d4d6de762f3f9aae1fedcf454c66b79b3ad58d
10-
refs/heads/dist-snap: 0a002d79b47340cc518ae4c0879a34c037c8411a
10+
refs/heads/dist-snap: e2ba58cd50c5ea96cb2babc66b694476a9c93dab
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/RELEASES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Version 0.6 (March 2013)
1+
Version 0.6 (April 2013)
22
---------------------------
33

44
* ~2100 changes, numerous bugfixes

branches/dist-snap/src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
286286
if args.len() > 0 && generics.ty_params.len() == 0 => {
287287
encode_symbol(ecx, ebml_w, variant.node.id);
288288
}
289-
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) => {}
289+
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) |
290+
ast::enum_variant_kind(_) => {}
290291
}
291292
encode_discriminant(ecx, ebml_w, variant.node.id);
292293
if vi[i].disr_val != disr_val {

branches/dist-snap/src/librustc/middle/resolve.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use syntax::ast::{expr_binary, expr_break, expr_cast, expr_field};
3737
use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path};
3838
use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
3939
use syntax::ast::{def_upvar, def_use, def_variant, div, eq};
40-
use syntax::ast::{expr, expr_again, expr_assign_op};
40+
use syntax::ast::{enum_variant_kind, expr, expr_again, expr_assign_op};
4141
use syntax::ast::{expr_index, expr_loop};
4242
use syntax::ast::{expr_path, expr_struct, expr_unary, fn_decl};
4343
use syntax::ast::{foreign_item, foreign_item_const, foreign_item_fn, ge};
@@ -1383,6 +1383,16 @@ pub impl Resolver {
13831383
variant.span);
13841384
self.structs.insert(local_def(variant.node.id));
13851385
}
1386+
enum_variant_kind(ref enum_definition) => {
1387+
child.define_type(privacy,
1388+
def_ty(local_def(variant.node.id)),
1389+
variant.span);
1390+
for (*enum_definition).variants.each |variant| {
1391+
self.build_reduced_graph_for_variant(*variant, item_id,
1392+
parent_privacy,
1393+
parent, visitor);
1394+
}
1395+
}
13861396
}
13871397
}
13881398

branches/dist-snap/src/librustc/middle/trans/base.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,14 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
20512051
trans_struct_def(ccx, struct_def, path,
20522052
variant.node.id);
20532053
}
2054+
ast::enum_variant_kind(ref enum_definition) => {
2055+
trans_enum_def(ccx,
2056+
*enum_definition,
2057+
id,
2058+
path,
2059+
vi,
2060+
&mut *i);
2061+
}
20542062
}
20552063
}
20562064
}
@@ -2505,6 +2513,9 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
25052513
ast::struct_variant_kind(_) => {
25062514
fail!(~"struct variant kind unexpected in get_item_val")
25072515
}
2516+
ast::enum_variant_kind(_) => {
2517+
fail!(~"enum variant kind unexpected in get_item_val")
2518+
}
25082519
}
25092520
set_inline_hint(llfn);
25102521
llfn

branches/dist-snap/src/librustc/middle/trans/monomorphize.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ pub fn monomorphic_fn(ccx: @CrateContext,
204204
}
205205
ast::struct_variant_kind(_) =>
206206
ccx.tcx.sess.bug(~"can't monomorphize struct variants"),
207+
ast::enum_variant_kind(_) =>
208+
ccx.tcx.sess.bug(~"can't monomorphize enum variants")
207209
}
208210
d
209211
}

branches/dist-snap/src/librustc/middle/ty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,6 +3873,9 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
38733873
ast::struct_variant_kind(_) => {
38743874
fail!(~"struct variant kinds unimpl in enum_variants")
38753875
}
3876+
ast::enum_variant_kind(_) => {
3877+
fail!(~"enum variant kinds unimpl in enum_variants")
3878+
}
38763879
}
38773880
})
38783881
}

branches/dist-snap/src/librustc/middle/typeck/check/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,16 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
30663066
ccx.tcx, local_def(v.node.id)).map(|cf|
30673067
ty::node_id_to_type(ccx.tcx, cf.id.node)));
30683068
}
3069+
ast::enum_variant_kind(_) => {
3070+
arg_tys = None;
3071+
do_check(ccx,
3072+
sp,
3073+
vs,
3074+
id,
3075+
&mut *disr_vals,
3076+
&mut *disr_val,
3077+
&mut *variants);
3078+
}
30693079
}
30703080

30713081
match arg_tys {

branches/dist-snap/src/librustc/middle/typeck/collect.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
202202
|f| ty::node_id_to_type(ccx.tcx, f.node.id));
203203
result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty));
204204
}
205+
206+
ast::enum_variant_kind(ref enum_definition) => {
207+
get_enum_variant_types(ccx,
208+
enum_ty,
209+
enum_definition.variants,
210+
generics,
211+
rp);
212+
result_ty = None;
213+
}
205214
};
206215

207216
match result_ty {

branches/dist-snap/src/libsyntax/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,13 +1078,15 @@ pub struct variant_arg {
10781078
pub enum variant_kind {
10791079
tuple_variant_kind(~[variant_arg]),
10801080
struct_variant_kind(@struct_def),
1081+
enum_variant_kind(enum_def)
10811082
}
10821083
10831084
#[auto_encode]
10841085
#[auto_decode]
10851086
#[deriving(Eq)]
10861087
pub struct enum_def {
10871088
variants: ~[variant],
1089+
common: Option<@struct_def>,
10881090
}
10891091
10901092
#[auto_encode]

branches/dist-snap/src/libsyntax/ext/auto_encode.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,8 @@ fn mk_enum_ser_body(
990990
),
991991
ast::struct_variant_kind(*) =>
992992
fail!(~"struct variants unimplemented"),
993+
ast::enum_variant_kind(*) =>
994+
fail!(~"enum variants unimplemented"),
993995
}
994996
};
995997
@@ -1087,6 +1089,8 @@ fn mk_enum_deser_body(
10871089
},
10881090
ast::struct_variant_kind(*) =>
10891091
fail!(~"struct variants unimplemented"),
1092+
ast::enum_variant_kind(*) =>
1093+
fail!(~"enum variants unimplemented")
10901094
};
10911095
10921096
let pat = @ast::pat {

branches/dist-snap/src/libsyntax/ext/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::prelude::*;
1212

1313
use ast;
1414
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
15-
use ast::{expr, expr_match, ident, impure_fn, item, item_};
15+
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
1616
use ast::{item_enum, item_impl, item_struct, Generics};
1717
use ast::{m_imm, meta_item, method};
1818
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};

branches/dist-snap/src/libsyntax/ext/deriving/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::prelude::*;
1212

1313
use ast;
1414
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
15-
use ast::{expr, expr_match, ident, impure_fn, item, item_};
15+
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
1616
use ast::{item_enum, item_impl, item_struct, Generics};
1717
use ast::{m_imm, meta_item, method};
1818
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};

branches/dist-snap/src/libsyntax/ext/deriving/iter_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::prelude::*;
1212

1313
use ast;
1414
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
15-
use ast::{expr, expr_match, ident, impure_fn, item, item_};
15+
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
1616
use ast::{item_enum, item_impl, item_struct, Generics};
1717
use ast::{m_imm, meta_item, method};
1818
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};

branches/dist-snap/src/libsyntax/ext/deriving/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use core::prelude::*;
1515

1616
use ast;
1717
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
18-
use ast::{expr, expr_match, ident, impure_fn, item, item_};
18+
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
1919
use ast::{item_enum, item_impl, item_struct, Generics};
2020
use ast::{m_imm, meta_item, method};
2121
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
@@ -283,13 +283,19 @@ pub fn create_enum_variant_pattern(cx: @ext_ctxt,
283283

284284
build::mk_pat_struct(cx, span, matching_path, field_pats)
285285
}
286+
enum_variant_kind(*) => {
287+
cx.span_unimpl(span, ~"enum variants for `deriving`");
288+
}
286289
}
287290
}
288291

289292
pub fn variant_arg_count(cx: @ext_ctxt, span: span, variant: &variant) -> uint {
290293
match variant.node.kind {
291294
tuple_variant_kind(ref args) => args.len(),
292295
struct_variant_kind(ref struct_def) => struct_def.fields.len(),
296+
enum_variant_kind(*) => {
297+
cx.span_bug(span, ~"variant_arg_count: enum variants deprecated")
298+
}
293299
}
294300
}
295301

branches/dist-snap/src/libsyntax/ext/pipes/pipec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl to_type_decls for state {
238238
cx.item_enum_poly(
239239
name,
240240
self.span,
241-
ast::enum_def { variants: items_msg },
241+
ast::enum_def { variants: items_msg, common: None },
242242
cx.strip_bounds(&self.generics)
243243
)
244244
]

branches/dist-snap/src/libsyntax/fold.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
257257
variants: do enum_definition.variants.map |x| {
258258
fld.fold_variant(x)
259259
},
260+
common: do enum_definition.common.map |x| {
261+
fold_struct_def(*x, fld)
262+
}
260263
},
261264
fold_generics(generics, fld))
262265
}
@@ -679,6 +682,17 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ {
679682
ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c))
680683
})
681684
}
685+
enum_variant_kind(ref enum_definition) => {
686+
let variants = do (*enum_definition).variants.map |x| {
687+
fld.fold_variant(x)
688+
};
689+
let common = do (*enum_definition).common.map |x| {
690+
fold_struct_def(*x, fld)
691+
};
692+
kind = enum_variant_kind(
693+
ast::enum_def { variants: variants, common: common }
694+
);
695+
}
682696
}
683697

684698
let fold_attribute = |x| fold_attribute_(x, fld);

branches/dist-snap/src/libsyntax/parse/parser.rs

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer};
1919
use ast::{bind_by_copy, bitand, bitor, bitxor, blk};
2020
use ast::{blk_check_mode, box, by_copy, by_ref};
2121
use ast::{crate, crate_cfg, decl, decl_item};
22-
use ast::{decl_local, default_blk, deref, div, enum_def};
22+
use ast::{decl_local, default_blk, deref, div, enum_def, enum_variant_kind};
2323
use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again};
2424
use ast::{expr_assign, expr_assign_op, expr_binary, expr_block};
2525
use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body};
@@ -3788,42 +3788,63 @@ pub impl Parser {
37883788
fn parse_enum_def(&self, generics: &ast::Generics) -> enum_def {
37893789
let mut variants = ~[];
37903790
let mut all_nullary = true, have_disr = false;
3791+
let mut common_fields = None;
3792+
37913793
while *self.token != token::RBRACE {
37923794
let variant_attrs = self.parse_outer_attributes();
37933795
let vlo = self.span.lo;
37943796

3797+
// Is this a common field declaration?
3798+
if self.eat_keyword(&~"struct") {
3799+
if common_fields.is_some() {
3800+
self.fatal(~"duplicate declaration of shared fields");
3801+
}
3802+
self.expect(&token::LBRACE);
3803+
common_fields = Some(self.parse_struct_def());
3804+
loop;
3805+
}
3806+
37953807
let vis = self.parse_visibility();
37963808

3809+
// Is this a nested enum declaration?
37973810
let ident, needs_comma, kind;
37983811
let mut args = ~[], disr_expr = None;
3799-
ident = self.parse_ident();
3800-
if self.eat(&token::LBRACE) {
3801-
// Parse a struct variant.
3802-
all_nullary = false;
3803-
kind = struct_variant_kind(self.parse_struct_def());
3804-
} else if *self.token == token::LPAREN {
3805-
all_nullary = false;
3806-
let arg_tys = self.parse_unspanned_seq(
3807-
&token::LPAREN,
3808-
&token::RPAREN,
3809-
seq_sep_trailing_disallowed(token::COMMA),
3810-
|p| p.parse_ty(false)
3811-
);
3812-
for arg_tys.each |ty| {
3813-
args.push(ast::variant_arg {
3814-
ty: *ty,
3815-
id: self.get_id(),
3816-
});
3817-
}
3818-
kind = tuple_variant_kind(args);
3819-
} else if self.eat(&token::EQ) {
3820-
have_disr = true;
3821-
disr_expr = Some(self.parse_expr());
3822-
kind = tuple_variant_kind(args);
3812+
if self.eat_keyword(&~"enum") {
3813+
ident = self.parse_ident();
3814+
self.expect(&token::LBRACE);
3815+
let nested_enum_def = self.parse_enum_def(generics);
3816+
kind = enum_variant_kind(nested_enum_def);
3817+
needs_comma = false;
38233818
} else {
3824-
kind = tuple_variant_kind(~[]);
3819+
ident = self.parse_ident();
3820+
if self.eat(&token::LBRACE) {
3821+
// Parse a struct variant.
3822+
all_nullary = false;
3823+
kind = struct_variant_kind(self.parse_struct_def());
3824+
} else if *self.token == token::LPAREN {
3825+
all_nullary = false;
3826+
let arg_tys = self.parse_unspanned_seq(
3827+
&token::LPAREN,
3828+
&token::RPAREN,
3829+
seq_sep_trailing_disallowed(token::COMMA),
3830+
|p| p.parse_ty(false)
3831+
);
3832+
for arg_tys.each |ty| {
3833+
args.push(ast::variant_arg {
3834+
ty: *ty,
3835+
id: self.get_id(),
3836+
});
3837+
}
3838+
kind = tuple_variant_kind(args);
3839+
} else if self.eat(&token::EQ) {
3840+
have_disr = true;
3841+
disr_expr = Some(self.parse_expr());
3842+
kind = tuple_variant_kind(args);
3843+
} else {
3844+
kind = tuple_variant_kind(~[]);
3845+
}
3846+
needs_comma = true;
38253847
}
3826-
needs_comma = true;
38273848

38283849
let vr = ast::variant_ {
38293850
name: ident,
@@ -3843,7 +3864,7 @@ pub impl Parser {
38433864
enum");
38443865
}
38453866

3846-
ast::enum_def { variants: variants }
3867+
ast::enum_def { variants: variants, common: common_fields }
38473868
}
38483869

38493870
fn parse_item_enum(&self) -> item_info {
@@ -3871,7 +3892,7 @@ pub impl Parser {
38713892
return (
38723893
id,
38733894
item_enum(
3874-
ast::enum_def { variants: ~[variant] },
3895+
ast::enum_def { variants: ~[variant], common: None },
38753896
generics),
38763897
None
38773898
);

branches/dist-snap/src/libsyntax/print/pprust.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,9 @@ pub fn print_variant(s: @ps, v: ast::variant) {
785785
let generics = ast_util::empty_generics();
786786
print_struct(s, struct_def, &generics, v.node.name, v.span);
787787
}
788+
ast::enum_variant_kind(ref enum_definition) => {
789+
print_variants(s, (*enum_definition).variants, v.span);
790+
}
788791
}
789792
match v.node.disr_expr {
790793
Some(d) => {

branches/dist-snap/src/libsyntax/visit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ pub fn visit_enum_def<E>(enum_definition: ast::enum_def,
215215
(v.visit_struct_def)(struct_def, vr.node.name, tps,
216216
vr.node.id, e, v);
217217
}
218+
enum_variant_kind(ref enum_definition) => {
219+
visit_enum_def((*enum_definition), tps, e, v);
220+
}
218221
}
219222
// Visit the disr expr if it exists
220223
for vr.node.disr_expr.each |ex| { (v.visit_expr)(*ex, e, v) }

0 commit comments

Comments
 (0)