Skip to content

compare_method_predicate_entailment is missing implied bounds from higher-ranked GAT #133805

Open
@compiler-errors

Description

I tried this code (from tests/ui/generic-associated-types/extended/lending_iterator.rs):

pub trait FromLendingIterator<A>: Sized {
    fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
}

impl<A> FromLendingIterator<A> for Vec<A> {
    fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
        let mut v = vec![];
        while let Some(item) = iter.next() {
            v.push(item);
        }
        v
    }
}

pub trait LendingIterator {
    type Item<'z>
    where
        Self: 'z;
    fn next(&mut self) -> Option<Self::Item<'_>>;

    fn collect<A, B: FromLendingIterator<A>>(self) -> B
    where
        Self: Sized,
        Self: for<'q> LendingIterator<Item<'q> = A>,
    {
        <B as FromLendingIterator<A>>::from_iter(self)
    }
}

I expected to see this happen: Pass (probably?)

Instead, this happened:

error[E0276]: impl has stricter requirements than trait
  --> $DIR/lending_iterator.rs:6:45
   |
LL |     fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
   |     ------------------------------------------------------------------------ definition of `from_iter` from trait
...
LL |     fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
   |                                             ^^^^^^^^^^^^ impl has extra requirement `I: 'x`

error: `Self` does not live long enough
  --> $DIR/lending_iterator.rs:27:9
   |
LL |         <B as FromLendingIterator<A>>::from_iter(self)
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0276`.

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-GATsArea: Generic associated types (GATs)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-implied-boundsArea: Implied bounds / inferred outlives-boundsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions