@@ -219,6 +219,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
219
219
if tag_field == field {
220
220
return match layout. ty . 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
+ } ,
222
226
ty:: Generator ( ..) => PathElem :: GeneratorTag ,
223
227
_ => bug ! ( "non-variant type {:?}" , layout. ty) ,
224
228
} ;
@@ -272,6 +276,20 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
272
276
}
273
277
}
274
278
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
+
275
293
// other ADTs
276
294
ty:: Adt ( def, _) => PathElem :: Field ( def. non_enum_variant ( ) . fields [ field] . ident . name ) ,
277
295
@@ -567,6 +585,17 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
567
585
self . check_safe_pointer ( value, "box" ) ?;
568
586
Ok ( true )
569
587
}
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
+ } ,
570
599
ty:: FnPtr ( _sig) => {
571
600
let value = try_validation ! (
572
601
self . ecx. read_immediate( value) ,
@@ -729,6 +758,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
729
758
) -> InterpResult < ' tcx > {
730
759
let name = match old_op. layout . ty . kind ( ) {
731
760
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
+ } ,
732
765
// Generators also have variants
733
766
ty:: Generator ( ..) => PathElem :: GeneratorState ( variant_id) ,
734
767
_ => bug ! ( "Unexpected type with variant: {:?}" , old_op. layout. ty) ,
0 commit comments