{"id":"96bbab6c03bb6950","repo":"rust-lang/rust","slug":"invalid-depkind-u","errorCode":null,"errorMessage":"Invalid DepKind {u}","messagePattern":"Invalid DepKind (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_middle/src/dep_graph/dep_node.rs","lineNumber":70,"sourceCode":"\nuse rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};\nuse rustc_data_structures::stable_hash::{StableHasher, StableOrd};\nuse rustc_hir::def_id::DefId;\nuse rustc_hir::definitions::DefPathHash;\nuse rustc_macros::{Decodable, Encodable, StableHash};\nuse rustc_span::Symbol;\n\nuse super::{DepNodeIndex, KeyFingerprintStyle, SerializedDepNodeIndex};\nuse crate::dep_graph::DepNodeKey;\nuse crate::mono::MonoItem;\nuse crate::ty::{TyCtxt, tls};\n\n// `enum DepKind` is generated by `define_dep_nodes!` below.\nimpl DepKind {\n    #[inline]\n    pub(crate) fn from_u16(u: u16) -> Self {\n        if u > Self::MAX {\n            panic!(\"Invalid DepKind {u}\");\n        }\n        // SAFETY: See comment on DEP_KIND_NUM_VARIANTS\n        unsafe { std::mem::transmute(u) }\n    }\n\n    #[inline]\n    pub(crate) const fn as_u16(&self) -> u16 {\n        *self as u16\n    }\n\n    #[inline]\n    pub const fn as_usize(&self) -> usize {\n        *self as usize\n    }\n\n    /// This is the highest value a `DepKind` can have. It's used during encoding to\n    /// pack information into the unused bits.\n    pub(crate) const MAX: u16 = DEP_KIND_NUM_VARIANTS - 1;","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_middle/src/dep_graph/dep_node.rs#L52-L88","documentation":"In `DepKind::from_u16` (dep_node.rs:70), the compiler reconstructs a DepKind variant from a serialized u16. DepKind is generated by `define_dep_nodes!` with a fixed `DEP_KIND_NUM_VARIANTS`; any value above `MAX` (= variants-1) is rejected. So this fires when persisted dep-graph metadata references a DepKind index the running compiler doesn't know.","triggerScenarios":"Deserializing a previous-session dep graph whose DepKind enum had more variants than the current compiler — i.e. incremental metadata written by a newer/different rustc, or corrupted `incremental/*.rlib` dep-graph section. Also reachable via an internal bug that writes an uninitialized kind.","commonSituations":"Switching toolchains (nightly to older stable, or between nightlies) without clearing `target/incremental`; copying a target dir across machines/toolchains; a partial/corrupted incremental cache from a killed build.","solutions":["Remove the incremental cache (`rm -rf target/<profile>/incremental`) or `cargo clean`, then rebuild.","Ensure the same rustc toolchain is used across the whole build (`rust-toolchain.toml`, CI cache keys scoped by toolchain).","If it recurs on a clean build, file a rustc issue — the encoder is writing a kind index the decoder rejects."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// DepKind is a small closed enum serialized as an integer; verify\n// before constructing a DepNode from external input.\nfn depkind_from_u(val: u32) -> Option<DepKind> {\n    DepKind::from_u32(val)\n}","typeGuard":"fn is_valid_dep_kind_u(val: u32) -> bool {\n    val < DepKind::VARIANTS as u32\n}","tryCatchPattern":null,"preventionTips":["Never construct DepNode / serialize DepKind from raw integers you did not read back from the same rustc build.","If you cache dep-graph nodes, version-stamp the cache with the exact rustc commit; DepKind numbering is unstable.","In fuzz targets that feed bytes into dep-graph decoding, gate on the variant count rather than relying on the assertion."],"tags":["rustc","dep-graph","incremental","version-mismatch"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}