rust-lang/rust · critical

provided `DefIndex` must refer to a module-like item

Error message

provided `DefIndex` must refer to a module-like item

What it means

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.

Source

Thrown at compiler/rustc_metadata/src/rmeta/decoder.rs:1341

    ///
    /// # Panics
    ///
    /// May panic if the provided `id` does not refer to a module.
    fn get_module_children(&self, tcx: TyCtxt<'_>, id: DefIndex) -> impl Iterator<Item = ModChild> {
        gen move {
            if let Some(data) = &self.root.proc_macro_data {
                // If we are loading as a proc macro, we want to return
                // the view of this crate as a proc macro crate.
                if id == CRATE_DEF_INDEX {
                    for (child_index, _) in data.macros.decode((self, tcx)) {
                        yield self.get_mod_child(tcx, child_index);
                    }
                }
            } else {
                // Iterate over all children.
                let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
                let non_reexports =
                    non_reexports.expect("provided `DefIndex` must refer to a module-like item");
                for child_index in non_reexports.decode((self, tcx)) {
                    yield self.get_mod_child(tcx, child_index);
                }

                let reexports = self.root.tables.module_children_reexports.get(self, id);
                if !reexports.is_default() {
                    for reexport in reexports.decode((self, tcx)) {
                        yield reexport;
                    }
                }
            }
        }
    }

    fn get_ambig_module_children(
        &self,
        tcx: TyCtxt<'_>,
        id: DefIndex,

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. `cargo clean` to drop stale resolver caches and re-encode module structure.
  2. Audit recent moves/renames of modules and `pub use` re-exports that may have left a stale `DefIndex` pointing at a non-module.
  3. Force the resolver version to match (`-Z resolver=...` only on nightly; otherwise align toolchain versions).
  4. If it reproduces cleanly, file an ICE with the resolver query that produced the bad `DefIndex`.
Defensive patterns

Strategy: retry

Validate before calling

# Drop stale resolver/module caches before building
cargo clean
cargo build

Try / catch

cargo build || { cargo clean && cargo build; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/810f8e406d1a3011. Report an issue: GitHub.