10
10
11
11
use llvm:: { self , LLVMConstInBoundsGEP } ;
12
12
use 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 } ;
14
14
use rustc:: mir;
15
15
use rustc:: mir:: tcx:: PlaceTy ;
16
16
use base;
@@ -281,7 +281,7 @@ impl PlaceRef<'ll, 'tcx> {
281
281
match self . layout . variants {
282
282
layout:: Variants :: Single { index } => {
283
283
let discr_val = self . layout . ty . ty_adt_def ( ) . map_or (
284
- index as u128 ,
284
+ index. as_u32 ( ) as u128 ,
285
285
|def| def. discriminant_for_variant ( bx. cx . tcx , index) . val ) ;
286
286
return C_uint_big ( cast_to, discr_val) ;
287
287
}
@@ -320,24 +320,24 @@ impl PlaceRef<'ll, 'tcx> {
320
320
C_uint_big ( niche_llty, niche_start)
321
321
} ;
322
322
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 ) )
325
325
} else {
326
326
// 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 ) ;
328
328
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 ) ;
330
330
bx. select ( bx. icmp ( llvm:: IntULE , lldiscr, lldiscr_max) ,
331
331
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 ) )
333
333
}
334
334
}
335
335
}
336
336
}
337
337
338
338
/// Set the discriminant for a new value of the given case of the given
339
339
/// 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 ) {
341
341
if self . layout . for_variant ( bx. cx , variant_index) . abi . is_uninhabited ( ) {
342
342
return ;
343
343
}
@@ -376,7 +376,8 @@ impl PlaceRef<'ll, 'tcx> {
376
376
377
377
let niche = self . project_field ( bx, 0 ) ;
378
378
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 )
380
381
. wrapping_add ( niche_start) ;
381
382
// FIXME(eddyb) Check the actual primitive type here.
382
383
let niche_llval = if niche_value == 0 {
@@ -401,7 +402,7 @@ impl PlaceRef<'ll, 'tcx> {
401
402
}
402
403
}
403
404
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 )
405
406
-> PlaceRef < ' ll , ' tcx > {
406
407
let mut downcast = * self ;
407
408
downcast. layout = self . layout . for_variant ( bx. cx , variant_index) ;
0 commit comments