rust-lang/rust · critical

no encoded attributes for a structure or variant

Error message

no encoded attributes for a structure or variant

What it means

Fires immediately after 285, in the same `get_item_attrs` branch (decoder.rs:1458). Once the constructor's parent struct/variant is found, the decoder expects that parent to have an `attributes` table entry; `.expect("no encoded attributes for a structure or variant")` panics when it does not. The invariant is that every struct/variant carries an (possibly empty) encoded attribute list.

Source

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

    ) -> 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,
        tcx: TyCtxt<'tcx>,
        id: DefIndex,
    ) -> &'tcx [DefId] {
        tcx.arena.alloc_from_iter(
            self.root

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. `cargo clean` and rebuild to re-encode the attribute table for the current schema.
  2. Align all crates on one rustc version.
  3. Rebuild the specific dependency that owns the struct/variant.
  4. Clean-build ICE -> report; the encoder omitted the attribute slot for a struct/variant.
Defensive patterns

Strategy: retry

Validate before calling

cargo clean && cargo build  # re-encode the attribute table consistently

Try / catch

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

Prevention

When it happens

Trigger: The parent struct/variant of a constructor was encoded without an `attributes` slot; schema drift where attributes moved tables; metadata corruption.

Common situations: Toolchain version mismatch between encoder and decoder; incremental cache reuse after attribute-table layout changes; a struct/variant with no attributes encoded by a path that skipped the (empty) entry.

Related errors


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