Skip to content

Commit fe75145

Browse files
---
yaml --- r: 63970 b: refs/heads/snap-stage3 c: 866a5b1 h: refs/heads/master v: v3
1 parent 9c7fa34 commit fe75145

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: ab34864a304fa364dc91bf16988e272e93de8d62
4+
refs/heads/snap-stage3: 866a5b1c78e52bd5c1c34df4a1a3c363ad6bfe7c
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
@@ -3816,41 +3816,62 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
38163816
}, _) => {
38173817
let mut disr_val = -1;
38183818
@enum_definition.variants.iter().transform(|variant| {
3819+
3820+
let ctor_ty = node_id_to_type(cx, variant.node.id);
3821+
38193822
match variant.node.kind {
38203823
ast::tuple_variant_kind(ref args) => {
3821-
let ctor_ty = node_id_to_type(cx, variant.node.id);
3822-
let arg_tys = {
3823-
if args.len() > 0u {
3824-
ty_fn_args(ctor_ty).map(|a| *a)
3825-
} else {
3824+
let arg_tys = if args.len() > 0u {
3825+
ty_fn_args(ctor_ty).map(|a| *a) }
3826+
else {
38263827
~[]
3827-
}
3828-
};
3828+
};
3829+
38293830
match variant.node.disr_expr {
38303831
Some (ex) => {
38313832
disr_val = match const_eval::eval_const_expr(cx,
38323833
ex) {
38333834
const_eval::const_int(val) => val as int,
3834-
_ => cx.sess.bug("tag_variants: bad disr expr")
3835+
_ => cx.sess.bug("enum_variants: bad disr expr")
38353836
}
38363837
}
38373838
_ => disr_val += 1
38383839
}
3839-
@VariantInfo_{args: arg_tys,
3840-
ctor_ty: ctor_ty,
3841-
name: variant.node.name,
3842-
id: ast_util::local_def(variant.node.id),
3843-
disr_val: disr_val,
3844-
vis: variant.node.vis
3840+
@VariantInfo_{
3841+
args: arg_tys,
3842+
ctor_ty: ctor_ty,
3843+
name: variant.node.name,
3844+
id: ast_util::local_def(variant.node.id),
3845+
disr_val: disr_val,
3846+
vis: variant.node.vis
38453847
}
3846-
}
3847-
ast::struct_variant_kind(_) => {
3848-
fail!("struct variant kinds unimpl in enum_variants")
3848+
},
3849+
ast::struct_variant_kind(struct_def) => {
3850+
let arg_tys =
3851+
// Is this check needed for structs too, or are they always guaranteed
3852+
// to have a valid constructor function?
3853+
if struct_def.fields.len() > 0 {
3854+
ty_fn_args(ctor_ty).map(|a| *a)
3855+
} else {
3856+
~[]
3857+
};
3858+
3859+
assert!(variant.node.disr_expr.is_none());
3860+
disr_val += 1;
3861+
3862+
@VariantInfo_{
3863+
args: arg_tys,
3864+
ctor_ty: ctor_ty,
3865+
name: variant.node.name,
3866+
id: ast_util::local_def(variant.node.id),
3867+
disr_val: disr_val,
3868+
vis: variant.node.vis
3869+
}
38493870
}
38503871
}
38513872
}).collect()
38523873
}
3853-
_ => cx.sess.bug("tag_variants: id not bound to an enum")
3874+
_ => cx.sess.bug("enum_variants: id not bound to an enum")
38543875
}
38553876
};
38563877
cx.enum_var_cache.insert(id, result);

0 commit comments

Comments
 (0)