`compare_method_predicate_entailment` is missing implied bounds from higher-ranked GAT
Open
Nobody has claimed this yet.
A-GATs
A-higher-ranked
A-implied-bounds
A-trait-system
C-bug
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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`.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/ui/generic-associated-types/extended/lending_iterator.rs and reproduce the two diagnostics shown in the issue. Investigate the compiler handling behind compare_method_predicate_entailment and higher-ranked GAT bounds; done means the test produces the expected result without the reported E0276 and lifetime errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100