Skip to content

Recursive Trait Hang in rustc #76351

@braxtoncuneo

Description

@braxtoncuneo

The code below, as the sole content of main.rs, should reproduce the error:

pub trait Indexed {
    type Index;
}

pub trait At<Address> {
    type AtItem;
    fn at(&self, address: Address`) -> &Self::AtItem;
}

impl <T, U> At<(T::Index,U)> for T
where
    Self: At<T::Index>,
    <T as At<T::Index>>::AtItem : At<U>,
    T : Indexed,
{
    type AtItem = <<T as At<T::Index>>::AtItem as At<U>>::AtItem;

    fn at(&self, address: (T::Index,U)) -> &<<T as At<T::Index>>::AtItem as At<U>>::AtItem {
        let (x,y) = address;
        At::<U>::at( self.at(x), y)
    }
}

fn main() {
    ().at(())
}

It pegs a CPU at 100%, and begins to consume progressively more memory (over 10 GB). It does not identify that Unit does not implement trait At

This issue is present in rustc 1.48.0-nightly (d006f57 2020-08-28).

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.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    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