{"record":{"id":"810f8e406d1a3011","repo":"rust-lang/rust","slug":"provided-defindex-must-refer-to-a-module-like-it","errorCode":null,"errorMessage":"provided `DefIndex` must refer to a module-like item","messagePattern":"provided `DefIndex` must refer to a module-like item","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_metadata/src/rmeta/decoder.rs","lineNumber":1341,"sourceCode":"    ///\n    /// # Panics\n    ///\n    /// May panic if the provided `id` does not refer to a module.\n    fn get_module_children(&self, tcx: TyCtxt<'_>, id: DefIndex) -> impl Iterator<Item = ModChild> {\n        gen move {\n            if let Some(data) = &self.root.proc_macro_data {\n                // If we are loading as a proc macro, we want to return\n                // the view of this crate as a proc macro crate.\n                if id == CRATE_DEF_INDEX {\n                    for (child_index, _) in data.macros.decode((self, tcx)) {\n                        yield self.get_mod_child(tcx, child_index);\n                    }\n                }\n            } else {\n                // Iterate over all children.\n                let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);\n                let non_reexports =\n                    non_reexports.expect(\"provided `DefIndex` must refer to a module-like item\");\n                for child_index in non_reexports.decode((self, tcx)) {\n                    yield self.get_mod_child(tcx, child_index);\n                }\n\n                let reexports = self.root.tables.module_children_reexports.get(self, id);\n                if !reexports.is_default() {\n                    for reexport in reexports.decode((self, tcx)) {\n                        yield reexport;\n                    }\n                }\n            }\n        }\n    }\n\n    fn get_ambig_module_children(\n        &self,\n        tcx: TyCtxt<'_>,\n        id: DefIndex,","sourceCodeStart":1323,"sourceCodeEnd":1359,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_metadata/src/rmeta/decoder.rs#L1323-L1359","documentation":"Fires in `get_module_children` (decoder.rs:1341). When asked for the children of a definition, the decoder looks up `module_children_non_reexports` and `.expect()`s a value, because only module-like items (modules, the crate root, enum for variants) are supposed to encode child lists. A `None` here means a `DefIndex` that is not module-like was passed in, or the entry was never written.","triggerScenarios":"Calling module-children resolution on a `DefIndex` that resolves to a non-module item (fn, type alias, const) due to a stale name-resolver cache; or reading metadata where a reexport/pub-use chain points at an item the encoder treated as a non-module.","commonSituations":"Incremental cache reuse after renaming/moving modules so a `DefIndex` no longer points at a module; edition or resolver-version mismatch between crates; heavy `pub use` re-export graphs decoded by a different resolver revision.","solutions":["`cargo clean` to drop stale resolver caches and re-encode module structure.","Audit recent moves/renames of modules and `pub use` re-exports that may have left a stale `DefIndex` pointing at a non-module.","Force the resolver version to match (`-Z resolver=...` only on nightly; otherwise align toolchain versions).","If it reproduces cleanly, file an ICE with the resolver query that produced the bad `DefIndex`."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Drop stale resolver/module caches before building\ncargo clean\ncargo build","typeGuard":null,"tryCatchPattern":"cargo build || { cargo clean && cargo build; }","preventionTips":["`cargo clean` after moving or renaming modules so `DefIndex` numbering is regenerated.","Avoid reusing `target/` across resolver-version or edition changes.","Pin the resolver edition (`resolver = \"2\"` in Cargo.toml) consistently."],"tags":["metadata","rmeta","decoder","module-resolution","ice"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}