1010
1111use llvm:: { self , LLVMConstInBoundsGEP } ;
1212use rustc:: ty:: { self , Ty } ;
13- use rustc:: ty:: layout:: { self , Align , TyLayout , LayoutOf , Size } ;
13+ use rustc:: ty:: layout:: { self , Align , TyLayout , LayoutOf , Size , VariantIdx } ;
1414use rustc:: mir;
1515use rustc:: mir:: tcx:: PlaceTy ;
1616use base;
@@ -281,7 +281,7 @@ impl PlaceRef<'ll, 'tcx> {
281281 match self . layout . variants {
282282 layout:: Variants :: Single { index } => {
283283 let discr_val = self . layout . ty . ty_adt_def ( ) . map_or (
284- index as u128 ,
284+ index. as_u32 ( ) as u128 ,
285285 |def| def. discriminant_for_variant ( bx. cx . tcx , index) . val ) ;
286286 return C_uint_big ( cast_to, discr_val) ;
287287 }
@@ -320,24 +320,24 @@ impl PlaceRef<'ll, 'tcx> {
320320 C_uint_big ( niche_llty, niche_start)
321321 } ;
322322 bx. select ( bx. icmp ( llvm:: IntEQ , lldiscr, niche_llval) ,
323- C_uint ( cast_to, * niche_variants. start ( ) as u64 ) ,
324- C_uint ( cast_to, dataful_variant as u64 ) )
323+ C_uint ( cast_to, niche_variants. start ( ) . as_u32 ( ) as u64 ) ,
324+ C_uint ( cast_to, dataful_variant. as_u32 ( ) as u64 ) )
325325 } else {
326326 // Rebase from niche values to discriminant values.
327- let delta = niche_start. wrapping_sub ( * niche_variants. start ( ) as u128 ) ;
327+ let delta = niche_start. wrapping_sub ( niche_variants. start ( ) . as_u32 ( ) as u128 ) ;
328328 let lldiscr = bx. sub ( lldiscr, C_uint_big ( niche_llty, delta) ) ;
329- let lldiscr_max = C_uint ( niche_llty, * niche_variants. end ( ) as u64 ) ;
329+ let lldiscr_max = C_uint ( niche_llty, niche_variants. end ( ) . as_u32 ( ) as u64 ) ;
330330 bx. select ( bx. icmp ( llvm:: IntULE , lldiscr, lldiscr_max) ,
331331 bx. intcast ( lldiscr, cast_to, false ) ,
332- C_uint ( cast_to, dataful_variant as u64 ) )
332+ C_uint ( cast_to, dataful_variant. as_u32 ( ) as u64 ) )
333333 }
334334 }
335335 }
336336 }
337337
338338 /// Set the discriminant for a new value of the given case of the given
339339 /// representation.
340- pub fn codegen_set_discr ( & self , bx : & Builder < ' a , ' ll , ' tcx > , variant_index : usize ) {
340+ pub fn codegen_set_discr ( & self , bx : & Builder < ' a , ' ll , ' tcx > , variant_index : VariantIdx ) {
341341 if self . layout . for_variant ( bx. cx , variant_index) . abi . is_uninhabited ( ) {
342342 return ;
343343 }
@@ -376,7 +376,8 @@ impl PlaceRef<'ll, 'tcx> {
376376
377377 let niche = self . project_field ( bx, 0 ) ;
378378 let niche_llty = niche. layout . immediate_llvm_type ( bx. cx ) ;
379- let niche_value = ( ( variant_index - * niche_variants. start ( ) ) as u128 )
379+ let niche_value = variant_index. as_u32 ( ) - niche_variants. start ( ) . as_u32 ( ) ;
380+ let niche_value = ( niche_value as u128 )
380381 . wrapping_add ( niche_start) ;
381382 // FIXME(eddyb) Check the actual primitive type here.
382383 let niche_llval = if niche_value == 0 {
@@ -401,7 +402,7 @@ impl PlaceRef<'ll, 'tcx> {
401402 }
402403 }
403404
404- pub fn project_downcast ( & self , bx : & Builder < ' a , ' ll , ' tcx > , variant_index : usize )
405+ pub fn project_downcast ( & self , bx : & Builder < ' a , ' ll , ' tcx > , variant_index : VariantIdx )
405406 -> PlaceRef < ' ll , ' tcx > {
406407 let mut downcast = * self ;
407408 downcast. layout = self . layout . for_variant ( bx. cx , variant_index) ;
0 commit comments