rust-lang / rust-lang/rust

A const with infinitely-changing types pointing to a self-referential static causes compiler hang.

Open
#158,554 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval C-bug I-hang T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This issue is a variant of #144719, but this issue doesn't involve patterns.

Compiling the following code causes the compiler to hang.

use std::marker::PhantomData;

#[repr(transparent)]
struct Generic<T: 'static>(&'static Generic<Option<T>>, PhantomData<T>);

#[repr(transparent)]
struct Concrete(&'static Concrete);

static X: Concrete = Concrete(&X);

const Y: &Generic<i32> = unsafe { &*(&raw const X).cast() };

fn main() {}

cc @RalfJung

Meta

Reproducible on the playground with version 1.98.0-nightly (2026-06-28 df6ee909ef35c75aa58a)

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 compiling the self-contained reproducer from the issue on the reported Rust nightly version and confirm the compiler hang. No repository file or test is named; done means the compiler no longer hangs when processing this const and self-referential static pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.