rust-lang/rust · critical
try_mark_previous_green() - forcing failed to set a color
Error message
try_mark_previous_green() - forcing failed to set a color
What it means
In incremental compilation's red-green marking (`try_mark_previous_green`, graph.rs:997), the compiler forces a parent dep node expecting it to come out Green or Red. If after forcing the color is still `Unknown` AND there are no compilation errors to account for the missing color, the invariant is broken and rustc panics. (When errors are present it tolerates the unknown color and returns None.)
Source
Thrown at compiler/rustc_middle/src/dep_graph/graph.rs:997
continue;
}
// We failed to mark it green, so we try to force the query.
if !tcx.try_force_from_dep_node(*parent_dep_node, parent_dep_node_index, &frame) {
return None;
}
match self.colors.get(parent_dep_node_index) {
DepNodeColor::Green(parent_index) => {
edges.push(parent_index);
continue;
}
DepNodeColor::Red => return None,
DepNodeColor::Unknown => {}
}
if tcx.dcx().has_errors_or_delayed_bugs().is_none() {
panic!("try_mark_previous_green() - forcing failed to set a color");
}
// If the query we just forced has resulted in some kind of compilation error, we
// cannot rely on the dep-node color having been properly updated. This means that the
// query system has reached an invalid state. We let the compiler continue (by
// returning `None`) so it can emit error messages and wind down, but rely on the fact
// that this invalid state will not be persisted to the incremental compilation cache
// because of compilation errors being present.
return None;
}
// If we got here without hitting a `return` that means that all
// dependencies of this DepNode could be marked as green. Therefore we
// can also mark this DepNode as green.
// There may be multiple threads trying to mark the same dep node green concurrently.
// We allocating an entry for the node in the current dependency graph andView on GitHub (pinned to 22057b88b0)
Solutions
- Clear the incremental cache (`rm -rf target/<profile>/incremental`) or `cargo clean` and rebuild.
- Disable incremental compilation for the affected project (`CARGO_INCREMENTAL=0`) as a workaround.
- On a reproducible clean-build case, file a rustc ICE issue with the full backtrace and the failing dep node.
Defensive patterns
Strategy: retry
Validate before calling
// Pre-flight: if previous-green forcing cannot make progress, the
// cache is internally inconsistent; detect and force a clean rebuild.
fn previous_green_consistent(cache: &DepGraphCache) -> bool {
cache.signature_matches_compiler() && cache.has_no_dangling_nodes()
} Type guard
fn cache_is_self_consistent(cache: &DepGraphCache) -> bool {
cache.signature_matches_compiler() && cache.has_no_dangling_nodes()
} Try / catch
// Best handled by invalidating the offending cache and retrying once.
let outcome = std::panic::catch_unwind(|| graph.try_mark_previous_green(&node));
match outcome {
Ok(true) => mark_green(node),
_ => {
incremental_dir::clear();
// single retry with a cold cache; do not loop.
rebuild_from_scratch();
}
} Prevention
- Treat this as an incremental-compilation cache inconsistency, not a source bug: clear target/<profile>/incremental and rebuild.
- Pin the rustc version per project (rust-toolchain.toml); this fires most often when an incremental cache from one build is consumed by another.
- Disable incremental compilation (CARGO_INCREMENTAL=0) on CI or when switching toolchains frequently.
- Do not manually copy or share the incremental cache directory across machines or checkouts.
When it happens
Trigger: The forcing machinery failed to color a node without registering any error — an internal bug in the query/force path, corruption of the previous dep graph, or an ICE-suppressed path that left the node uncolored. Reachable whenever incremental compilation is enabled and a previous dep graph is being replayed.
Common situations: Corrupted or stale `incremental` directory, toolchain switch leaving an incompatible previous graph, or a genuine rustc incremental-compilation bug. Often intermittent and tied to a specific incremental session.
Related errors
- Cannot summarize when dependencies are not recorded.
- Invalid DepKind {u}
- local id should be u32, found {local_id:?}
- forbidden edge {:?} -> {:?} created
- Query label {label} does not exist
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/1de1baa7faa98435.json.
Report an issue: GitHub.