@@ -343,7 +343,7 @@ where
343343 ref_tracking. track ( ( ret, base_intern_mode) , || ( ) ) ;
344344
345345 while let Some ( ( ( mplace, mode) , _) ) = ref_tracking. todo . pop ( ) {
346- let interned = InternVisitor {
346+ let res = InternVisitor {
347347 ref_tracking : & mut ref_tracking,
348348 ecx,
349349 mode,
@@ -352,23 +352,24 @@ where
352352 inside_unsafe_cell : false ,
353353 }
354354 . visit_value ( mplace) ;
355- if let Err ( error) = interned {
356- // This can happen when e.g. the tag of an enum is not a valid discriminant. We do have
357- // to read enum discriminants in order to find references in enum variant fields.
358- if let err_ub ! ( ValidationFailure ( _) ) = error. kind {
359- let err = crate :: const_eval:: error_to_const_error ( & ecx, error) ;
360- match err. struct_error (
361- ecx. tcx ,
362- "it is undefined behavior to use this value" ,
363- |mut diag| {
364- diag. note ( crate :: const_eval:: note_on_undefined_behavior_error ( ) ) ;
365- diag. emit ( ) ;
366- } ,
367- ) {
368- ErrorHandled :: TooGeneric
369- | ErrorHandled :: Reported ( ErrorReported )
370- | ErrorHandled :: Linted => { }
371- }
355+ // We deliberately *ignore* interpreter errors here. When there is a problem, the remaining
356+ // references are "leftover"-interned, and later validation will show a proper error
357+ // and point at the right part of the value causing the problem.
358+ match res {
359+ Ok ( ( ) ) => { } ,
360+ Err ( error) => {
361+ ecx. tcx . sess . delay_span_bug (
362+ ecx. tcx . span ,
363+ "error during interning should later cause validation failure" ,
364+ ) ;
365+ // Some errors shouldn't come up because creating them causes
366+ // an allocation, which we should avoid. When that happens,
367+ // dedicated error variants should be introduced instead.
368+ assert ! (
369+ !error. kind. allocates( ) ,
370+ "interning encountered allocating error: {}" ,
371+ error
372+ ) ;
372373 }
373374 }
374375 }
0 commit comments