@@ -159,19 +159,27 @@ fn load_discr(bcx: block, scrutinee: ValueRef, min: int, max: int)
159
159
}
160
160
}
161
161
162
- pub fn trans_switch ( bcx : block , r : & Repr , scrutinee : ValueRef ) ->
163
- ( _match:: branch_kind , Option < ValueRef > ) {
162
+ pub fn trans_switch ( bcx : block , r : & Repr , scrutinee : ValueRef )
163
+ -> ( _match:: branch_kind , Option < ValueRef > ) {
164
164
match * r {
165
- CEnum ( min , max ) => {
166
- ( _match:: switch, Some ( load_discr ( bcx, scrutinee , min , max ) ) )
165
+ CEnum ( * ) | General ( * ) => {
166
+ ( _match:: switch, Some ( trans_cast_to_int ( bcx, r , scrutinee ) ) )
167
167
}
168
168
Unit ( * ) | Univariant ( * ) => {
169
169
( _match:: single, None )
170
170
}
171
- General ( ref cases) => {
172
- ( _match:: switch, Some ( load_discr ( bcx, scrutinee, 0 ,
173
- ( cases. len ( ) - 1 ) as int ) ) )
174
- }
171
+ }
172
+ }
173
+
174
+ pub fn trans_cast_to_int ( bcx : block , r : & Repr , scrutinee : ValueRef )
175
+ -> ValueRef {
176
+ match * r {
177
+ Unit ( the_disc) => C_int ( bcx. ccx ( ) , the_disc) ,
178
+ CEnum ( min, max) => load_discr ( bcx, scrutinee, min, max) ,
179
+ Univariant ( * ) => bcx. ccx ( ) . sess . bug ( ~"type has no explicit \
180
+ discriminant") ,
181
+ General ( ref cases) => load_discr ( bcx, scrutinee, 0 ,
182
+ ( cases. len ( ) - 1 ) as int )
175
183
}
176
184
}
177
185
0 commit comments