diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-01-13 20:43:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-13 20:43:44 -0500 |
| commit | 81f742954a48af17a2a5c57cc708164245a48329 (patch) | |
| tree | 449971669fc0492de1fb39de55b5f7f8a3e0ef0a /compiler/rustc_middle/src/mir | |
| parent | 2ae9916816a448fcaab3b2da461de754eda0055a (diff) | |
| parent | 15c01eb22c8f7abbfe6d49dc5824c239547a0323 (diff) | |
| download | rust-81f742954a48af17a2a5c57cc708164245a48329.tar.gz rust-81f742954a48af17a2a5c57cc708164245a48329.zip | |
Rollup merge of #134498 - oli-obk:push-wmxynprsyxvr, r=compiler-errors
Fix cycle error only occurring with -Zdump-mir fixes #134205 During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building). Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
Diffstat (limited to 'compiler/rustc_middle/src/mir')
| -rw-r--r-- | compiler/rustc_middle/src/mir/pretty.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 47522f00bb1..24d2478f770 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1555,16 +1555,22 @@ pub fn write_allocations<'tcx>( write!(w, " (vtable: impl {dyn_ty} for {ty})")? } Some(GlobalAlloc::Static(did)) if !tcx.is_foreign_item(did) => { - match tcx.eval_static_initializer(did) { - Ok(alloc) => { - write!(w, " (static: {}, ", tcx.def_path_str(did))?; - write_allocation_track_relocs(w, alloc)?; + write!(w, " (static: {}", tcx.def_path_str(did))?; + if body.phase <= MirPhase::Runtime(RuntimePhase::PostCleanup) + && tcx.hir().body_const_context(body.source.def_id()).is_some() + { + // Statics may be cyclic and evaluating them too early + // in the MIR pipeline may cause cycle errors even though + // normal compilation is fine. + write!(w, ")")?; + } else { + match tcx.eval_static_initializer(did) { + Ok(alloc) => { + write!(w, ", ")?; + write_allocation_track_relocs(w, alloc)?; + } + Err(_) => write!(w, ", error during initializer evaluation)")?, } - Err(_) => write!( - w, - " (static: {}, error during initializer evaluation)", - tcx.def_path_str(did) - )?, } } Some(GlobalAlloc::Static(did)) => { |
