Description
I found a case where apparently, trying to construct a struct the wrong way leads to the compiler very quickly exhausting all memory.
I observed it to take up 10G mem +10G of swap in a few seconds on my system.
The issue seems to be fixed on nightly, but I was unsure if I should still open a ticket about it.
Code
This scenario seems to require an external crate, so the minimum reproduction I can manage is a pair of lib.rs
and main.rs
:
// lib.rs
pub struct QueryCache {}
impl QueryCache {
pub async fn open() {}
}
// main.rs
use example::QueryCache;
fn main() {
QueryCache()
}
Alternatively see https://github.com/Kimundi/rustc_bug_2024_quick_oom
To reproduce, run:
cargo build
...and monitor memory consumption.
Meta
rustc --version --verbose
:
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Error output
I can not reproduce it in the MRE, but sometimes I get this error instead of the endless resource exhaustion:
error[E0391]: cycle detected when getting the resolver for lowering
|
= note: ...which requires normalizing `example::QueryCache::open::{opaque#0}`...
= note: ...which requires looking up limits...
= note: ...which requires getting the crate HIR...
= note: ...which again requires getting the resolver for lowering, completing the cycle
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
For more information about this error, try `rustc --explain E0391`.
Fixed on Nightly
The issue seems to be fixed on nightly:
rustc +nightly --version --verbose
:
rustc 1.78.0-nightly (2d24fe591 2024-03-09)
binary: rustc
commit-hash: 2d24fe591f30386d6d5fc2bb941c78d7266bf10f
commit-date: 2024-03-09
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
cargo +nightly build
Compiling example v0.1.0 (/home/kimundi/projects/ice_repro)
error[E0423]: expected function, tuple struct or tuple variant, found struct `QueryCache`
--> src/main.rs:4:5
|
4 | QueryCache()
| ^^^^^^^^^^^^ help: use struct literal syntax instead: `QueryCache {}`
|
::: /home/kimundi/projects/ice_repro/src/lib.rs:1:1
|
1 | pub struct QueryCache {}
| --------------------- `QueryCache` defined here
For more information about this error, try `rustc --explain E0423`.
error: could not compile `example` (bin "example") due to 1 previous error