@@ -231,39 +231,36 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
231231}
232232
233233/**
234- * Obtain as much of a "discriminant" as this representation has.
234+ * Obtain a representation of the discriminant sufficient to translate
235+ * destructuring; this may or may not involve the actual discriminant.
236+ *
235237 * This should ideally be less tightly tied to `_match`.
236238 */
237239pub fn trans_switch ( bcx : block , r : & Repr , scrutinee : ValueRef )
238240 -> ( _match:: branch_kind , Option < ValueRef > ) {
239241 match * r {
240242 CEnum ( * ) | General ( * ) => {
241- ( _match:: switch, Some ( trans_cast_to_int ( bcx, r, scrutinee) ) )
243+ ( _match:: switch, Some ( trans_get_discr ( bcx, r, scrutinee) ) )
242244 }
243245 Unit ( * ) | Univariant ( * ) => {
244246 ( _match:: single, None )
245247 }
246248 }
247249}
248250
249- /**
250- * If the representation is potentially of a C-like enum, implement
251- * coercion to numeric types.
252- */
253- pub fn trans_cast_to_int ( bcx : block , r : & Repr , scrutinee : ValueRef )
251+ /// Obtain the actual discriminant of a value.
252+ pub fn trans_get_discr ( bcx : block , r : & Repr , scrutinee : ValueRef )
254253 -> ValueRef {
255254 match * r {
256255 Unit ( the_disc) => C_int ( bcx. ccx ( ) , the_disc) ,
257256 CEnum ( min, max) => load_discr ( bcx, scrutinee, min, max) ,
258- Univariant ( * ) => bcx. ccx ( ) . sess . bug ( ~"type has no explicit \
259- discriminant") ,
260- // Note: this case is used internally by trans_switch,
261- // even though it shouldn't be reached by an external caller.
257+ Univariant ( * ) => C_int ( bcx. ccx ( ) , 0 ) ,
262258 General ( ref cases) => load_discr ( bcx, scrutinee, 0 ,
263259 ( cases. len ( ) - 1 ) as int )
264260 }
265261}
266262
263+ /// Helper for cases where the discriminant is simply loaded.
267264fn load_discr ( bcx : block , scrutinee : ValueRef , min : int , max : int )
268265 -> ValueRef {
269266 let ptr = GEPi ( bcx, scrutinee, [ 0 , 0 ] ) ;
@@ -285,6 +282,7 @@ fn load_discr(bcx: block, scrutinee: ValueRef, min: int, max: int)
285282/**
286283 * Yield information about how to dispatch a case of the
287284 * discriminant-like value returned by `trans_switch`.
285+ *
288286 * This should ideally be less tightly tied to `_match`.
289287 */
290288pub fn trans_case( bcx : block , r : & Repr , discr : int ) -> _match:: opt_result {
0 commit comments