@@ -3816,41 +3816,62 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
3816
3816
} , _) => {
3817
3817
let mut disr_val = -1 ;
3818
3818
@enum_definition. variants . iter ( ) . transform ( |variant| {
3819
+
3820
+ let ctor_ty = node_id_to_type ( cx, variant. node . id ) ;
3821
+
3819
3822
match variant. node . kind {
3820
3823
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 ( ) > 0 u {
3824
- ty_fn_args ( ctor_ty) . map ( |a| * a)
3825
- } else {
3824
+ let arg_tys = if args. len ( ) > 0 u {
3825
+ ty_fn_args ( ctor_ty) . map ( |a| * a) }
3826
+ else {
3826
3827
~[ ]
3827
- }
3828
- } ;
3828
+ } ;
3829
+
3829
3830
match variant. node . disr_expr {
3830
3831
Some ( ex) => {
3831
3832
disr_val = match const_eval:: eval_const_expr ( cx,
3832
3833
ex) {
3833
3834
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" )
3835
3836
}
3836
3837
}
3837
3838
_ => disr_val += 1
3838
3839
}
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
3845
3847
}
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
+ }
3849
3870
}
3850
3871
}
3851
3872
} ) . collect ( )
3852
3873
}
3853
- _ => cx. sess . bug ( "tag_variants : id not bound to an enum" )
3874
+ _ => cx. sess . bug ( "enum_variants : id not bound to an enum" )
3854
3875
}
3855
3876
} ;
3856
3877
cx. enum_var_cache . insert ( id, result) ;
0 commit comments