@@ -217,12 +217,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
217217        match  layout. variants  { 
218218            Variants :: Multiple  {  tag_field,  .. }  => { 
219219                if  tag_field == field { 
220-                     return  match  layout. ty . kind ( )  { 
220+                     return  match  layout. ty . strip_variant_type ( ) . 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-                         } , 
226222                        ty:: Generator ( ..)  => PathElem :: GeneratorTag , 
227223                        _ => bug ! ( "non-variant type {:?}" ,  layout. ty) , 
228224                    } ; 
@@ -232,7 +228,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
232228        } 
233229
234230        // 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 ( )  { 
236232            // generators and closures. 
237233            ty:: Closure ( def_id,  _)  | ty:: Generator ( def_id,  _,  _)  => { 
238234                let  mut  name = None ; 
@@ -276,20 +272,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
276272                } 
277273            } 
278274
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- 
293275            // other ADTs 
294276            ty:: Adt ( def,  _)  => PathElem :: Field ( def. non_enum_variant ( ) . fields [ field] . ident . name ) , 
295277
@@ -513,7 +495,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
513495    )  -> InterpResult < ' tcx ,  bool >  { 
514496        // Go over all the primitive types 
515497        let  ty = value. layout . ty ; 
516-         match  ty. kind ( )  { 
498+         match  ty. strip_variant_type ( ) . kind ( )  { 
517499            ty:: Bool  => { 
518500                let  value = self . read_scalar ( value) ?; 
519501                try_validation ! ( 
@@ -585,17 +567,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
585567                self . check_safe_pointer ( value,  "box" ) ?; 
586568                Ok ( true ) 
587569            } 
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-             } , 
599570            ty:: FnPtr ( _sig)  => { 
600571                let  value = try_validation ! ( 
601572                    self . ecx. read_immediate( value) , 
@@ -641,6 +612,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
641612            | ty:: Opaque ( ..) 
642613            | ty:: Projection ( ..) 
643614            | ty:: GeneratorWitness ( ..)  => bug ! ( "Encountered invalid type {:?}" ,  ty) , 
615+ 
616+             ty:: Variant ( ..)  => unreachable ! ( ) , 
644617        } 
645618    } 
646619
@@ -756,15 +729,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
756729        variant_id :  VariantIdx , 
757730        new_op :  & OpTy < ' tcx ,  M :: PointerTag > , 
758731    )  -> 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 ( )  { 
760734            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-             } , 
765735            // Generators also have variants 
766736            ty:: Generator ( ..)  => PathElem :: GeneratorState ( variant_id) , 
767-             _ => bug ! ( "Unexpected type with variant: {:?}" ,  old_op . layout . ty) , 
737+             _ => bug ! ( "Unexpected type with variant: {:?}" ,  ty) , 
768738        } ; 
769739        self . with_elem ( name,  move  |this| this. visit_value ( new_op) ) 
770740    } 
0 commit comments