Skip to content

Compiler hangs checking recursive LazyCell with generic lifetime #152857

@easonkamander

Description

@easonkamander

Code

use std::cell::LazyCell;

enum Cycle<'c, F> {
    There(Box<Cycle<'c, F>>),
    Later(Box<LazyCell<Cycle<'c, F>, F>>),
}

trait Recursive<'c>: FnOnce() -> Cycle<'c, Self> + Sized {}

impl<'c, F> Recursive<'c> for F where F: FnOnce() -> Cycle<'c, F> {}

fn recursive<'c>() -> Cycle<'c, impl Recursive<'c>> {
    let make = || Cycle::There(Box::new(recursive()));
    Cycle::Later(LazyCell::new(make))
}

Meta

rustc --version --verbose before updating:

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

rustc --version --verbose after updating, yielding the same behaviour:

rustc 1.93.1 (01f6ddf75 2026-02-11)
binary: rustc
commit-hash: 01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf
commit-date: 2026-02-11
host: x86_64-unknown-linux-gnu
release: 1.93.1
LLVM version: 21.1.8

Error output

cargo check does not terminate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions