Skip to content

Commit 8ec84ec

Browse files
committed
---
yaml --- r: 64057 b: refs/heads/snap-stage3 c: 88487d8 h: refs/heads/master i: 64055: 7d925ab v: v3
1 parent 3dfb606 commit 8ec84ec

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: b16825216e7b4196a88b103cd6921d8cdb0ba7be
4+
refs/heads/snap-stage3: 88487d8274a51afa253d9f9612991621f1ec4fd0
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

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

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,41 +3828,62 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
38283828
}, _) => {
38293829
let mut disr_val = -1;
38303830
@enum_definition.variants.iter().transform(|variant| {
3831+
3832+
let ctor_ty = node_id_to_type(cx, variant.node.id);
3833+
38313834
match variant.node.kind {
38323835
ast::tuple_variant_kind(ref args) => {
3833-
let ctor_ty = node_id_to_type(cx, variant.node.id);
3834-
let arg_tys = {
3835-
if args.len() > 0u {
3836-
ty_fn_args(ctor_ty).map(|a| *a)
3837-
} else {
3836+
let arg_tys = if args.len() > 0u {
3837+
ty_fn_args(ctor_ty).map(|a| *a) }
3838+
else {
38383839
~[]
3839-
}
3840-
};
3840+
};
3841+
38413842
match variant.node.disr_expr {
38423843
Some (ex) => {
38433844
disr_val = match const_eval::eval_const_expr(cx,
38443845
ex) {
38453846
const_eval::const_int(val) => val as int,
3846-
_ => cx.sess.bug("tag_variants: bad disr expr")
3847+
_ => cx.sess.bug("enum_variants: bad disr expr")
38473848
}
38483849
}
38493850
_ => disr_val += 1
38503851
}
3851-
@VariantInfo_{args: arg_tys,
3852-
ctor_ty: ctor_ty,
3853-
name: variant.node.name,
3854-
id: ast_util::local_def(variant.node.id),
3855-
disr_val: disr_val,
3856-
vis: variant.node.vis
3852+
@VariantInfo_{
3853+
args: arg_tys,
3854+
ctor_ty: ctor_ty,
3855+
name: variant.node.name,
3856+
id: ast_util::local_def(variant.node.id),
3857+
disr_val: disr_val,
3858+
vis: variant.node.vis
38573859
}
3858-
}
3859-
ast::struct_variant_kind(_) => {
3860-
fail!("struct variant kinds unimpl in enum_variants")
3860+
},
3861+
ast::struct_variant_kind(struct_def) => {
3862+
let arg_tys =
3863+
// Is this check needed for structs too, or are they always guaranteed
3864+
// to have a valid constructor function?
3865+
if struct_def.fields.len() > 0 {
3866+
ty_fn_args(ctor_ty).map(|a| *a)
3867+
} else {
3868+
~[]
3869+
};
3870+
3871+
assert!(variant.node.disr_expr.is_none());
3872+
disr_val += 1;
3873+
3874+
@VariantInfo_{
3875+
args: arg_tys,
3876+
ctor_ty: ctor_ty,
3877+
name: variant.node.name,
3878+
id: ast_util::local_def(variant.node.id),
3879+
disr_val: disr_val,
3880+
vis: variant.node.vis
3881+
}
38613882
}
38623883
}
38633884
}).collect()
38643885
}
3865-
_ => cx.sess.bug("tag_variants: id not bound to an enum")
3886+
_ => cx.sess.bug("enum_variants: id not bound to an enum")
38663887
}
38673888
};
38683889
cx.enum_var_cache.insert(id, result);

0 commit comments

Comments
 (0)