rust-lang/rust · critical

no parent for a constructor

Error message

no parent for a constructor

What it means

Fires inside `get_item_attrs` (decoder.rs:1453). When a constructor's attributes are requested, the decoder reads the constructor's `def_key` and expects it to carry a `parent` pointing at the owning struct/variant; `def_key.parent.expect("no parent for a constructor")` panics when that parent is `None`. A constructor (tuple-struct/enum-variant ctor) without a parent is structurally invalid metadata.

Source

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

    fn get_item_attrs(
        &self,
        tcx: TyCtxt<'_>,
        id: DefIndex,
    ) -> impl Iterator<Item = hir::Attribute> {
        self.root
            .tables
            .attributes
            .get(self, id)
            .unwrap_or_else(|| {
                let def_key = self.def_key(id);
                match def_key.disambiguated_data.data {
                    DefPathData::Ctor => {
                        // Structure and variant constructors don't have any attributes encoded for them,
                        // but we assume that someone passing a constructor ID actually wants to look at
                        // the attributes on the corresponding struct or variant.
                        assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
                        let parent_id = def_key.parent.expect("no parent for a constructor");
                        self.root
                            .tables
                            .attributes
                            .get(self, parent_id)
                            .expect("no encoded attributes for a structure or variant")
                    }
                    DefPathData::SyntheticCoroutineBody => {
                        // SyntheticCoroutineBodies cannot have attributes
                        LazyArray::default()
                    }
                    _ => panic!("Definition key {def_key:?} of type `{:?}` did not have any attributes stored", def_key.disambiguated_data.data)
                }
            })
            .decode((self, tcx))
    }

    fn get_inherent_implementations_for_type<'tcx>(
        &self,

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. `cargo clean` to discard the truncated/corrupt artifact and rebuild.
  2. Re-run the build (an interrupted previous build may have left a partial rmeta).
  3. Verify disk is not full and the build was not killed mid-link.
  4. If it reproduces on a clean build, file an ICE: a constructor was encoded without its parent def_key.
Defensive patterns

Strategy: retry

Validate before calling

# A constructor without a parent implies a truncated rmeta; rebuild clean
# and check the build was not interrupted / disk not full.
df -h .                # ensure disk has space
cargo clean && cargo build

Try / catch

cargo build || { df -h . && cargo clean && cargo build; }

Prevention

When it happens

Trigger: Looking up attributes on a constructor `DefIndex` whose `def_key` was serialized without a parent field (encoder bug or truncated metadata); reading a constructor from a partially-written/corrupted rmeta blob.

Common situations: Interrupted build leaving a half-written `.rlib`; rmeta produced by a buggy nightly; cross-version metadata reuse.

Related errors


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