@@ -35,22 +35,16 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
35
35
36
36
Goto { target } => self . goto_block ( target) ,
37
37
38
- If { ref cond, targets : ( then_target, else_target) } => {
39
- let cond_val = self . eval_operand_to_primval ( cond) ?. to_bool ( ) ?;
40
- self . goto_block ( if cond_val { then_target } else { else_target } ) ;
41
- }
42
-
43
38
SwitchInt { ref discr, ref values, ref targets, .. } => {
44
- let discr_val = self . eval_and_read_lvalue ( discr) ?;
45
- let discr_ty = self . lvalue_ty ( discr) ;
39
+ let discr_val = self . eval_operand ( discr) ?;
40
+ let discr_ty = self . operand_ty ( discr) ;
46
41
let discr_prim = self . value_to_primval ( discr_val, discr_ty) ?;
47
42
48
43
// Branch to the `otherwise` case by default, if no match is found.
49
44
let mut target_block = targets[ targets. len ( ) - 1 ] ;
50
45
51
- for ( index, const_val) in values. iter ( ) . enumerate ( ) {
52
- let val = self . const_to_value ( const_val) ?;
53
- let prim = self . value_to_primval ( val, discr_ty) ?;
46
+ for ( index, const_int) in values. iter ( ) . enumerate ( ) {
47
+ let prim = PrimVal :: Bytes ( const_int. to_u128_unchecked ( ) ) ;
54
48
if discr_prim. to_bytes ( ) ? == prim. to_bytes ( ) ? {
55
49
target_block = targets[ index] ;
56
50
break ;
@@ -60,23 +54,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
60
54
self . goto_block ( target_block) ;
61
55
}
62
56
63
- Switch { ref discr, ref targets, adt_def } => {
64
- // FIXME(solson)
65
- let lvalue = self . eval_lvalue ( discr) ?;
66
- let lvalue = self . force_allocation ( lvalue) ?;
67
-
68
- let adt_ptr = lvalue. to_ptr ( ) ;
69
- let adt_ty = self . lvalue_ty ( discr) ;
70
- let discr_val = self . read_discriminant_value ( adt_ptr, adt_ty) ?;
71
- let matching = adt_def. variants . iter ( )
72
- . position ( |v| discr_val == v. disr_val . to_u128_unchecked ( ) ) ;
73
-
74
- match matching {
75
- Some ( i) => self . goto_block ( targets[ i] ) ,
76
- None => return Err ( EvalError :: InvalidDiscriminant ) ,
77
- }
78
- }
79
-
80
57
Call { ref func, ref args, ref destination, .. } => {
81
58
let destination = match * destination {
82
59
Some ( ( ref lv, target) ) => Some ( ( self . eval_lvalue ( lv) ?, target) ) ,
@@ -216,12 +193,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
216
193
trace ! ( "layout({:?}) = {:#?}" , dest_ty, dest_layout) ;
217
194
match * dest_layout {
218
195
Layout :: Univariant { .. } => {
219
- let disr_val = v. disr_val . to_u128_unchecked ( ) ;
196
+ let disr_val = v. disr_val ;
220
197
assert_eq ! ( disr_val, 0 ) ;
221
198
self . assign_fields ( lvalue, dest_ty, args) ?;
222
199
} ,
223
200
Layout :: General { discr, ref variants, .. } => {
224
- let disr_val = v. disr_val . to_u128_unchecked ( ) ;
201
+ let disr_val = v. disr_val ;
225
202
let discr_size = discr. size ( ) . bytes ( ) ;
226
203
self . assign_discr_and_fields (
227
204
lvalue,
@@ -234,7 +211,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
234
211
) ?;
235
212
} ,
236
213
Layout :: StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
237
- let disr_val = v. disr_val . to_u128_unchecked ( ) ;
214
+ let disr_val = v. disr_val ;
238
215
if nndiscr as u128 == disr_val {
239
216
self . assign_fields ( lvalue, dest_ty, args) ?;
240
217
} else {
@@ -325,7 +302,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
325
302
}
326
303
}
327
304
328
- fn read_discriminant_value ( & self , adt_ptr : Pointer , adt_ty : Ty < ' tcx > ) -> EvalResult < ' tcx , u128 > {
305
+ pub fn read_discriminant_value ( & self , adt_ptr : Pointer , adt_ty : Ty < ' tcx > ) -> EvalResult < ' tcx , u128 > {
329
306
use rustc:: ty:: layout:: Layout :: * ;
330
307
let adt_layout = self . type_layout ( adt_ty) ?;
331
308
trace ! ( "read_discriminant_value {:#?}" , adt_layout) ;
0 commit comments