Infinite nested structs started compiling in release mode
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
I'm not sure if this is a bug or not.
This weirdness was discovered while investigating https://github.com/rust-lang/unsafe-code-guidelines/issues/413. See also https://github.com/rust-lang/rust/issues/149898#issuecomment-4551058234. cc @RalfJung
I tried this code:
use std::marker::PhantomData;
trait Chain {
type Next;
}
impl<T> Chain for T {
type Next = Thing<Option<T>>;
}
struct Thing<T: Chain>(T::Next, PhantomData<T>);
// Thing<i32> contains infinitely many layers of nested structs
#[inline(never)]
fn dummy<T>(_: T) {}
fn make_ptr<T: Chain>() {
let x: *const Thing<T> = unsafe { std::mem::transmute(1_usize) };
dummy(x);
}
fn main() {
make_ptr::<i32>();
}
I compiled the code in release mode.
This code previously errored with the following error:
error: queries overflow the depth limit!
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`playground`)
= note: query depth increased by 130 when computing layout of `Thing<i32>`
The code now compiles without errors.
Version it worked on
The code failed to compile on the playground with stable rust version 1.95.0.
Version with regression
The code compiled without errors on the playground with rust version 1.97.0-beta.1 (2026-05-26 96f70397ed7ba8baf8d1)
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.
Research direction
Start by compiling the minimal Rust example from the issue in release mode on the reported stable and beta versions, then compare the compiler behavior and diagnostics. Trace the layout computation for the nested Thing type and consult the linked unsafe-code-guidelines and Rust issues. Done means identifying whether the change is an unintended regression and adding a regression test or documenting the expected behavior.
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
- Mostly clear
- Newbie friendliness
- 48/100