rust-lang/rust · critical

`Sized`/`MetaSized` does not have an associated type: {:?}

Error message

`Sized`/`MetaSized` does not have an associated type: {:?}

What it means

A `panic!` in `consider_builtin_sizedness_candidates`. The built-in `Sized` and `MetaSized` traits have no associated types, so a `NormalizesTo` goal against them is meaningless; reaching this candidate means dispatch sent an associated-type projection goal to the sizedness candidate assembly. It is a solver dispatch invariant, not user-facing.

Source

Thrown at compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs:501

        _goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        ecx.cx().delay_bug("associated types not allowed on auto traits");
        Err(NoSolution.into())
    }

    fn consider_trait_alias_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        panic!("trait aliases do not have associated types: {:?}", goal);
    }

    fn consider_builtin_sizedness_candidates(
        _ecx: &mut EvalCtxt<'_, D>,
        goal: Goal<I, Self>,
        _sizedness: SizedTraitKind,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        panic!("`Sized`/`MetaSized` does not have an associated type: {:?}", goal);
    }

    fn consider_builtin_copy_clone_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        panic!("`Copy`/`Clone` does not have an associated type: {:?}", goal);
    }

    fn consider_builtin_fn_ptr_trait_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        panic!("`FnPtr` does not have an associated type: {:?}", goal);
    }

    fn consider_builtin_fn_trait_candidates(
        ecx: &mut EvalCtxt<'_, D>,

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Audit code that builds trait refs to ensure `Sized`/`MetaSized` are never the trait of a projection.
  2. Report as a rustc ICE with a minimal repro under `-Znext-solver`.
  3. Run on the stable solver as a workaround.

Example fix

// before — projecting on the Sized trait (invalid)
fn f<T: Sized>() -> <T as Sized>::Item { todo!() }
// after — Sized has no associated type; remove the projection
fn f<T: Sized>() { todo!() }
Defensive patterns

Strategy: validation

Validate before calling

// Sized / MetaSized are marker traits with no associated types. Block
// any projection that names them.
fn is_sized_family(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {
    let sized  = tcx.require_lang_item(LangItem::Sized, None);
    let meta   = tcx.lang_items().meta_sized();
    trait_def_id == sized || meta == Some(trait_def_id)
}
if is_sized_family(tcx, did) {
    return Err("Sized/MetaSized has no associated type");
}

Type guard

fn projection_target_is_not_sized(tcx: TyCtxt<'_>, did: DefId) -> bool {
    !is_sized_family(tcx, did)
}

Try / catch

use std::panic;
match panic::catch_unwind(panic::AssertUnwindSafe(|| solver.normalizes_to(goal))) {
    Ok(v) => v,
    Err(_) => Err("do not project an associated type off Sized / MetaSized"),
}

Prevention

When it happens

Trigger: A `NormalizesTo` goal whose trait is `Sized`/`MetaSized` is assembled by the candidate logic that handles built-in sizedness. Reproducible by naming an associated item on `Sized` under the new solver (which is not allowed by the language).

Common situations: Macro-generated code or IR construction that synthesizes `<T as Sized>::Foo`; nightly refactors of the sizedness candidate dispatch.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/22ec8cf391b00473.json. Report an issue: GitHub.