Skip to content

Clever recursive types + deref = seemingly infinite compile time #67064

Open
@meithecatte

Description

@meithecatte

The following takes an unknown, potentially infinite amount of time greater than 10 minutes to compile:

struct S<T>(T);
impl<T> std::ops::Deref for S<T> {
    type Target = S<(T,T)>;
    fn deref(&self) -> &Self::Target {
        self.thing()
    }
}

As @rkruppe pointed out on Discord,

Most places in rustc are supposed to have limits to stop them from going in circles forever (or just for a very long time), so at first glance I'd consider this a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions