Skip to content

rustc after 1.91 hangs during type inference case #159750

Description

@flying-kestrel

If there's any more information I can give, I'm happy to investigate! Sorry for the length of the reproduction, I couldn't find anything shorter.

Code

I tried this code:

use std::marker::PhantomData;

pub trait Marker {}
impl Marker for () {}

pub trait Relation {
    type Domain: Marker;
    type Codomain: Marker;
}

pub trait Follow<R: Relation, E: Marker, const DIR: bool> {}

impl<R: Relation> Follow<R, R::Codomain, true> for R::Domain {}
impl<R: Relation> Follow<R, R::Domain, false> for R::Codomain {}

// this bound on T is somehow important?
pub trait Container<T: Marker>: IntoIterator<Item = T> {
    type WithReplacedMarker<N: Marker>: Container<N>;
    type IDContainer;
}

impl<T: Marker> Container<T> for Option<T> {
    type WithReplacedMarker<N: Marker> = Option<N>;
    type IDContainer = Option<()>;
}

struct StubQueryable<E: Marker, C: Container<E>>(PhantomData<(E, C)>);

impl<E: Marker, C: Container<E>> Queryable for StubQueryable<E, C> {
    type Output = E;
    type Container = C;
}

pub trait Queryable {
    type Output: Marker;
    type Container: Container<Self::Output>;

    fn finish(&self) -> <Self::Container as Container<Self::Output>>::IDContainer {
        todo!()
    }

    fn follow<R: Relation, E: Marker, const DIR: bool>(
        &self,
        _r: &R,
    ) -> impl Queryable<Output = E, Container = Option<E>> {
        StubQueryable::<E, Option<E>>(PhantomData)
    }
}


struct R;
impl Relation for R {
    type Domain = ();
    type Codomain = ();
}

fn run_on(q: &impl Queryable<Output = (), Container = Option<()>>) {
    // this line causes rustc to hang:
    q.follow(&R).finish();
}

I expected to see this happen: Compile error due to inability to determine the value of the DIR generic parameter.

Instead, this happened: rustc hangs in a presumably-infinite loop (at least 60 seconds instead of 40ms)

Version it worked on

It most recently worked on: 1.91.0

Version with regression

rustc --version --verbose:

rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3

(The same happens for 1.94, 1.96-nightly, 1.97, and 1.99-nightly.)

Metadata

Metadata

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-inferenceArea: Type inferenceA-method-lookupArea: Method lookup (typeck, post `rustc_resolve`, not to be confused with `A-resolve`)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}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`.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions