@@ -1353,6 +1353,16 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
13531353 interp_ok ( ( ) )
13541354 }
13551355
1356+ #[ inline]
1357+ fn visit_variantless ( & mut self , val : & PlaceTy < ' tcx , M :: Provenance > ) -> InterpResult < ' tcx > {
1358+ let ty = val. layout . ty ;
1359+ assert ! ( ty. is_enum( ) , "encountered non-enum variantless type `{ty}`" ) ;
1360+ throw_validation_failure ! (
1361+ self . path,
1362+ format!( "encountered a value of zero-variant enum `{ty}`" )
1363+ ) ;
1364+ }
1365+
13561366 #[ inline]
13571367 fn visit_value ( & mut self , val : & PlaceTy < ' tcx , M :: Provenance > ) -> InterpResult < ' tcx > {
13581368 trace ! ( "visit_value: {:?}, {:?}" , * val, val. layout) ;
@@ -1557,23 +1567,14 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
15571567 }
15581568 }
15591569
1560- // *After* all of this, check further information stored in the layout.
1561- // On leaf types like `!` or empty enums, this will raise the error.
1562- // This means that for types wrapping such a type, we won't ever get here, but it's
1563- // just the simplest way to check for this case.
1564- //
1565- // FIXME: We could avoid some redundant checks here. For newtypes wrapping
1566- // scalars, we do the same check on every "level" (e.g., first we check
1567- // the fields of MyNewtype, and then we check MyNewType again).
1568- if val. layout . is_uninhabited ( ) {
1569- let ty = val. layout . ty ;
1570- throw_validation_failure ! (
1571- self . path,
1572- format!( "encountered a value of uninhabited type `{ty}`" )
1573- ) ;
1574- }
1570+ // Assert that we checked everything there is to check about this type.
1571+ assert ! (
1572+ !val. layout. is_uninhabited( ) ,
1573+ "a value of type `{}` passed validation but that type is uninhabited" ,
1574+ val. layout. ty
1575+ ) ;
15751576 if cfg ! ( debug_assertions) {
1576- // Check that we don't miss any new changes to layout computation in our checks above .
1577+ // Only run expensive checks when debug assertions are enabled .
15771578 match val. layout . backend_repr {
15781579 BackendRepr :: Scalar ( scalar_layout) => {
15791580 if !scalar_layout. is_uninit_valid ( ) {
0 commit comments