Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation stop when referring to GAT of Self in where clause of trait implementation #109279

Open
BotAngus opened this issue Mar 17, 2023 · 2 comments
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@BotAngus
Copy link

BotAngus commented Mar 17, 2023

I tried this code:

trait LendingIterator {
    type Item<'me>
    where
        Self: 'me;
    fn next(&mut self) -> Option<Self::Item<'_>>;
    
    fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item<'_>>
    where
        Self: Sized,
        P: FnMut(&Self::Item<'_>) -> bool,
    {
        todo!()
    }
}

struct Filter<I, P> {
    iter: I,
    predicate: P,
}

impl<I: LendingIterator, P> LendingIterator for Filter<I, P>
where
    P: FnMut(&Self::Item<'_>) -> bool,
{
    type Item<'me> = I::Item<'me>
    where
        Self: 'me;

    fn next(&mut self) -> Option<Self::Item<'_>> {
        self.iter.find(&mut self.predicate)
    }
}

I expect the code to compile or give, but instead the compilation comes to a halt (or gets stuck in an infinite loop) without any errors. This seems to occur in the current stable, beta, and nightly versions of the compiler.

If the P: FnMut(&Self::Item<'_>) -> bool, in the where clause is swapped with P: FnMut(&I::Item<'_>) -> bool, it compiles without any errors.

@BotAngus BotAngus added the C-bug Category: This is a bug. label Mar 17, 2023
@BotAngus BotAngus changed the title Compilation Stop Compilation stop when referinng to GAT of Self in where clause of trait implementation Mar 17, 2023
@BotAngus BotAngus changed the title Compilation stop when referinng to GAT of Self in where clause of trait implementation Compilation stop when referring to GAT of Self in where clause of trait implementation Mar 17, 2023
@fmease
Copy link
Member

fmease commented Mar 17, 2023

Duplicate of #108826.

@rustbot label T-compiler F-generic_associated_types I-hang

@rustbot rustbot added F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2023
@fmease
Copy link
Member

fmease commented Aug 21, 2023

Fixed by next solver (-Zsolver=next):

**error[E0275]: overflow evaluating the requirement `Filter<I, P>: LendingIterator`
  --> eh.rs:21:49
   |
21 | impl<I: LendingIterator, P> LendingIterator for Filter<I, P>
   |                                                 ^^^^^^^^^^^^
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`eh`)

error[E0275]: overflow evaluating the requirement `<Filter<I, P> as LendingIterator>::Item<'_> == _`
  --> eh.rs:29:27
   |
29 |     fn next(&mut self) -> Option<Self::Item<'_>> {
   |                           ^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`eh`)**

@rustbot label fixed-by-next-solver

@rustbot rustbot added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Aug 29, 2023
@fmease fmease added A-GATs Area: Generic associated types (GATs) and removed F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants