{"id":"425140e2b643a440","repo":"rust-lang/rust","slug":"error-trying-to-record-dependency-on-depnode-dep","errorCode":null,"errorMessage":"Error: trying to record dependency on DepNode {dep_node} in a context that does not allow it (e.g. during query deserialization). The most common case of recording a dependency on a DepNode `foo` is when the corresponding query `foo` is invoked. Invoking queries is not allowed as part of loading something from the incremental on-disk cache. See <https://github.com/rust-lang/rust/pull/91919>.","messagePattern":"Error: trying to record dependency on DepNode (.+?) in a context that does not allow it \\(e\\.g\\. during query deserialization\\)\\. The most common case of recording a dependency on a DepNode `foo` is when the corresponding query `foo` is invoked\\. Invoking queries is not allowed as part of loading something from the incremental on-disk cache\\. See <https://github\\.com/rust-lang/rust/pull/91919>\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_middle/src/dep_graph/graph.rs","lineNumber":1446,"sourceCode":"    // corresponds to `dep_node_index`, but that's OK since we are about\n    // to ICE anyway.\n    let mut dep_node = None;\n\n    // First try to find the dep node among those that already existed in the\n    // previous session and has been marked green\n    for prev_index in data.colors.values.indices() {\n        if data.colors.current(prev_index) == Some(dep_node_index) {\n            dep_node = Some(*data.previous.index_to_node(prev_index));\n            break;\n        }\n    }\n\n    let dep_node = dep_node.map_or_else(\n        || format!(\"with index {:?}\", dep_node_index),\n        |dep_node| format!(\"`{:?}`\", dep_node),\n    );\n\n    panic!(\n        \"Error: trying to record dependency on DepNode {dep_node} in a \\\n         context that does not allow it (e.g. during query deserialization). \\\n         The most common case of recording a dependency on a DepNode `foo` is \\\n         when the corresponding query `foo` is invoked. Invoking queries is not \\\n         allowed as part of loading something from the incremental on-disk cache. \\\n         See <https://github.com/rust-lang/rust/pull/91919>.\"\n    )\n}\n\nimpl<'tcx> TyCtxt<'tcx> {\n    /// Return whether this kind always require evaluation.\n    #[inline(always)]\n    fn is_eval_always(self, kind: DepKind) -> bool {\n        self.dep_kind_vtable(kind).is_eval_always\n    }\n}\n","sourceCodeStart":1428,"sourceCodeEnd":1463,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_middle/src/dep_graph/graph.rs#L1428-L1463","documentation":"Internal compiler error (ICE) from panic_on_forbidden_read (compiler/rustc_middle/src/dep_graph/graph.rs:1446), reached via DepGraph::read_index when the current task's dependency-tracking ref is TaskDepsRef::Forbid. That state is used while deserializing/loading values from the incremental on-disk cache, where recording a new query dependency would create a cycle or a non-reproducible graph. The message names the offending DepNode and points at PR #91919 which introduced the forbid context.","triggerScenarios":"A query is invoked (transitively) from inside the on-disk cache loading path, e.g. decoding a SerializedDepGraph entry, decoding a query result, or running an eval_always query while TaskDepsRef is Forbid. Concretely, read_index(dep_node_index) is called while the thread-local TaskDepsRef equals Forbid.","commonSituations":"Compiler bugs where a deserializer/decoder calls into tcx.<query>(...) instead of reading the cached value; custom rustc query providers that invoke other queries during deserialization; regressions after refactors that move query calls into the decode path.","solutions":["Report the ICE to the rustc team with the DepNode name and a reproducer; this is a compiler-internal invariant violation, not user code.","If you are writing a custom query provider, ensure it does not call other tcx queries during decode/deserialize paths — read from the cached DepNode instead.","Disable incremental compilation (-C incremental=no) or wipe the incremental cache directory to rule out cache corruption causing a different code path.","Bisect across nightly rustc versions to find the commit that introduced the query call inside the forbidden context (PR #91919 is the reference point)."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// No pre-call validation is possible: the error fires deep inside\n// query deserialization from the incremental cache. Mitigate by\n// disabling incremental compilation for the affected crate.\nfn build_cmd_no_incremental() -> std::process::Command {\n    let mut cmd = std::process::Command::new(\"cargo\");\n    cmd.args([\"build\", \"--release\", \"-C\", \"incremental=no\"]);\n    cmd.env_remove(\"CARGO_INCREMENTAL\");\n    cmd\n}","typeGuard":null,"tryCatchPattern":"// For tool authors driving rustc as a library via rustc_interface::run_compiler,\n// isolate the compiler callback in catch_unwind so an ICE does not tear down\n// the host process.\nuse std::panic::{catch_unwind, AssertUnwindSafe};\n\nlet result = catch_unwind(AssertUnwindSafe(|| {\n    rustc_interface::run_compiler(config, |tcx| {\n        // ... perform queries that may trigger incremental cache loading ...\n    })\n}));\nmatch result {\n    Ok(value) => /* use value */ { let _ = value; }\n    Err(payload) => {\n        eprintln!(\"rustc ICE during incremental cache load; falling back to clean build\");\n        // Delete target/<profile>/incremental and retry once without -Zincremental\n    }\n}","preventionTips":["Disable incremental compilation (CARGO_INCREMENTAL=0 or -C incremental=no) in CI and release builds","Delete the target/<profile>/incremental directory when switching toolchains or updating macros","Report the ICE with the rustc version and the panic backtrace to the rust-lang/rust issue tracker","Avoid mixing nightly and stable toolchains on the same target directory"],"tags":["rustc","incremental-compilation","ice","dep-graph","query-system"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}