Switching to Family-Pattern results in compiler non-termination in `report_ambiguity_errors`
@BloodStainedCrow is already working on this.
Since May 22, 2026.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I have a project where most of the codebase is generic over a collection trait (a probability distribution, either storing the full distribution or always collapsing it immediately).
I previously used an associated type for mapping the inner type of the collection:
While using it, I was able to compile my crate in ~3 seconds using an insignificant amount of RAM.
trait Distribution<Value> {
type Inner<T>: Distribution<T, Inner::Inner<Value> = Self>;
}
Since this comes with some annoying trait bounds all over the code, I decided to switch to the family pattern when I learned of it:
trait DistributionFamily {
type Value<T>: Distribution<T, Family = Self>;
}
trait Distribution<Value> {
type Family: DistributionFamily;
}
After refactoring the entire codebase to (correctly afaik) use the family trait, I noticed I could no longer use neither rust-analyzer nor bacon.
Trying to compile using cargo build now often uses an ever increasing amount of RAM (I usually kill it before it fills up my swap and locks up my computer lol) up to ~50GB. The longest I had the compile running was ~30 minutes (when for some reason the RAM usage did not grow unbounded) after which I decided it would not finish and cancelled it.
I unfortunately do not have a small reproduction, but the code is public.
Pre-Refactor (No issue): https://github.com/BloodStainedCrow/sts2engine/tree/121db071183d1b904f28278e68c3671f58ade99a
Post-Refactor (No longer finishes compiling): https://github.com/BloodStainedCrow/sts2engine/tree/1d1f51eb6d098e8d72a354306f497ed31796d6df
Meta
rustc --version --verbose:
Tested on multiple versions:
Originally on:
rustc 1.94.0-nightly (7b5cde737 2025-12-27)
binary: rustc
commit-hash: 7b5cde7370b82fecf700071dda98c3fbc7d41fae
commit-date: 2025-12-27
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8
Compiler with debug symbols:
rustc 1.94.0-nightly (4a4ef493e 2026-03-02) (built from a source tarball)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8
I followed the guide on profiling rustc, and it seems the entire runtime is used in <rustc_hir_typeck::fn_ctxt::FnCtxt>::report_ambiguity_errors. The full samply record cargo b report can be found here.
This issue seems absent when using -Znext-solver.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.