{"record":{"id":"9e1b5e593876028b","repo":"rust-lang/rust","slug":"variants-are-not-encoded-for-an-enum","errorCode":null,"errorMessage":"variants are not encoded for an enum","messagePattern":"variants are not encoded for an enum","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_metadata/src/rmeta/decoder.rs","lineNumber":1177,"sourceCode":"\n    fn get_adt_def<'tcx>(&self, tcx: TyCtxt<'tcx>, item_id: DefIndex) -> ty::AdtDef<'tcx> {\n        let kind = self.def_kind(item_id);\n        let did = self.local_def_id(item_id);\n\n        let adt_kind = match kind {\n            DefKind::Enum => ty::AdtKind::Enum,\n            DefKind::Struct => ty::AdtKind::Struct,\n            DefKind::Union => ty::AdtKind::Union,\n            _ => bug!(\"get_adt_def called on a non-ADT {:?}\", did),\n        };\n        let repr = self.root.tables.repr_options.get(self, item_id).unwrap().decode((self, tcx));\n\n        let mut variants: Vec<_> = if let ty::AdtKind::Enum = adt_kind {\n            self.root\n                .tables\n                .module_children_non_reexports\n                .get(self, item_id)\n                .expect(\"variants are not encoded for an enum\")\n                .decode((self, tcx))\n                .filter_map(|index| {\n                    let kind = self.def_kind(index);\n                    match kind {\n                        DefKind::Ctor(..) => None,\n                        _ => Some(self.get_variant(tcx, kind, index, did)),\n                    }\n                })\n                .collect()\n        } else {\n            std::iter::once(self.get_variant(tcx, kind, item_id, did)).collect()\n        };\n\n        variants.sort_by_key(|(idx, _)| *idx);\n\n        tcx.mk_adt_def(\n            did,\n            adt_kind,","sourceCodeStart":1159,"sourceCodeEnd":1195,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_metadata/src/rmeta/decoder.rs#L1159-L1195","documentation":"Fires in `get_adt_def` (decoder.rs:1177) when decoding an enum: the decoder expects `module_children_non_reexports` to hold the enum's variants, and `.expect(\"variants are not encoded for an enum\")` panics when that table slot is empty/default. For enums the variants are encoded as the enum's module children, so a missing entry means the metadata for that enum was written without its variant list (or is being read with a mismatched schema).","triggerScenarios":"Querying the definition of an enum whose rmeta was stripped of variant info (e.g. a crate compiled without the variant-encoding path, or a fieldless enum whose constructors were encoded differently than the reader expects); schema drift between encoding and decoding rustc versions for enum layout.","commonSituations":"Mixing artifacts from two rustc versions where enum-encoding changed; a dependency rebuilt mid-upgrade; nightly-only enum features (e.g. `#[repr(...)]` changes) read by a decoder that predates them.","solutions":["`cargo clean` and rebuild so the enum's metadata is re-encoded by the current compiler.","Confirm the dependency and the root crate use the same rustc (`rustc --version --verbose`); run `rustup update` to a consistent toolchain.","If the enum comes from a prebuilt sysroot or vendored rlib, rebuild that artifact from source with the active compiler.","On a clean, single-toolchain build that still panics, file an ICE: the encoder omitted variants for a valid enum."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Ensure enum metadata is regenerated by the current compiler\ncargo clean\ncargo build","typeGuard":null,"tryCatchPattern":"cargo build || { cargo clean && cargo build; }","preventionTips":["Run `cargo clean` after upgrading rustc or switching nightly versions.","Keep the dependency graph on a single toolchain via `rust-toolchain.toml`.","Rebuild dependencies from source rather than reusing vendored rlibs built by another compiler."],"tags":["metadata","rmeta","decoder","enum","ice"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}