rust-lang/rust · critical

`Unsize` does not have an associated type: {:?}

Error message

`Unsize` does not have an associated type: {:?}

What it means

consider_structural_builtin_unsize_candidates (normalizes_to.rs:973) panics unconditionally. The Unsize trait (used for unsized coercions like `&[T; N] -> &[T]` and `T -> dyn Trait`) has no associated types; it is only meaningful as a trait goal (the real impl lives in trait_goals.rs). assembly/mod.rs:690 additionally calls this for Unsize, so a projection goal against Unsize is a goal-construction invariant violation.

Source

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

                projection_term: ty::AliasTerm::new(
                    ecx.cx(),
                    goal.predicate.alias.kind,
                    [self_ty, coroutine.resume_ty()],
                ),
                term,
            }
            .upcast(cx),
            // Technically, we need to check that the coroutine type is Sized,
            // but that's already proven by the coroutine being WF.
            [],
        )
    }

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

    fn consider_builtin_discriminant_kind_candidate(
        ecx: &mut EvalCtxt<'_, D>,
        goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        let self_ty = goal.predicate.self_ty();
        let discriminant_ty = match self_ty.kind() {
            ty::Bool
            | ty::Char
            | ty::Int(..)
            | ty::Uint(..)
            | ty::Float(..)
            | ty::Array(..)
            | ty::Pat(..)
            | ty::RawPtr(..)
            | ty::Ref(..)
            | ty::FnDef(..)

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Update to the latest nightly (rustup update nightly).
  2. Disable -Znext-solver (remove the flag or -Znext-solver=no).
  3. File an ICE at https://github.com/rust-lang/rust/issues including the goal from the panic and a minimal reproducer.
  4. Bisect nightlies to identify the introducing commit.
Defensive patterns

Strategy: type-guard

Validate before calling

// `Unsize` is a lang trait with NO associated types; it only governs
// coercions (`&[T; N]` -> `&[T]`, `&Concrete` -> `&dyn Trait`).
// Never write `<T as Unsize<U>>::Foo`.
fn unsize_coerce<'a, T: Unsize<U>, U>(x: &'a T) -> &'a U { x } // OK as bound

Type guard

trait _GuardUnsize<T: ?Sized, U: ?Sized> where T: Unsize<U> {} // bound-only sentinel

Prevention

When it happens

Trigger: A NormalizesTo goal whose trait_ref is the Unsize lang item is assembled by the next solver. Valid Rust cannot project an associated type off Unsize, so this indicates the solver mis-routed a goal or built an ill-formed projection.

Common situations: Nightly rustc regression in the next solver during unsizing/coercion handling; fuzzing; not produced by ordinary `as dyn Trait` or slice-coercion code.

Related errors


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