Skip to content

rustc after 1.91 hangs during type inference case #159750

Closed

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.)

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jul 22, 2026
  2. InvalidPathException commented on Jul 23, 2026

    @InvalidPathException
    Contributor

    -Znext-solver=globally fixes this

    error[E0599]: the method `finish` exists for associated type `impl Queryable<Container = Option<_>>`, but its trait bounds were not satisfied
      --> hang-clean.rs:32:16
       |
    32 |     q.follow().finish();
       |                ^^^^^^ method cannot be called on `impl Queryable<Container = Option<_>>` due to unsatisfied trait bounds
       |
       = note: the following trait bounds were not satisfied:
               `Option<_>: Container<<impl Queryable<Container = Option<_>> as Queryable>::Output>`
    

    reduced

    trait Container<T> {
        type IDContainer;
    }
    
    impl<T> Container<T> for Option<T> {
        type IDContainer = ();
    }
    
    trait Queryable {
        type Output;
        type Container;
    
        fn finish(&self) -> <Self::Container as Container<Self::Output>>::IDContainer;
    }
    
    fn follow<E>() -> impl Queryable<Container = Option<E>> {
        loop {}
    }
    
    fn main() {
        follow().finish();
    }

    @rustbot claim

  3. added
    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`.
    A-associated-itemsArea: Associated items (types, constants & functions)
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    A-method-lookupArea: Method lookup (typeck, post `rustc_resolve`, not to be confused with `A-resolve`)
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 23, 2026
  4. InvalidPathException commented on Jul 23, 2026

    @InvalidPathException
    Contributor

    seems like duplicate for #157516

  5. InvalidPathException commented on Jul 23, 2026

    @InvalidPathException
    Contributor

    Found that the regression was introduced by #142712, kind of subtle...

  6. added 4 commits that reference this issue on Jul 26, 2026
  7. added a commit that references this issue on Jul 27, 2026
  8. ojeda commented on Jul 27, 2026

    @ojeda
    Contributor

    @InvalidPathException Was #159774 intended to close this one too?

  9. apiraino commented on Jul 27, 2026

    @apiraino
    Contributor

    Closed by #159774

  10. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.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