@@ -219,6 +219,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
219219 if tag_field == field {
220220 return match layout. ty . kind ( ) {
221221 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+ } ,
222226 ty:: Generator ( ..) => PathElem :: GeneratorTag ,
223227 _ => bug ! ( "non-variant type {:?}" , layout. ty) ,
224228 } ;
@@ -272,6 +276,20 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
272276 }
273277 }
274278
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+
275293 // other ADTs
276294 ty:: Adt ( def, _) => PathElem :: Field ( def. non_enum_variant ( ) . fields [ field] . ident . name ) ,
277295
@@ -567,6 +585,17 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
567585 self . check_safe_pointer ( value, "box" ) ?;
568586 Ok ( true )
569587 }
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+ } ,
570599 ty:: FnPtr ( _sig) => {
571600 let value = try_validation ! (
572601 self . ecx. read_immediate( value) ,
@@ -729,6 +758,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
729758 ) -> InterpResult < ' tcx > {
730759 let name = match old_op. layout . ty . kind ( ) {
731760 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+ } ,
732765 // Generators also have variants
733766 ty:: Generator ( ..) => PathElem :: GeneratorState ( variant_id) ,
734767 _ => bug ! ( "Unexpected type with variant: {:?}" , old_op. layout. ty) ,
0 commit comments