@@ -217,12 +217,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
217
217
match layout. variants {
218
218
Variants :: Multiple { tag_field, .. } => {
219
219
if tag_field == field {
220
- return match layout. ty . kind ( ) {
220
+ return match layout. ty . strip_variant_type ( ) . kind ( ) {
221
221
ty:: Adt ( def, ..) if def. is_enum ( ) => PathElem :: EnumTag ,
222
- ty:: Variant ( ty, ..) => match ty. kind ( ) {
223
- ty:: Adt ( def, ..) if def. is_enum ( ) => PathElem :: EnumTag ,
224
- _ => bug ! ( "non-variant type {:?}" , layout. ty) ,
225
- } ,
226
222
ty:: Generator ( ..) => PathElem :: GeneratorTag ,
227
223
_ => bug ! ( "non-variant type {:?}" , layout. ty) ,
228
224
} ;
@@ -232,7 +228,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
232
228
}
233
229
234
230
// Now we know we are projecting to a field, so figure out which one.
235
- match layout. ty . kind ( ) {
231
+ match layout. ty . strip_variant_type ( ) . kind ( ) {
236
232
// generators and closures.
237
233
ty:: Closure ( def_id, _) | ty:: Generator ( def_id, _, _) => {
238
234
let mut name = None ;
@@ -276,20 +272,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
276
272
}
277
273
}
278
274
279
- ty:: Variant ( ty, ..) => match ty. kind ( ) {
280
- ty:: Adt ( def, ..) if def. is_enum ( ) => {
281
- // we might be projecting *to* a variant, or to a field *in* a variant.
282
- match layout. variants {
283
- Variants :: Single { index } => {
284
- // Inside a variant
285
- PathElem :: Field ( def. variants [ index] . fields [ field] . ident . name )
286
- }
287
- Variants :: Multiple { .. } => bug ! ( "we handled variants above" ) ,
288
- }
289
- }
290
- _ => bug ! ( "unexpected type: {:?}" , ty. kind( ) ) ,
291
- } ,
292
-
293
275
// other ADTs
294
276
ty:: Adt ( def, _) => PathElem :: Field ( def. non_enum_variant ( ) . fields [ field] . ident . name ) ,
295
277
@@ -513,7 +495,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
513
495
) -> InterpResult < ' tcx , bool > {
514
496
// Go over all the primitive types
515
497
let ty = value. layout . ty ;
516
- match ty. kind ( ) {
498
+ match ty. strip_variant_type ( ) . kind ( ) {
517
499
ty:: Bool => {
518
500
let value = self . read_scalar ( value) ?;
519
501
try_validation ! (
@@ -585,17 +567,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
585
567
self . check_safe_pointer ( value, "box" ) ?;
586
568
Ok ( true )
587
569
}
588
- ty:: Variant ( ty, _) => match ty. kind ( ) {
589
- ty:: Adt ( def, _) => {
590
- if def. is_box ( ) {
591
- self . check_safe_pointer ( value, "box" ) ?;
592
- Ok ( true )
593
- } else {
594
- Ok ( false )
595
- }
596
- }
597
- _ => bug ! ( "unexpected type: {:?}" , ty. kind( ) ) ,
598
- } ,
599
570
ty:: FnPtr ( _sig) => {
600
571
let value = try_validation ! (
601
572
self . ecx. read_immediate( value) ,
@@ -641,6 +612,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
641
612
| ty:: Opaque ( ..)
642
613
| ty:: Projection ( ..)
643
614
| ty:: GeneratorWitness ( ..) => bug ! ( "Encountered invalid type {:?}" , ty) ,
615
+
616
+ ty:: Variant ( ..) => unreachable ! ( ) ,
644
617
}
645
618
}
646
619
@@ -756,15 +729,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
756
729
variant_id : VariantIdx ,
757
730
new_op : & OpTy < ' tcx , M :: PointerTag > ,
758
731
) -> InterpResult < ' tcx > {
759
- let name = match old_op. layout . ty . kind ( ) {
732
+ let ty = old_op. layout . ty . strip_variant_type ( ) ;
733
+ let name = match ty. kind ( ) {
760
734
ty:: Adt ( adt, _) => PathElem :: Variant ( adt. variants [ variant_id] . ident . name ) ,
761
- ty:: Variant ( ty, ..) => match ty. kind ( ) {
762
- ty:: Adt ( adt, ..) => PathElem :: Variant ( adt. variants [ variant_id] . ident . name ) ,
763
- _ => bug ! ( "unexpected type {:?}" , ty. kind( ) ) ,
764
- } ,
765
735
// Generators also have variants
766
736
ty:: Generator ( ..) => PathElem :: GeneratorState ( variant_id) ,
767
- _ => bug ! ( "Unexpected type with variant: {:?}" , old_op . layout . ty) ,
737
+ _ => bug ! ( "Unexpected type with variant: {:?}" , ty) ,
768
738
} ;
769
739
self . with_elem ( name, move |this| this. visit_value ( new_op) )
770
740
}
0 commit comments