Skip to content

Infinite Loop when Evaluating Recursive Type #122443

Open
@entropylost

Description

I tried the code:

trait Access {
    type Downcast: Access;
}

trait Mapping<X: Access> {}

trait AllowedMappingLoopback<X: Access> {
    type Chain: AllowedMapping<X::Downcast>;
}
impl<X: Access> AllowedMappingLoopback<X> for X
where
    X: AllowedMapping<X::Downcast>,
{
    type Chain = X;
}

trait AllowedMapping<X: Access>: AllowedMappingLoopback<X, Chain = Self> {}
impl<X: Access, T> AllowedMapping<X> for T where
    T: Mapping<X> + AllowedMappingLoopback<X, Chain = Self>
{
}

fn do_thing_with_allowed<X: Access>(mapping: impl AllowedMapping<X>) {}

struct BasicMapping;

fn test() {
    do_thing_with_allowed(BasicMapping);
}

This results in an infinite loop within the compiler, within both the latest nightly (1.78.0 (2024-03-12)) and stable (1.76.0).
(see playground)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.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`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions