{"id":"1de1baa7faa98435","repo":"rust-lang/rust","slug":"try-mark-previous-green-forcing-failed-to-set","errorCode":null,"errorMessage":"try_mark_previous_green() - forcing failed to set a color","messagePattern":"try_mark_previous_green\\(\\) - forcing failed to set a color","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_middle/src/dep_graph/graph.rs","lineNumber":997,"sourceCode":"                continue;\n            }\n\n            // We failed to mark it green, so we try to force the query.\n            if !tcx.try_force_from_dep_node(*parent_dep_node, parent_dep_node_index, &frame) {\n                return None;\n            }\n\n            match self.colors.get(parent_dep_node_index) {\n                DepNodeColor::Green(parent_index) => {\n                    edges.push(parent_index);\n                    continue;\n                }\n                DepNodeColor::Red => return None,\n                DepNodeColor::Unknown => {}\n            }\n\n            if tcx.dcx().has_errors_or_delayed_bugs().is_none() {\n                panic!(\"try_mark_previous_green() - forcing failed to set a color\");\n            }\n\n            // If the query we just forced has resulted in some kind of compilation error, we\n            // cannot rely on the dep-node color having been properly updated. This means that the\n            // query system has reached an invalid state. We let the compiler continue (by\n            // returning `None`) so it can emit error messages and wind down, but rely on the fact\n            // that this invalid state will not be persisted to the incremental compilation cache\n            // because of compilation errors being present.\n            return None;\n        }\n\n        // If we got here without hitting a `return` that means that all\n        // dependencies of this DepNode could be marked as green. Therefore we\n        // can also mark this DepNode as green.\n\n        // There may be multiple threads trying to mark the same dep node green concurrently.\n\n        // We allocating an entry for the node in the current dependency graph and","sourceCodeStart":979,"sourceCodeEnd":1015,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_middle/src/dep_graph/graph.rs#L979-L1015","documentation":"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.)","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight: if previous-green forcing cannot make progress, the\n// cache is internally inconsistent; detect and force a clean rebuild.\nfn previous_green_consistent(cache: &DepGraphCache) -> bool {\n    cache.signature_matches_compiler() && cache.has_no_dangling_nodes()\n}","typeGuard":"fn cache_is_self_consistent(cache: &DepGraphCache) -> bool {\n    cache.signature_matches_compiler() && cache.has_no_dangling_nodes()\n}","tryCatchPattern":"// Best handled by invalidating the offending cache and retrying once.\nlet outcome = std::panic::catch_unwind(|| graph.try_mark_previous_green(&node));\nmatch outcome {\n    Ok(true) => mark_green(node),\n    _ => {\n        incremental_dir::clear();\n        // single retry with a cold cache; do not loop.\n        rebuild_from_scratch();\n    }\n}","preventionTips":["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."],"tags":["rustc","dep-graph","incremental","internal"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}