@@ -71,14 +71,6 @@ use util::ppaux::ty_to_str;
7171
7272/// Representations.
7373pub enum Repr {
74- /**
75- * `Unit` exists only so that an enum with a single C-like variant
76- * can occupy no space, for ABI compatibility with rustc from
77- * before (and during) the creation of this module. It may not be
78- * worth keeping around; `CEnum` and `Univariant` cover it
79- * overwise.
80- */
81- Unit ( int ) ,
8274 /// C-like enums; basically an int.
8375 CEnum ( int , int ) , // discriminant range
8476 /**
@@ -146,18 +138,15 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
146138 } ;
147139 if cases. len ( ) == 0 {
148140 // Uninhabitable; represent as unit
149- Unit ( 0 )
150- } else if cases. len ( ) == 1 && cases[ 0 ] . tys . len ( ) == 0 {
151- // `()`-like; see comment on definition of `Unit`.
152- Unit ( cases[ 0 ] . discr )
153- } else if cases. len ( ) == 1 {
154- // Equivalent to a struct/tuple/newtype.
155- fail_unless ! ( cases[ 0 ] . discr == 0 ) ;
156- Univariant ( mk_struct ( cx, cases[ 0 ] . tys ) , false )
141+ Univariant ( mk_struct ( cx, ~[ ] ) , false )
157142 } else if cases. all ( |c| c. tys . len ( ) == 0 ) {
158143 // All bodies empty -> intlike
159144 let discrs = cases. map ( |c| c. discr ) ;
160145 CEnum ( discrs. min ( ) , discrs. max ( ) )
146+ } else if cases. len ( ) == 1 {
147+ // Equivalent to a struct/tuple/newtype.
148+ fail_unless ! ( cases[ 0 ] . discr == 0 ) ;
149+ Univariant ( mk_struct ( cx, cases[ 0 ] . tys ) , false )
161150 } else {
162151 // The general case. Since there's at least one
163152 // non-empty body, explicit discriminants should have
@@ -201,7 +190,6 @@ pub fn sizing_fields_of(cx: @CrateContext, r: &Repr) -> ~[TypeRef] {
201190fn generic_fields_of ( cx : @CrateContext , r : & Repr , sizing : bool )
202191 -> ~[ TypeRef ] {
203192 match * r {
204- Unit ( * ) => ~[ ] ,
205193 CEnum ( * ) => ~[ T_enum_discrim ( cx) ] ,
206194 Univariant ( ref st, _dtor) => {
207195 if sizing {
@@ -229,7 +217,7 @@ pub fn trans_switch(bcx: block, r: &Repr, scrutinee: ValueRef)
229217 CEnum ( * ) | General ( * ) => {
230218 ( _match:: switch, Some ( trans_get_discr ( bcx, r, scrutinee) ) )
231219 }
232- Unit ( * ) | Univariant ( * ) => {
220+ Univariant ( * ) => {
233221 ( _match:: single, None )
234222 }
235223 }
@@ -239,7 +227,6 @@ pub fn trans_switch(bcx: block, r: &Repr, scrutinee: ValueRef)
239227pub fn trans_get_discr ( bcx : block , r : & Repr , scrutinee : ValueRef )
240228 -> ValueRef {
241229 match * r {
242- Unit ( the_disc) => C_int ( bcx. ccx ( ) , the_disc) ,
243230 CEnum ( min, max) => load_discr ( bcx, scrutinee, min, max) ,
244231 Univariant ( * ) => C_int ( bcx. ccx ( ) , 0 ) ,
245232 General ( ref cases) => load_discr ( bcx, scrutinee, 0 ,
@@ -277,7 +264,7 @@ pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
277264 CEnum ( * ) => {
278265 _match:: single_result ( rslt ( bcx, C_int ( bcx. ccx ( ) , discr) ) )
279266 }
280- Unit ( * ) | Univariant ( * ) => {
267+ Univariant ( * ) => {
281268 bcx. ccx ( ) . sess . bug ( ~"no cases for univariants or structs")
282269 }
283270 General ( * ) => {
@@ -293,9 +280,6 @@ pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
293280 */
294281pub fn trans_start_init ( bcx : block , r : & Repr , val : ValueRef , discr : int ) {
295282 match * r {
296- Unit ( the_discr) => {
297- fail_unless ! ( discr == the_discr) ;
298- }
299283 CEnum ( min, max) => {
300284 fail_unless ! ( min <= discr && discr <= max) ;
301285 Store ( bcx, C_int ( bcx. ccx ( ) , discr) , GEPi ( bcx, val, [ 0 , 0 ] ) )
@@ -320,7 +304,7 @@ pub fn trans_start_init(bcx: block, r: &Repr, val: ValueRef, discr: int) {
320304 */
321305pub fn num_args ( r : & Repr , discr : int ) -> uint {
322306 match * r {
323- Unit ( * ) | CEnum ( * ) => 0 ,
307+ CEnum ( * ) => 0 ,
324308 Univariant ( ref st, dtor) => {
325309 fail_unless ! ( discr == 0 ) ;
326310 st. fields . len ( ) - ( if dtor { 1 } else { 0 } )
@@ -336,7 +320,7 @@ pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
336320 // decide to do some kind of cdr-coding-like non-unique repr
337321 // someday), it will need to return a possibly-new bcx as well.
338322 match * r {
339- Unit ( * ) | CEnum ( * ) => {
323+ CEnum ( * ) => {
340324 bcx. ccx ( ) . sess . bug ( ~"element access in C -like enum")
341325 }
342326 Univariant ( ref st, _dtor) => {
@@ -399,9 +383,6 @@ pub fn trans_drop_flag_ptr(bcx: block, r: &Repr, val: ValueRef) -> ValueRef {
399383pub fn trans_const ( ccx : @CrateContext , r : & Repr , discr : int ,
400384 vals : & [ ValueRef ] ) -> ValueRef {
401385 match * r {
402- Unit ( * ) => {
403- C_struct ( ~[ ] )
404- }
405386 CEnum ( min, max) => {
406387 fail_unless ! ( vals. len( ) == 0 ) ;
407388 fail_unless ! ( min <= discr && discr <= max) ;
@@ -475,7 +456,6 @@ fn roundup(x: u64, a: u64) -> u64 { ((x + (a - 1)) / a) * a }
475456pub fn const_get_discrim ( ccx : @CrateContext , r : & Repr , val : ValueRef )
476457 -> int {
477458 match * r {
478- Unit ( discr) => discr,
479459 CEnum ( * ) => const_to_int ( val) as int ,
480460 Univariant ( * ) => 0 ,
481461 General ( * ) => const_to_int ( const_get_elt ( ccx, val, [ 0 ] ) ) as int ,
@@ -492,7 +472,7 @@ pub fn const_get_discrim(ccx: @CrateContext, r: &Repr, val: ValueRef)
492472pub fn const_get_field( ccx : @CrateContext , r : & Repr , val : ValueRef ,
493473 _discr : int , ix : uint ) -> ValueRef {
494474 match * r {
495- Unit ( * ) | CEnum ( * ) => ccx. sess . bug ( ~"element access in C -like enum \
475+ CEnum ( * ) => ccx. sess . bug ( ~"element access in C -like enum \
496476 const ") ,
497477 Univariant ( * ) => const_struct_field ( ccx, val, ix) ,
498478 General ( * ) => const_struct_field ( ccx, const_get_elt ( ccx, val,
0 commit comments