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
- Update to the latest nightly (rustup update nightly).
- Disable -Znext-solver (remove the flag or -Znext-solver=no).
- File an ICE at https://github.com/rust-lang/rust/issues including the goal from the panic and a minimal reproducer.
- 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
- Use `Unsize` purely as a coercion bound, not an associated-type source.
- Prefer `CoerceUnsized` or explicit `.into()`/`as` over manual Unsize reasoning.
- Lint against `as Unsize` followed by `>::`.
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
- no such associated type in `AsyncFn*`: {:?}
- `Tuple` does not have an associated type: {:?}
- `FusedIterator` does not have an associated type: {:?}
- unexpected associated item `{:?}` for `{self_ty:?}`
- `Destruct` does not have an associated type: {:?}
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/7f31909bce03d83c.json.
Report an issue: GitHub.