rust-lang / rust-lang/rust

rustc runs forever with escalating memory use

Open
#149,819 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug I-compilemem I-hang S-has-bisection S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

It seems that rustc is stuck in some kind of endless type deduction loop for the edges variable in the code snippet below. If an explicit type is given for edges, rustc will run and complain as expected.

I searched for similar bugs but all I could find was macro related. I'm also no rustc expert so chances are rather high that I missed something or that I used the wrong search parameters.

I tried the following code. I know it doesn't really make sense (it was rather early):

fn main() {
    let mut edges = vec![];

    for pair in edges.windows(2) {
        edges.push((pair[0], pair[1]));
    }
}

Running cargo build, cargo run or cargo check on this they all yield the same result.

I expected to see this happen: rustc complains that my code makes no sense.

Instead, this happened: rustc runs forever and consumes 32G+ RAM in <1 min.

If an explicit type is given for edges, rustc will complain as expected:

fn main() {
    let mut edges: Vec<(i32, i32)> = vec![];

    for pair in edges.windows(2) {
        edges.push((pair[0], pair[1]));
    }
}
Meta

Checked with +stable, +beta, and +nightly. Versions below.

rustc --version --verbose:

rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: x86_64-unknown-linux-gnu
release: 1.91.1
LLVM version: 21.1.2

rustc 1.93.0-beta.1 (1b6e21e16 2025-12-08)
binary: rustc
commit-hash: 1b6e21e163baa0b20f119e17e3871910978a60b6
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.93.0-beta.1
LLVM version: 21.1.5

rustc 1.94.0-nightly (37aa2135b 2025-12-08)
binary: rustc
commit-hash: 37aa2135b5d0936bd13aa699d941aaa94fbaa645
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.5
Backtrace

n.a. there is no crash, my pc always ran out of memory. I could provide a perf trace if necessary, but issue should be easily reproducible.

I'm not familiar with debugging rustc but I will try to support best I can, just let me know. Thanks for your work on Rust!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimal edges example with cargo check, comparing its behavior with the explicitly typed version and the reported stable, beta, and nightly compilers. Trace the type deduction path responsible for the runaway memory use; the issue is resolved when the untyped example terminates with an appropriate compiler diagnostic instead of running indefinitely, with a regression test covering it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.