@@ -426,27 +426,27 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
426426 if let Some ( GlobalAlloc :: Static ( did) ) = alloc_kind {
427427 assert ! ( !self . ecx. tcx. is_thread_local_static( did) ) ;
428428 assert ! ( self . ecx. tcx. is_static( did) ) ;
429- // See const_eval::machine::MemoryExtra::can_access_statics for why
430- // this check is so important.
431- // This check is reachable when the const just referenced the static,
432- // but never read it (so we never entered `before_access_global`).
433- // We also need to do it here instead of going on to avoid running
434- // into the `before_access_global` check during validation.
435- if !self . may_ref_to_static {
429+ if self . may_ref_to_static {
430+ // We skip checking other statics. These statics must be sound by
431+ // themselves, and the only way to get broken statics here is by using
432+ // unsafe code.
433+ // The reasons we don't check other statics is twofold. For one, in all
434+ // sound cases, the static was already validated on its own, and second, we
435+ // trigger cycle errors if we try to compute the value of the other static
436+ // and that static refers back to us.
437+ // We might miss const-invalid data,
438+ // but things are still sound otherwise (in particular re: consts
439+ // referring to statics).
440+ return Ok ( ( ) ) ;
441+ } else {
442+ // See const_eval::machine::MemoryExtra::can_access_statics for why
443+ // this check is so important.
444+ // This check is reachable when the const just referenced the static,
445+ // but never read it (so we never entered `before_access_global`).
436446 throw_validation_failure ! ( self . path,
437447 { "a {} pointing to a static variable" , kind }
438448 ) ;
439449 }
440- // We skip checking other statics. These statics must be sound by themselves,
441- // and the only way to get broken statics here is by using unsafe code.
442- // The reasons we don't check other statics is twofold. For one, in all sound
443- // cases, the static was already validated on its own, and second, we trigger
444- // cycle errors if we try to compute the value of the other static and that
445- // static refers back to us.
446- // We might miss const-invalid data,
447- // but things are still sound otherwise (in particular re: consts
448- // referring to statics).
449- return Ok ( ( ) ) ;
450450 }
451451 }
452452 // Proceed recursively even for ZST, no reason to skip them!
0 commit comments