{"record":{"id":"2af52ec5c8db8e8a","repo":"rust-lang/rust","slug":"missing-polonius-context-with-zpolonius-next","errorCode":null,"errorMessage":"missing polonius context with `-Zpolonius=next`","messagePattern":"missing polonius context with `-Zpolonius=next`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_borrowck/src/polonius/dump.rs","lineNumber":35,"sourceCode":"\n/// `-Zdump-mir=polonius` dumps MIR annotated with NLL and polonius specific information.\npub(crate) fn dump_polonius_mir<'tcx>(\n    infcx: &BorrowckInferCtxt<'tcx>,\n    body: &Body<'tcx>,\n    regioncx: &RegionInferenceContext<'tcx>,\n    closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,\n    borrow_set: &BorrowSet<'tcx>,\n    polonius_context: Option<&PoloniusContext>,\n) {\n    let tcx = infcx.tcx;\n    if !tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {\n        return;\n    }\n\n    let Some(dumper) = MirDumper::new(tcx, \"polonius\", body) else { return };\n\n    let polonius_context =\n        polonius_context.expect(\"missing polonius context with `-Zpolonius=next`\");\n\n    // If we have a polonius graph to dump along the rest of the MIR and NLL info, we extract its\n    // constraints here.\n    let mut collector = LocalizedOutlivesConstraintCollector { constraints: Vec::new() };\n    if let Some(graph) = &polonius_context.graph {\n        graph.traverse(\n            body,\n            regioncx.liveness_constraints(),\n            &polonius_context.live_region_variances,\n            regioncx.universal_regions(),\n            borrow_set,\n            &mut collector,\n        );\n    }\n\n    let extra_data = &|pass_where, out: &mut dyn io::Write| {\n        emit_polonius_mir(\n            tcx,","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_borrowck/src/polonius/dump.rs#L17-L53","documentation":"This panic occurs in the Polonius MIR dump path (`-Zdump-mir=polonius`). After confirming that `-Zpolonius=next` is enabled, the code unwraps the `Option<&PoloniusContext>` via `.expect(...)`. The PoloniusContext should always be constructed when `-Zpolonius=next` is active. If it is `None` — meaning the borrow checker did not build a polonius context for this body despite the flag being on — the compiler panics.","triggerScenarios":"Compiling with `-Zpolonius=next` combined with `-Zdump-mir=polonius` on a MIR body where the polonius context was not constructed (e.g., a body that was skipped by polonius, a body where polonius was disabled mid-pipeline, or a configuration mismatch between the dump request and the analysis that ran).","commonSituations":"Nightly Rust developers experimenting with the next-generation Polonius borrow checker. Happens when the polonius pipeline is partially configured — for example, using `-Zpolonius=next` on a crate that has bodies excluded from polonius analysis, or when a tooling change decoupled the dump from the analysis pass.","solutions":["Ensure both flags are consistently set: `-Zpolonius=next` must be the active analysis mode for the dump to have data.","Remove `-Zdump-mir=polonius` if you don't need the polonius-specific MIR annotation; the panic only fires in the dump path.","Update to the latest nightly — the Polonius integration is under active development and flag wiring changes frequently.","File a bug if the flags are consistent and you still hit it; the dump function at `dump.rs:34-35` should guard against `None` more gracefully."],"exampleFix":"# before (may trigger ICE)\nRUSTFLAGS='-Zpolonius=next -Zdump-mir=polonius' cargo build\n\n# after (use a single consistent flag set; drop the dump if not needed)\nRUSTFLAGS='-Zpolonius=next' cargo build","handlingStrategy":"validation","validationCode":"// Validate flag consistency before compiling\n// In a build script or CI config:\n// Ensure -Zpolonius=next is set if -Zdump-mir=polonius is used\n// Shell check:\n// if echo \"$RUSTFLAGS\" | grep -q 'dump-mir=polonius'; then\n//   echo \"$RUSTFLAGS\" | grep -q 'polonius=next' || \\\n//     export RUSTFLAGS=\"$RUSTFLAGS -Zpolonius=next\"\n// fi","typeGuard":null,"tryCatchPattern":"// In a custom rustc driver, validate polonius context before dumping:\nif tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {\n    if let Some(_ctx) = polonius_context {\n        dump_polonius_mir(/* ... */);\n    } else {\n        tcx.sess.warn(\"polonius=next enabled but no context; skipping dump\");\n    }\n}","preventionTips":["Always pair -Zdump-mir=polonius with -Zpolonius=next.","Don't request polonius dumps on crates that skip polonius analysis.","Keep polonius-related flags version-pinned to your nightly.","Test flag combinations in a scratch crate before applying to your project."],"tags":["rustc","borrowck","polonius","ice","dump-mir","nightly","compiler-internal"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}