Skip to content

Trait resolution fails, and then rustc hangs. #134312

Open
@frankmcsherry

Description

I tried this code:

trait Index {
    type IndexRef;
}

trait Borrow {
    type Borrowed<'a>;
}

trait Test {
    type Ref<'a>;
    type Container: Borrow where for<'a> <Self::Container as Borrow>::Borrowed<'a> : Index<IndexRef = Self::Ref<'a>>;
}

This builds fine if <Self::Container as Borrow>::Borrowed<'a> is replaced by &'a Self::Container. However, the above both errors, and also hangs rustc (still running after many minutes; wedges playground). The error is

binding for associated type Ref references lifetime 'a, which does not appear in the trait input types

I don't understand the error, though I could imagine that it is my fault or a known limitation of GATs. However, the hanging of rustc seems likely to be a bug.

Meta

rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)
Compiler output before hang

error[E0582]: binding for associated type `IndexRef` references lifetime `'a`, which does not appear in the trait input types
  --> lib.rs:11:92
   |
11 |     type Container: Borrow where for<'a> <Self::Container as Borrow>::Borrowed<'a> : Index<IndexRef = Self::Ref<'a>>;
   |                                                                                            ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

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-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.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.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