@@ -3828,41 +3828,62 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
3828
3828
} , _) => {
3829
3829
let mut disr_val = -1 ;
3830
3830
@enum_definition. variants . iter ( ) . transform ( |variant| {
3831
+
3832
+ let ctor_ty = node_id_to_type ( cx, variant. node . id ) ;
3833
+
3831
3834
match variant. node . kind {
3832
3835
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 ( ) > 0 u {
3836
- ty_fn_args ( ctor_ty) . map ( |a| * a)
3837
- } else {
3836
+ let arg_tys = if args. len ( ) > 0 u {
3837
+ ty_fn_args ( ctor_ty) . map ( |a| * a) }
3838
+ else {
3838
3839
~[ ]
3839
- }
3840
- } ;
3840
+ } ;
3841
+
3841
3842
match variant. node . disr_expr {
3842
3843
Some ( ex) => {
3843
3844
disr_val = match const_eval:: eval_const_expr ( cx,
3844
3845
ex) {
3845
3846
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" )
3847
3848
}
3848
3849
}
3849
3850
_ => disr_val += 1
3850
3851
}
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
3857
3859
}
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
+ }
3861
3882
}
3862
3883
}
3863
3884
} ) . collect ( )
3864
3885
}
3865
- _ => cx. sess . bug ( "tag_variants : id not bound to an enum" )
3886
+ _ => cx. sess . bug ( "enum_variants : id not bound to an enum" )
3866
3887
}
3867
3888
} ;
3868
3889
cx. enum_var_cache . insert ( id, result) ;
0 commit comments